简体   繁体   English

FindAll()在Yii Framework中不起作用

[英]FindAll() not working in Yii Framework

My model name is Sales. 我的模型名称是Sales。

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

$allSales return nothing (Blank). $ allSales不返回任何值(空白)。 But its working my local computer(Ubuntu) and Not working on live server (Mac) . 但是它可以在我的本地计算机(Ubuntu)上运行,而不能在实时服务器(Mac)上运行

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

$allSales2 is working on both server $ allSales2在两台服务器上都工作

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. 检查php_error.log文件以及每个服务器上php.ini中的相应内存限制。

You can also try to use CDataProviderIterator to fetch all the models, instead of findAll() . 您也可以尝试使用CDataProviderIterator而不是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); 如果不是,则添加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 如果您不喜欢在findAll中使用数组,则可以使用如下所示的CDbCriteria

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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