Hi.
There’s an issue driving me mad. I have a view with a simple GridView, implemented using YiiBooster but behaves the same using the core CGridView.
The filter doesn’t trigger search. Inspecting the HTML, there are no change
or keydown
events, like in other gridviews.
The model implements rules for the search
scenario.
I really cannot spot where’s the problem. I hope someone can give a hint. Thanks.
The model’s search()
:
public function rules()
{
// load validation rules folder
Yii::import('userGroups.validation.*');
// scenarios for the password_confirm
// registration is added depeding on the configuration parameter
$passwordConfirmScenarios = array('recovery', 'changePassword');
if (UserGroupsConfiguration::findRule('registration_password_confirm') === true)
$passwordConfirmScenarios[] = 'registration';
// rules
$rules = array(
array('group_id', 'length', 'max' => 20),
array('username, password, home', 'length', 'max' => 120),
array('email', 'email', 'checkMX' => true),
array('rememberMe', 'safe'),
// rules for activation
array('username, activation_code', 'required', 'on' => 'activate'),
array('activation_code', 'checkCode', 'on' => 'activate'),
// rules for passRequest
array('username, email', 'required', 'on' => 'passRequest'),
array('email', 'checkMail', 'on' => 'passRequest'),
array('answer', 'securityQuestion', 'on' => 'passRequest'),
// rules for mailRequest
array('mail', 'requestableMail', 'on' => 'mailRequest'),
// rules for changePassword
array('old_password', 'required', 'on' => 'changePassword'),
array('old_password', 'oldPassMatch', 'on' => 'changePassword'),
// rules for admin
array('group', 'levelCheck', 'on' => 'admin'),
// rules for multiple scenarios
array('username, password', 'required', 'on' => array('login', 'registration')),
array('email, old_password, password, password_confirm', 'accountOwnership', 'on' => array('changeMisc', 'changePassword')),
array('email', 'required', 'on' => array('registration', 'admin', 'mailRequest', 'changeMisc', 'invitation')),
array('username, email', 'unique', 'on' => array('registration', 'admin', 'recovery', 'changeMisc', 'invitation')),
array(
'username', 'match', 'pattern' => '/^[A-Za-z0-9]{4,}$/', 'on' => array('registration', 'admin', 'recovery'),
'message' => Yii::t('userGroupsModule.general', 'username must be at least 4 characters and can only be alphanumeric')
),
array('password', 'required', 'on' => array('recovery', 'changePassword')),
array('password', 'passwordStrength', 'on' => array('registration', 'admin', 'recovery', 'changePassword')),
array('password_confirm', 'required', 'on' => $passwordConfirmScenarios),
array(
'password_confirm', 'compare', 'compareAttribute' => 'password', 'on' => $passwordConfirmScenarios,
'message' => Yii::t('userGroupsModule.general', 'La password di conferma non coincide')
),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, group_name, group_id, username, home, status', 'safe', 'on' => 'search'),
);
if (UserGroupsConfiguration::findRule('simple_password_reset') === false)
array_push($rules, array('question, answer', 'required', 'on' => array('recovery', 'registration', 'changePassword')));
if (UserGroupsConfiguration::findRule('registration_captcha') === true) {
array_push($rules, array('captcha', 'required', 'on' => 'registration'));
array_push($rules, array('captcha', 'captcha', 'on' => 'registration'));
}
return $rules;
}
The controller:
public function actionUtenti()
{
Yii::app()->getModule('userGroups');
$this->layout = 'column2';
$model = new UserGroupsUser('search');
$model->unsetAttributes();
if (isset($_GET['UserGroupsUser']))
$model->attributes = $_GET['UserGroupsUser'];
$this->render('utenti', array(
'model' => $model,
));
}
The view:
<?php
/** @var UserGroupsUser $model */
/** @var SiteController $this */
$this->breadcrumbs = array(
Yii::t('Backend', 'Elenco'),
);
?>
<h1>Gestione utenti</h1>
<?php
$this->widget('bootstrap.widgets.TbGridView', array(
'id' => 'aaaa-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
'username',
),
'pager' => array(
'class' => 'bootstrap.widgets.TbPager',
'displayFirstAndLast' => true,
),
));