Здравствуйте!
Нужно сделать два выпадающих списка так, чтобы при выборе значения в
одном из них (продукт), автоматически во втором загружались зависимые
значения (версии продукта).
В расширениях нашел виджет jquerycascadeselect, но
документация к нему для меня не понятна.
Делаю так:
// Модели (Models)
class Product extends CActiveRecord
{
// ...
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'product_versions'=>array(self::HAS_MANY, 'ProductVersion', 'id_product'),
);
}
// ...
}
class ProductVersion extends CActiveRecord
{
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'product' => array(self::BELONGS_TO, 'Product', 'id_product'),
'productVersionsOs' => array(self::HAS_MANY, 'ProductVersionsOs', 'id_product_version'),
);
}
}
// Контроллер (Controller)
class ProductSelectorController extends Controller
{
public function actionSelect()
{
// Yii::app()->getClientScript()->registerCoreScript('jquery');
$this->render('select',array(
'products' => CHtml::listData(Product::model()->findAll(), 'id', 'name'),
'data' => array()
));
}
public function actionGetdata()
{
$ret = "";
if(Yii::app()->request->isAjaxRequest)
{
if($_GET['val'] != 'null'){
$pr = Product::model()->findbyPk((int)$_GET['val']);
if($pr){
$neededmodels = $pr->getRelated('product_versions');
$i = 0;
foreach($neededmodels as $row){
if($i != 0) $ret .= ","; else $i++;
$ret .= "{'Value':'".$row["id"]."','Text':'".$row["name"]."'}";
}
}
}
}
echo "[".$ret."]";
}
}
// Представление (View)
$jqcs = $this->createWidget('application.extensions.JQueryCascadeSelect.JQueryCascadeSelect');
echo CHtml::dropDownList(
'product',
'',
$products,
array(
'prompt'=>'Select Product...',
'size'=>5
)
);
echo $jqcs->makeDropDown(
'versions',
'',
$data,
array(
'prompt'=>'Select Version...',
'size'=>5
),
'productSelector/getdata',
'product');
Собственно, этот код не работает.
Помогите разобраться.