1. Go to this page and download the library: Download mikehaertl/defaultpersister library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mikehaertl / defaultpersister example snippets
$model->saveAsDefaults();
$model->loadDefaults();
// Will merge with already saved defaults
$model->saveAsDefaults('name');
$model->saveAsDefaults(array('status','project_id'));
$model->loadDefaults('name');
$model->loadDefaults(array('name','project_id'));
// true indicates that only safe attributes should be loaded
$model->loadDefaults(null,true);
$model->resetDefaults(); // Reset all defaults
$model->resetDefaults('name'); // Reset specific attribute
public function behaviors()
{
return array(
'defaults'=>array(
'class'=>'ext.defaultpersister.AttributeDefaultsPersister',
'attributes'=>array('name','status','project_id'),
),
);
}
public function actionUserList()
{
$filter=new User('filter');
$filter->loadDefaults();
// Set filter attributes on Ajax request and save them as default
if (($isAjax=isset($_GET['ajax'])) && isset($_GET['User']))
{
$filter->attributes=$_GET['User'];
if (!$filter->validate()) // Invalid filter settings!
return;
$filter->saveAsDefaults();
}
// Similar to the search() method in Yii's default CRUD models,
// this method creates a CActiveDataProvider from the current
// attribute values:
$data=$filter->getDataProvider();
if ($isAjax)
// render only the partial for the data grid:
$this->renderPartial('_userGrid',array(
'data'=>$data,
));
else
// render complete view with filter and data grid
$this->render('userList',array(
'filter'=>$filter,
'data'=>$data,
));
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.