【发布时间】:2015-12-01 06:56:22
【问题描述】:
我在 cakephp 3.x 中发现了上述问题。
namespace App\Controller;
class UsersController extends AppController
{
public function index()
{
$users = $this->Users->find('all');
print_r($users); // <-- print_r creates a problem in cakephp 3.x
$this->set('users', $users);
}
}
我已经运行了上面的代码,我发现了以下错误:
Error: Cannot access parent:: when current class scope has no parent
File /var/www/html/cakephp-3-1-5/vendor/cakephp/cakephp/src/ORM/Query.php
Line: 1018
这个错误是由 print_r 引起的。我也试过 pr, var_dump 但同样的问题存在。
然后在评论 print_r 后,它关闭了 apache 并显示“连接已重置”,然后我需要重新启动我的 apache 服务,然后它才能正常工作。
所以我认为这个问题是 print_r。但我不知道真正的问题是什么,因为作为开发人员我需要调试我的结果集。在这里它限制我使用 print_r、pr 和 var_dump。
我的目的是显示结果集。
结果集
(int) 0 => object(Cake\ORM\Entity) {
'id' => (int) 1,
'title' => 'Distance between two addresses using Google Maps API and PHP',
'description' => 'Calculate distance between two addresses........',
'created' => object(Cake\I18n\Time) {
'time' => '2015-11-30T11:50:21+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'modified' => object(Cake\I18n\Time) {
'time' => '2015-12-01T06:32:17+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'status' => true,
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'Posts'
},
(int) 1 => object(Cake\ORM\Entity) {
'id' => (int) 2,
'title' => 'Ajax Pagination in CodeIgniter Framework',
'description' => 'CodeIgniter have the pagination library by........',
'created' => object(Cake\I18n\Time) {
'time' => '2015-11-30T11:50:21+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'modified' => object(Cake\I18n\Time) {
'time' => '2015-11-30T11:50:21+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'status' => true,
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'Posts'
}
cakephp 3.x 有问题吗? cakephp 3.x 是稳定版吗? 我可以将它用作开发框架还是使用以前的版本(如 2.x)?
谢谢。
【问题讨论】:
-
您必须提供用户目标代码才能找到问题的解决方案
-
在做了一些研究之后,我发现到现在 cakephp 3.x 中存在一些分段错误。所以我们可以使用 pj($var) 或 debug($var) 代替 print_r(), pr()。感谢您的方法。
标签: php cakephp-3.0