freecarve
(Consulenza78)
July 17, 2013, 8:59am
1
Hi i’m a little new to Yii,
I have a model Client and a model Work with a Work/client_id field (FK).
I want that in Work/view/create I can click a button and search a value in Client/view/admin, retrieve the client_id and fill my Work/create/client_id…
then go on with my create form and submit my Work…
I suppose that I cannot use a dropdownlist for the many Clients in the model…
is there an easy way to do this?
I searched but I tell you that I’m a newbie, thanks
freecarve:
Hi i’m a little new to Yii,
I have a model Client and a model Work with a Work/client_id field (FK).
I want that in Work/view/create I can click a button and search a value in Client/view/admin, retrieve the client_id and fill my Work/create/client_id…
then go on with my create form and submit my Work…
I suppose that I cannot use a dropdownlist for the many Clients in the model…
is there an easy way to do this?
I searched but I tell you that I’m a newbie, thanks
<?php echo $form->dropDownList($model,'client_id',CHtml::listData(Client::model()->findAll(),'id','name')); ?> //replace 'name' with your attribute
Zugluk
(Lacffy Duck)
July 17, 2013, 9:26am
3
I guess this could much help you
if you are passing client_id to admin view then u can use like this
in the controller
$criteria=new CDbCriteria;
$criteria->condition='client_id=:clientId';
$criteria->params=array(':clientId'=>$_GET['id']);
$model= Client::model()->findAll($criteria);
freecarve
(Consulenza78)
July 17, 2013, 4:26pm
5
if you are passing client_id to admin view then u can use like this
in the controller
$criteria=new CDbCriteria;
$criteria->condition='client_id=:clientId';
$criteria->params=array(':clientId'=>$_GET['id']);
$model= Client::model()->findAll($criteria);
Thanks 4 the support. At the end I created an autocomplete field with the extension ejui-autocomplete-fk-field.
This extension help me with a search from the Client table and it’s good when there are many records (a dropdownlist was impossible in my case).