php - Yii Model attributes showing null/blank values -


i working on simple form in yii. able access model attributes values before.

but can't, because it's showing blank/null.

i don't know what's problem , how solve this. appreciated. thank you.

here's form code.

    <div class="span4">     <?php $form=$this->beginwidget('cactiveform', array(     'id'=>'testform',     'enableclientvalidation'=>true,     'clientoptions'=>array(         'validateonsubmit'=>true,     ),     )); ?>      <p class="note">fields <span class="required">*</span> required.</p>      <div class="row">     <?php echo $form->labelex($model,'sample'); ?>     <?php echo $form->textfield($model,'sample'); ?>     <?php echo $form->error($model,'sample'); ?>     </div>     <div class="row buttons">     <?php echo chtml::submitbutton('login'); ?>     </div>     <?php $this->endwidget(); ?>    </div> 

here model's code:

     class questions extends cactiverecord     {         public $sample;      public function tablename()     {           return 'questions';     }       /**      * @return array customized attribute labels (name=>label)      */     public function attributelabels()     {         return array(             'queid' => 'queid',             'question' => 'question',                         'sample'=>'sample textfield',         );     }      public static function model($classname=__class__)     {         return parent::model($classname);     }          public function getinput()         {             $data = $this->sample;             echo "<script>alert('testing input'".$this->sample."')</script>";             echo $this->sample;             return $data;          } } 

and controller code page:

  public function actiontest()       {         $model = new questions();         $data = "";           if(isset($_post["questions"]))           {             $data = $model->getinput();           }          $this->render('test',array('model'=>$model,'data'=>$data));      } 

in controller , why use $_post['test'] ? 'test' here . model name questions

try

if(isset($_post["questions"])) {    $model->attributes = $_post["questions"];    echo $model->sample ; // value of sample   } 

or

if want attribute values , can try instead of getinput() ,

 $data = $_post['questions']['sample']; 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -