rmrevin / yii2-comments

Yii 2 comments extension
MIT License
52 stars 19 forks source link

Pjax support #8

Closed Patroklo closed 8 years ago

Patroklo commented 8 years ago

(I know, you probably want to kill me for being so annoying, I understand it :stuck_out_tongue_winking_eye: )

I'm trying to add Pjax support to the system, but the insert code in CommentFormWidget, even after changing the code to:

        if ($CommentCreateForm->load(\Yii::$app->getRequest()->post())) {
            if ($CommentCreateForm->validate()) {
                if ($CommentCreateForm->save()) {

                    if (\Yii::$app->getModule(Comments\Module::NAME)->Pjax != TRUE)
                    {
                        \Yii::$app->getResponse()
                            ->refresh(sprintf($this->anchorAfterUpdate, $CommentCreateForm->Comment->id))
                            ->send();

                        exit;
                    }
                }
            }
        }

Because it is executed with each comment already created, the only solution I've been able to find it's to move this code into the commentListWidget, where it's only executed one time AND also before loading the entire list (one more complication, because this code inserts the comment after loading all the comments).

Does come to your mind some other solution?

rmrevin commented 8 years ago

There is a great solution. Do not use pjax. This extension is an implementation of a bad pattern. I do not recommend using it.

rmrevin commented 8 years ago

If an extension is required to alter the code for yourself - it's a bad extension. If tomorrow I want to add some dynamics? I will again adjust to pjax.

Patroklo commented 8 years ago

Indeed I see things that I dont like in pjax, this is the first time I have ever used it and was curious about it, I'll check different approaches.

rmrevin commented 8 years ago

The best option - use the framework (eg angular). But a very small percentage of developers are able to use js frameworks. Therefore, for the realization of ajax should use jquery. For forms processing has excellent ext jquery form.