Created to ease the quite repetitive task of programming cascading select lists.
protected/extensionsSee the following code example:
$state = $this->createWidget('ext.jquery-cascade.jQueryCascade'); // dropDownList($id, $selected, $data, $htmlOptions = array(), $source, $cascaded) echo $state->dropDownList('stateId', '', CHtml::listData(State::model()->findAll(), 'id', 'name'), '', CController::createUrl('city/list'), 'cityId' );
The function which serves the data needed:
public function actionList() { if (Yii::app()->request->isAjaxRequest) { $state = State::model()->findByPk($_GET['selected']); $cities = array(); foreach ($state->cities as $city) { $cities[] = array('label' => $city->name, 'value' => $city->id); } echo json_encode($cities); Yii::app()->end(); } else { throw new CHttpException(400, 'Invalid request.'); } }
Total 6 comments
Here we go:
Anyway the header doesn't change:(
Hi,
I got the filter working;) Sorry, my fault...
But I still have the problem, that I'm not able to set the value...:( How can I do that...
I tried with:
Cheers Phil
@philippfrenzel,
Hey, I like your extension! But I don't get to run the filter stuff:(
Here is my code:
And then in the controller:
And one other issue is, that I try to set the selection by javascript Jquery - but I don't get it to run:(
Thank you for your help!
Cheers Phil
Never use DIRECTORY_SEPARATOR in URL!
Since you are providing an example for everyone to implement, I would recommend:
In actionList(), wrap the output with:
if(Yii::app()->request->isAjaxRequest) { .... } else { throw new CHttpException(400,'Invalid request. Please do not repeat this request again.'); }
Additionally, please end the output of actionList() properly, using
Yii::app()->end();
so that debugging output doesn't screw with the json output.
Leave a comment
Please login to leave your comment.