A
A
Arthur Strezhinov2017-09-04 17:00:16
Yii
Arthur Strezhinov, 2017-09-04 17:00:16

How to implement preview for articles, products?

Hey guys, how to implement a simplified preview of an article and a product, I looked at WP, then there is a button like a preview, you click and it takes you to the page with the article.
How can it be implemented in Yii2, with a different url, so that later this link can be closed from robots.
Tell the logic!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
melnikov_m, 2017-09-04
@strezinov

for example, you have a controller / action - article / article_page
Then you can make a preview article / article_preview
When you click on the "preview" button in the admin panel, you go to the page with the article at the address (article / article_preview, of course, don't forget to pass the article id) and if the user is an admin , then the page is displayed even if publish = false... For everyone else, the link will not preview with a 404 error
. This is one of the options...

A
Alexander Pavlenko, 2017-09-04
@RichyNix

In vp, each click on the "save" button is a new record in the database, and the published article comes with a label published, or something like that.
Therefore, you can save an article with a specific label, and when previewing, check the label, user and other data, and if everything is OK, issue a template. Well, accordingly, the method is only for authorized users, if not authorized - 404.

M
Maxim Timofeev, 2017-09-04
@webinar

Write an action similar to the one that renders an article, but instead of searching from the database, pass all the parameters of the post request entity. You form a model from this data, for example, by creating a new instance of the class and throwing data there, everything is the same as in the standard create, only the view is different and you do not need to save

public function actionCreate()
    {
        $model = new Hren();

        if ($model->load(Yii::$app->request->post())) {
            return $this->render('someview', ['model' => $model]);
        }
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question