How to carry parameters when Yii2 return

Source: Internet
Author: User
In the use of YII2 in the process of encountering such problems, first thank you for your help, not very grateful!
As an exercise, do a message board, this message board message form and message content in the same interface, now the demand is when I fill out the message after the content click Send, and then if the controller successfully saved data, with JS Alert prompt users to successfully send. But now the problem is, normally we are using render to render the template, and this render can have parameters, but in order to prevent repeated submissions, I use the refresh here, and this is the direct refresh interface, And refresh is no way to add parameters like render, leave the people what to do to solve my needs.
Note: The parameter is attached because the parameter can be received from the view and can know whether the submission is successful, the success of the direct prompt, of course, if there is a better way to solve without parameters better!
Thank you, everyone!

Reply content:

In the use of YII2 in the process of encountering such problems, first thank you for your help, not very grateful!
As an exercise, do a message board, this message board message form and message content in the same interface, now the demand is when I fill out the message after the content click Send, and then if the controller successfully saved data, with JS Alert prompt users to successfully send. But now the problem is, normally we are using render to render the template, and this render can have parameters, but in order to prevent repeated submissions, I use the refresh here, and this is the direct refresh interface, And refresh is no way to add parameters like render, leave the people what to do to solve my needs.
Note: The parameter is attached because the parameter can be received from the view and can know whether the submission is successful, the success of the direct prompt, of course, if there is a better way to solve without parameters better!
Thank you, everyone!

Yii::$app->session->setFlash('success', 'success!');$this->refresh();

This requirement, changed to AJAX implementation better, after the user commits the Ajax post submission

It's sometimes written in old age.

if(!empty($_POST['xxx'])){    //有提交时候的代码,多输出一段提示,比如div或者script}//一般情况下的页面

Refresh is not recommended, you will need to temporarily save the data into a session or cookie, and then clear

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.