1

I'm trying to populate a drop down list from a table called supplier_table but I'm currently trying to do this within the view/create of a system_user table. I'm not quite sure how to use different models within a page.

This is my code from the create page:

<?php $this->renderPartial('_form', array('model'=>$model,
//(>w<) for dropdown 
'companyval'=>$companyval)); ?>

Problem is that $companyval is from a different model and currently, the model that is being used for this page is the one for this particular "create".

I'm not sure I explained it clearly, but if you have any questions, just comment.

1 Answer 1

2

As i understood from the question is that you want to show a dropdown from some other model in view of a different controller. In Yii you can do it like this.

I suppose you are using CActiveForm and have supplier Model with supplier_id in user table. You can modify if this solves the issue. add this code in view / _form of controller

    <?php $supplier = Supplier::model()->findAll();
          $list = CHtml::listData($supplier ,'id','name'); 
          echo $form->DropDownList($model,'supplier_id', 
          $list, array('prompt'=>'Select Supplier')); ?>
Sign up to request clarification or add additional context in comments.

3 Comments

I have a question, in the line "Supplier::model()" Does the Supplier mean the actual name of the table inside the database?
Supplier is model class name
it is Model name. Supplier is model name

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.