Answer the question
In order to leave comments, you need to log in
How to properly implement select lists in Yii ?
Hello! Help me please. I have a form for adding a post, it needs to specify the author_id , I want to make me select them from the list by name, and not enter the id. How can I implement this? Please help me in detail if possible. Thank you!
Answer the question
In order to leave comments, you need to log in
<?php
echo $form->dropDownList(
$model,
'author_id',
CHtml::listData(Authors::model()->findAll(), 'id', 'name')
);
?>
dropDownList
Read more www.yiiframework.com/doc/guide/1.1/en/form.builder
I'm building sites in Laravel and was also wondering how to implement such a list. Of course, the framework provides its own tools for this, but I did not bother and did this:
<select name="author_id">
/*В ларавеле это делалось через функцию шаблонизатора @foreach, в yii есть своя */
@foreach($author as $auth)
/* Фигурные скобки заменяют оператор echo, ну это так если че */
<option value="{{ $auth->id }}"> {{ $auth->name }}</option>
@endforeach
</select>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question