Answer the question
In order to leave comments, you need to log in
Yii CDbCriteria and data fetch?
I work with Yii and in the admin panel I have the following URL:
site.ru/controller/action/active:1;trusted:1 ...
Line: active:1;trusted:1 we have the data to select.
For example, I want to get all active and trusted users.
It will look something like this:
$criteria = new CDbCriteria;
$criteria->limit = ProcessingData::load()->limit();
if(isset($params['active']) && is_numeric($params['active']))
$criteria->compare('active',$params['active']);
if(isset($params['trusted']) && is_numeric($params['active']))
$criteria->compare('trusted',$params['trusted']);
$criteria->order = 'date DESC';
$criteria->offset = ProcessingData::load()->offset($params['page'],$criteria->limit);
Answer the question
In order to leave comments, you need to log in
Why didn't the standard search() method in the model work? We drive everything that is needed from the get into the attributes of the model, validate it and then get the data from the search.
Can you try something like this
foreach( $params as $key=>$value )
{
if(is_numeric($value))
{
$criteria->compare($key,$value);
}
}
here again, how do we know that $key will contain the value existing in the base column?
I don’t program in Yii at all, but if entities are used there as in the doctrine or some other things, then you can try something like this:
foreach( $params as $key=>$value )
{
//if( property_exists(new Class, $key) && is_numeric($value) )
if( property_exists('Ваш класс', $key) && is_numeric($value) )
{
$criteria->compare($key,$value);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question