In yii2, the connection uses the post method to request the action, but the request is executed three times.

Source: Internet
Author: User
Now, I clicked the link, which is a post request. The parameter is passed by get, and the actionTripDays method is executed three times. Three pieces of data are inserted in the table and should be executed only once, insert a piece of data. What is this ?? Please help, but I am in, if, dump ($ position... now the situation is, I clicked aLink, yes postRequest. The parameter is getPassed, actionTripDaysThe method is executed three times. Three data entries are inserted in the table, and only one data entry is executed. What is the reason ?? Help

But I am,if,dump($position)But only one output.

$ LogId, 'position' => 'end'])?> "Class =" add-one-day "data-method =" post "rel =" nofollow "> + add the next day public function actionTripDays ($ id) {$ model = $ this-> findModel ($ id); // The first write is as follows: if (! Empty ($ position = Yii: $ app-> request-> get ('position', '') // if (Yii:: $ app-> request-> getIsPost ()&&! Empty ($ position = Yii: $ app-> request-> get ('position', '') {// dump (Yii :: $ app-> request-> get ('position', ''); // exit; TravelDay: addDay ($ position, $ model-> id );} else {TravelDay: initDay ($ model-> id);} $ days = TravelDay: find () -> where (['travel _ log_id '=> $ model-> id])-> orderBy (['order' => SORT_ASC])-> all (); $ images = TravelImg: find ()-> where (['travel _ log_id '=> $ model-> id]) -> orderBy (['order' => SORT_ASC])-> all (); return $ this-> render ('trip-days ', ['images' => $ images, 'days' => $ days, 'logid' => $ model-> id,]);}

Reply content:

Now, I clicked.aLink, yespostRequest. The parameter isgetPassed,actionTripDaysThe method is executed three times. Three data entries are inserted in the table, and only one data entry is executed. What is the reason ?? Help

But I am,if,dump($position)But only one output.

$ LogId, 'position' => 'end'])?> "Class =" add-one-day "data-method =" post "rel =" nofollow "> + add the next day public function actionTripDays ($ id) {$ model = $ this-> findModel ($ id); // The first write is as follows: if (! Empty ($ position = Yii: $ app-> request-> get ('position', '') // if (Yii:: $ app-> request-> getIsPost ()&&! Empty ($ position = Yii: $ app-> request-> get ('position', '') {// dump (Yii :: $ app-> request-> get ('position', ''); // exit; TravelDay: addDay ($ position, $ model-> id );} else {TravelDay: initDay ($ model-> id);} $ days = TravelDay: find () -> where (['travel _ log_id '=> $ model-> id])-> orderBy (['order' => SORT_ASC])-> all (); $ images = TravelImg: find ()-> where (['travel _ log_id '=> $ model-> id]) -> orderBy (['order' => SORT_ASC])-> all (); return $ this-> render ('trip-days ', ['images' => $ images, 'days' => $ days, 'logid' => $ model-> id,]);}

I am not answering this question. I want to ask how yii sets the Request Method for element.

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.