php - Custom action Error in Yii2 -
i have controller called textcontroller,i created custom action in controller called trans controller used manage multi languages.the problem arises when submit form.it shows me not found (#404) requested page not exist.
confused this...can me????
attaching controller , view here.
my controller
public function actiontranslate() { // echo 'dddddddddd';die(); for($x = 0; $x < count($_post['english']); $x++ ) { $model = $this->findmodel($_post['text_id'][$x]); $model->trans_text_id = $_post['text_id'][$x]; $model->trans_text_label =$_post['label_id'][$x]; $model->english =$_post['english'][$x]; $model->spanish =$_post['spanish'][$x]; $model->french =$_post['french'][$x] ; $model->german =$_post['german'][$x] ; // echo '<pre>';print_r($model->trans_text_id); $model->save(false); } echo yii::$app->session->setflash('success', 'translation saved'); return $this->redirect(yii::$app->request->referrer); }
my form
<?php use yii\helpers\html; use app\modules\admin\models\translabels; use app\modules\admin\models\transtext; $ids = $_get['id']; // echo $ids; $model = translabels::find()->where(['trans_page_title' => $ids])->all(); // echo '<pre>';print_r($model);die(); ?> <table class="table table-striped table-bordered" > <thead> <tr> <th>labels</th> <th>english</th> <th>spanish</th> <th>french</th> <th>german</th> </tr> </thead> <tbody> <form action="<?php echo yii::$app->homeurl;?>admin/text/translate" method="post" > <?php if (yii::$app->session->hasflash('success')) {?> <div> <center><h1><span style="color:green; text-align:centre "><?php print_r(yii::$app->session->getflash('success')); ?> </span></h1></center> </div> <?php } ?> <?php foreach($model $expertn) { $title=$expertn['trans_labels']; $label_id = $expertn['trans_label_id']; $sql = transtext::find()->where(['trans_text_label'=>$label_id])->all(); $eng = $sql[0]->english; $span = $sql[0]->spanish; $fren = $sql[0]->french; $ger = $sql[0]->german; $text_id = $sql[0]->trans_text_id; // echo '<pre>';print_r($ger); // echo $expertn['trans_label_id']; echo '<tr>'; // start new row echo '<td data-label="payment">'; echo $expertn['trans_labels']; echo '<input type="hidden" name="text_id[]" value="'.$text_id.'"/>'; echo '<input type="hidden" name="label_id[]" value="'.$expertn['trans_label_id'].'"/>'; echo '</td>'; echo '<td data-label="issue date">'; echo '<input type="text" name="english[]" value="'.$eng.'"/>'; echo '</td>'; echo '<td data-label="issue date">'; echo '<input type="text"name="spanish[]" value="'.$span.'"/>'; echo '</td>'; echo '<td data-label="issue date">'; echo '<input type="text"name="french[]" value="'.$fren.'"/>'; echo '</td>'; echo '<td data-label="issue date">'; echo '<input type="text"name="german[]" value="'.$ger.'"/>'; echo '</td>'; // echo '<td>'; // echo $expertn['tcount']; // echo '</td>'; echo '</tr>'; } echo '<input type="submit" name="submit" id="sub" value="save" class="btn btn-primary bton"/>'; ?> </form> </tbody> </table>
thanks in advance...
if having controller named textcontroller
in view file
... <form action="<?php echo yii::$app->request/baseurl;?>admin/text/translate" method="post" > ...
or
... <form action="<?php echo yii::$app->homeurl;?>/admin/text/translate" method="post" > ...
and in textcontroller.php
public function actiontranslate() { // echo 'dddddddddd';die(); for($x = 0; $x < count($_post['english']); $x++ ) { if($model = $this->findmodel($_post['text_id'][$x])) { $model->trans_text_id = $_post['text_id'][$x]; $model->trans_text_label =$_post['label_id'][$x]; $model->english =$_post['english'][$x]; $model->spanish =$_post['spanish'][$x]; $model->french =$_post['french'][$x] ; $model->german =$_post['german'][$x] ; // echo '<pre>';print_r($model->trans_text_id); $model->save(false); unset($model); } } echo yii::$app->session->setflash('success', 'translation saved'); return $this->redirect(yii::$app->request->referrer); }
you should put if
condition (because if not found in db then?) in for
loop , unset
@ end of if
condition
Comments
Post a Comment