Hope you are all doing well.

I need some help from you regarding my question that how can I get single data by CHtml Query into Text Field.

for example I am using

<?php echo $form->dropDownList($model,'im_costprice', CHtml::listData(Purchaseorddt::model()->findAll(" pp_purordnum = '$pp_purordnum' "), 'pp_purchasrate', 'pp_purchasrate'), array('id'=>'purchasrate')); ?>

BUT I want to get single data into textfiled so that user can edit/ change the data. Such as:

<?php echo $form->textField($model,'im_costprice', CHtml::Data(Purchaseorddt::model()->findByAttributes(" pp_purordnum = '$pp_purordnum' "), 'pp_purchasrate', 'pp_purchasrate'), array('id'=>'purchasrate')); ?>

It is showing ERROR. Fatal error: Call to undefined method CHtml::Data()... How Can I solve this. Please help me with some idea.

Helps are highly appreciated .

有帮助吗?

解决方案

Just store the value of the Purchaseorddt::model()->findByAttributes part in a separate variable and replace that variable in the place of your CHtml::Data section.

Edit - Something on these lines would work. Do remember though that it is a better approach to do your queries in the controller or the model.

<?php $x = Purchaseorddt::model()->findByAttributes( array('pp_purordnum' => $pp_purordnum));
       $y = $x['pp_purchasrate'];
       $model->im_costprice = $y;
       echo $form->textField($model,'im_costprice',array('id'=>'purchasrate'));   ?>

其他提示

In your controller you can put code like that

$purchaseorddt = Purchaseorddt::model()->findByAttributes("pp_purordnum = '$pp_purordnum'");

and then assign like

if(!empty($purchaseorddt)) {
  $model->in_costproce = $purchaseorddt->pp_purchasrate;
}

then in view use like

  echo $form->textField($model,'im_costprice', array('id'=>'purchasrate')); 

for more information on cactiveform textField http://www.yiiframework.com/doc/api/1.1/CActiveForm#telField-detail

just simple call the model in controller like this :

$data = Purchaseorddt::model->findByPK($pp_purordnum);
$model->costprice=$data->pp_purordnum;

that code will automaticly fill the value in textfield

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top