0

UPDATED THE SOLUTION::: IT IS WORKING NOW

I have created a controller with join query. Now I want to include controller to actionCreate function and show data into text filed in form.

Controller

public function actionCreate()
{
    $model=new Grndetail;

    if (isset($_POST['Grndetail'])) {
        $model->attributes=$_POST['Grndetail'];
        if ($model->save())
            $this->redirect(array('view','id'=>$model->id));
    }
    
    $grndata = $this->GrnData1();
    $model->im_grnnumber = $grndata['im_grnnumber'];
    $this->render('create',array('model'=>$model, 'grndata'=>$grndata,));
}



public function GrnData1()
{               
    $sql = Yii::app()->db->createCommand()
              ->select('t.im_grnnumber, t.im_purordnum, r.pp_purordnum, r.cm_code, r.pp_quantity, r.pp_unit, r.pp_unitqty, r.pp_purchasrate, p.cm_description, p.cm_code')
              ->from('im_grnheader t')
              ->join('pp_purchaseorddt r', 't.im_purordnum = r.pp_purordnum')
              ->join('cm_productmaster p', 'p.cm_code = r.cm_code')
             //->where('id=:id', array(':id'=>$id))
              ->order('im_grnnumber DESC')
              ->queryRow();
                    
     return $sql;
}

form filed

<?php echo $form->textField($model,'im_grnnumber'); ?>

Is anything I am missing. How can I view the data as value in form when I am creating something.

UPDATED THE SOLUTION::: IT IS WORKING NOW

4 Answers 4

1

You should change your program as

public function GrnData1(){

$sql = Yii::app()->db->createCommand()->setFetchMode(PDO::FETCH_OBJ) // change it

->select('t.im_grnnumber, t.im_purordnum, r.pp_purordnum, r.cm_code, r.pp_quantity,  r.pp_unit, r.pp_unitqty, r.pp_purchasrate, p.cm_description, p.cm_code')

->from('im_grnheader t')
->join('pp_purchaseorddt r', 't.im_purordnum = r.pp_purordnum')
->join('cm_productmaster p', 'p.cm_code = r.cm_code')
->order('im_grnnumber DESC')
->queryRow();

Return $sql; // write here return statement

}

Now you can access your data like this

echo $form->textField($model,'im_grnnumber', array('value'=>$grndata->im_grnnumber));

Hope, It will help you.

Thanks

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Dear. I forgot to return $sql. thanks for help. But in textfield is not working. I got the Solutions and Updated my POST/ CODE. Please Have a look. Thanks AGAIN
1

Var $grndata is an array, not a model. So the correct way to call its values should be this:

<?php echo $form->textField($model,'im_grnnumber', array('value'=>$grndata['im_grnnumber']) ); ?>

Or something like that, I'm not sure of the format of the array returned by queryRow(). Maybe print_r($grndata) to see the style of the array.

3 Comments

it's showing ERROR: GrndetailController and its behaviors do not have a method or closure named "GrnData1".
I changed it. But still same error. I found something for static .. help me for dynamic. Like from controller :: $model->im_grnnumber ="1111"; is working. it is showing in the field. How can I do that dynamically. Please help –
Thank you Dear. I forgot to return $sql. thanks for help. I got the Solutions and Updated my POST/ CODE. Please Have a look. Thanks AGAIN
0

change actionGrnData1() to GrnData1()

3 Comments

I changed it. But still same error. I found something for static .. help me for dynamic. Like from controller :: $model->im_grnnumber ="1111"; is working. it is showing in the field. How can I do that dynamically. Please help
Do you have any idea what you are saying. he has created a function and why are you converting it to an action??
Thank you Dear. I forgot to return $sql. thanks for help. I got the Solutions and Updated my POST/ CODE. Please Have a look. Thanks AGAIN
0

You should complete your textField like this

    <?php echo $form->textField($model,'im_grnnumber',
array('value'=>$grndata->im_grnnumber
)); ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.