简体   繁体   中英

FindAll() not working in Yii Framework

My model name is Sales.

$allSales = Sales::model()->findAll();

$allSales return nothing (Blank). But its working my local computer(Ubuntu) and Not working on live server (Mac) .

$allSales2 = Sales::model()->findAll("id < 2000");

$allSales2 is working on both server

Please help me. Thanks in advance.

(Blank) is vague, but if the page itself is blank when it loads you are likely seeing an out of memory error. This is common with a large number of active records being queried at once. Check the php_error.log file and the respective memory limits in php.ini on each server.

You can also try to use CDataProviderIterator to fetch all the models, instead of findAll() .

$dataProvider = new CActiveDataProvider('Sales');
$allSales = new CDataProviderIterator($dataProvider);

foreach ($allSales as $model) {
    //do whatever
}

If your issue IS a memory problem, this should get around it.

If not, add var_dump($allSales); to your original code, and report the results from the live server.

You need pass the conditions as array. Try like this

$allSales2 = Sales::model()->findAll(
    array(
         "condition" => "id <  2000"
    )
);

If you do not like to use array in findAll then can use CDbCriteria like below

$criteria = new CDbCriteria;
$criteria->select = '*';
$criteria->condition = 'id < 2000';
$allSales2 = Sales::model()->findAll($criteria);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM