Problem with cgridview filter

Hi there!

I have a big question. Maybe someone can help me.

I have a CGridview with userid column. That column is defined as an integer:




public function rules(){                

    return array(

        array('id_user','numerical','integerOnly'=>true),

        array('id_user', 'safe','on'=>'search'),

    );

}



When I write "abc" in the gridview filter, the controller does:


$model->attributes=$_POST['User'];

Next, load the view with the CGridview. That gridview gets data from the dataprovider. Returned from model:


$model->search();

As


$model->id_user

contains an invalid character no numerical, the SQL fails (Oracle).

I can use


$model->validation()

, the problem is where. In controller, in model…

Any idea?

Thanks.

I don’t think problem is anywhere, I mean $model->search will work with assigned attribute values. What ever is set as filter on page will be added in query. What you can do is :

i search method :




if (is_numeric($this->user_id)

   $criteria->addCondition('t.user_id = ' . $this->user_id);



meaning only if user_id is numeric it will apply condition. If it’s not numeric user_id will not be used in query. That should solve sql issue you have

1 Like

That was the solution we took for the same issue, but i think it should be also controlled in the view with any kind of js validation.