This extension is use to validate the field is required or not required depends by another field.
For Example, now the form have 2 fields, they are
Name and
Email. You can set if
Name was not empty then
Email field will become required to force the user enter the value.
In the Model rules you just include the extension file and then set the
if value for which object only.
array('email', 'ext.requiredif', 'if' => 'name')
Posted by
chevrons in
Yii
I had install Rights module inside my application. The Rights module itself wouldn’t auto integrate with the controller.
So I need to integrate myself, at each of the controller we need to add 2 extra function they are:
public function filters() {
return array(
'accessControl',
);
}
and
public function accessRules() {
return array(
array('allow',
'action' => array('Index'),
'users' => array('@'),
),
);
}
Posted by
chevrons in
Yii
Because I didn’t found any example of Yii autocomplete function. particularly showing how to fetched data via a server request.
For the widget function in view:
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name' => 'username',
'value' => $model->username,
'sourceUrl' => array('user/getusername'),//path of the controller
'options' => array(
'minLength' => '1', // min chars to start search
'select' => '' // when the value selected
),
));
Now, we start create the
getusername action in the
UserController file.
Because need develop an APi application with frontend and backend together.
Frontend without any interface and it just return
JSON format to the user. But backend have interface to let user do the setting and update data.
In Yii
main.php only allow set one error page. The solution is set the error page in controller class.
You can follow
below example to write your own error page to each controller.
Posted by
chevrons in
Yii
Default Yii cgridview pagination didn’t show the first and last page. But actually it was hidden but the CSS class, the easy method is change the CSS class to let it can show it.
how to do it? open
pager.css file and find the code like below.
Controller error handler:
ul.yiiPager .first, ul.yiiPager .last {
display: none;
}
Posted by
chevrons in
Yii
Below example showing you how to add the row number in cgridview widgets.
You just need add the following script inside the array
columns.
array(
'header' => 'No.',
'value' => '$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)',
),
The completed example as below:
Posted by
chevrons in
Yii
Normally we include Javascript in our application in Yii is below script
Yii::app()->getClientScript()->registerScriptFile('jquery.js');
But, now we need include yiigridview.js script file in our application. Because it was generate by Yii and it located at assets folder. So above example cannot used.
In here, we need to call
getAssetManager() to get the assets folder url and folder name generated by Yii.
Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('zii.widgets.assets'));
The above example will get the gridview path from the assets folder.
Posted by
chevrons in
Yii
Following last post
CGridview listdata with CArrayDataProvider to list down the data with cgridview.
But it just can listing the records without the pagination. Use back last post example script and then modify the
CArrayDataProvider as below example.
Posted by
chevrons in
Yii
Yii, use CArrayDataProvider to listing out the array with CGridView widgets.
Below example are showing how to use it.
Data array:
$data = array();
$data[] = array('id' => 1, 'name' => 'name 1', 'age' => 22, 'date' => '1-Jan-2013');
$data[] = array('id' => 2, 'name' => 'name 2', 'age' => 25, 'date' => '1-Feb-2013');
$data[] = array('id' => 3, 'name' => 'name 3', 'age' => 22, 'date' => '1-Mac-2013');
$data[] = array('id' => 4, 'name' => 'name 4', 'age' => 28, 'date' => '1-Jan-2013');
$data[] = array('id' => 5, 'name' => 'name 5', 'age' => 23, 'date' => '1-Apr-2013');
$data[] = array('id' => 6, 'name' => 'name 6', 'age' => 29, 'date' => '1-May-2013');
$data[] = array('id' => 7, 'name' => 'name 7', 'age' => 21, 'date' => '1-Jan-2013');
$data[] = array('id' => 8, 'name' => 'name 8', 'age' => 20, 'date' => '1-Feb-2013');
Posted by
chevrons in
Yii
In Yii
CGridView it doesn’t provide absolute row number in all the pages.
The easy way is write the a calculation method inside the column to show the column number.
Posted by
chevrons in
Yii