Property "CClientScript.scripts" is not defined.
Cause:
Most probably happened when it cannot locate yii file.
Solution:
Check the path from index.php file and yiic.php file. Make sure it point to Yii Root.
Thursday, April 3, 2014
Yii Load data into select option list box dynamically + sorting
I would like to share how to sort list and load data into list box in yii.
Let say we have member table like Member(id, mid, name),
Controller File
<?php
class SignupController extends Controller
{
public function actionGetMember(){
$json = array();
$records = Member::model()->findAll(array('order'=>'id'));
$count_records = count($records);
if($count_records > 0){
$json = array();
foreach ($records as $record) {
array_push($json, $record->attributes);
}
}
echo json_encode($json);
}
}
?>
==============================
Js File
jQuery(function($) {
// To call profession and specialty listing
$.ajax({
url: 'signup/GetMember',
type: 'GET',
dataType: 'json',
success: function(data) {
$.each(data, function(index, element) {
$("<option></option>", {value: element['mid'], text: element['name']}).appendTo('#User');
});
}
});
});
===========================
View File
<select id="User">
<option>Please select:</option>
</select>
Let say we have member table like Member(id, mid, name),
Controller File
<?php
class SignupController extends Controller
{
public function actionGetMember(){
$json = array();
$records = Member::model()->findAll(array('order'=>'id'));
$count_records = count($records);
if($count_records > 0){
$json = array();
foreach ($records as $record) {
array_push($json, $record->attributes);
}
}
echo json_encode($json);
}
}
?>
==============================
Js File
jQuery(function($) {
// To call profession and specialty listing
$.ajax({
url: 'signup/GetMember',
type: 'GET',
dataType: 'json',
success: function(data) {
$.each(data, function(index, element) {
$("<option></option>", {value: element['mid'], text: element['name']}).appendTo('#User');
});
}
});
});
===========================
View File
<select id="User">
<option>Please select:</option>
</select>
Subscribe to:
Posts (Atom)