php - How to get the value from a dropdown list and use it as a form submit id -


i'm new yii may or may not make sense. want use on form submit dropdown list value id cat_id.

model:

public function getcategories(){      $user = yii::app()->db->createcommand()         ->select()         ->from('categories')         ->queryall();      return $user;  } 

this comes category model.

controller:

public function actioncreate() {     $model=new posts;     $categories = categories::model()->getcategories();     $model->cat  = chtml::listdata($categories, 'id', 'name');      if(isset($_post['posts']))     {         $model->attributes=$_post['posts'];         if($model->save())             $this->redirect(array('view','id'=>$model->id));     }      $this->render('create',array(         'categories'=>$model->cat,         'model'=>$model,     )); } 

view:

<div class="row">     <?php echo $form->labelex($model,'cat_id'); ?>     <?php echo chtml::dropdownlist('categories', $model, $model->cat, array('empty' => 'select category')); ?>     <?php echo $form->error($model,'cat_id'); ?> </div> 

public function actioncreate() {     $model=new posts;      if(isset($_post['posts']))     {         $model->attributes=$_post['posts'];         if($model->save())             $this->redirect(array('view','id'=>$model->id));     }      $this->render('create',array(         'model'=>$model,     )); } 

view

<div class="row">     <?php echo $form->labelex($model,'cat_id'); ?>     <?php echo $form->dropdownlist($model,'cat_id',chtml::listdata(categories::model()->findall(),'id','name'),array('empty' => 'select category')); ?>     <?php echo $form->error($model,'cat_id'); ?> </div> 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -