Answer the question
In order to leave comments, you need to log in
How to correctly take data from the model thanks to "listdata" and "activeDropDownList"?
Hello. I'm building a book learning website. It is necessary to create a sub-category (an entry in the MySQL database table), the category of which is selected from the drop-down list. Here's the incomplete form:
<h1><?php echo $title ?></h1>
<?php echo CHtml::beginForm(); ?>
<div class="label"><?php echo CHtml::activeLabelEx($subcategory,
"category") ?></div>
<?php $listData = CHtml::listData($categories, "id", "name") ?>
<div class="control"><?php echo CHtml::activeDropDownList($subcategory,
"category", $listData) ?></div>
<?php echo CHtml::error($subcategory, "category") ?>
. . .
<div class="button"><?php echo CHtml::submitButton("Сохранить"); ?></div>
<?php echo CHtml::endForm() ?>
<p> </p>
<p><?php echo CHtml::link("Назад", array("subcategory/index")) ?></p>
<?php $listData = CHtml::listData($categories, "id", "name") ?>
<div class="control"><?php echo CHtml::activeDropDownList($subcategory,
"category", $listData) ?></div>
Answer the question
In order to leave comments, you need to log in
Do you have a name field in $categories? do var_dump first, see what is stored there in principle.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question