Rajib Rakshit
Rajib Rakshit

Reputation: 13

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.

Upvotes: 0

Views: 756

Answers (2)

Willem Renzema
Willem Renzema

Reputation: 5187

(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.

Upvotes: 1

MH2K9
MH2K9

Reputation: 12039

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);

Upvotes: 0

Related Questions