Invalid argument supplied for foreach() CORE\Cake\Utility\ObjectCollection.php, line 330


<a><b>Warning</b> (2)</a>: Invalid argument supplied for foreach() [<b>CORE\Cake\Utility\ObjectCollection.php</b>, line <b>330</b>]
Code Context
ObjectCollection::normalizeObjectArray() - CORE\Cake\Utility\ObjectCollection.php, line 330
BehaviorCollection::init() - CORE\Cake\Model\BehaviorCollection.php, line 66
Model::__construct() - CORE\Cake\Model\Model.php, line 748
ReflectionClass::newInstance() - [internal], line ??
ClassRegistry::init() - CORE\Cake\Utility\ClassRegistry.php, line 164
Model::_constructLinkedModel() - CORE\Cake\Model\Model.php, line 1031
Model::__isset() - CORE\Cake\Model\Model.php, line 857
Model::__get() - CORE\Cake\Model\Model.php, line 887
DboSource::read() - CORE\Cake\Model\Datasource\DboSource.php, line 1063
Model::find() - CORE\Cake\Model\Model.php, line 2674
Batch::count_enrolled() - APP\Plugin\course\Model\batch.php, line 73
CoursesController::index_admin() - APP\Plugin\course\Controller\CoursesController.php, line 55
ReflectionMethod::invokeArgs() - [internal], line ??
Controller::invokeAction() - CORE\Cake\Controller\Controller.php, line 485
Dispatcher::_invoke() - CORE\Cake\Routing\Dispatcher.php, line 186
Dispatcher::dispatch() - CORE\Cake\Routing\Dispatcher.php, line 161
[main] - APP\webroot\index.php, line 97

Selama 3 hari saya tersangkut dengan ralat ini. Sungguhpun ianya sekadar amaran(warning), tapi saya mahu menjadikan sistem saya bebas ralat. Kod yang pada asalnya menggunakan cakephp 1.3 kini dalam proses migrasi ke cakephp 2.3.

Hasil daripada apa yang saya kesan penggunaan fungsi $this->NamaModel->(‘count’) haruslah mempunyai parameter ‘contain’ => array(). Dimana kesemua hubungan model ini bersama model lain, haruslah diputuskan.


<?php

$params = array(

'conditions' => array('namaField' => $value),

'contain' => array()

);

$this->NamaModel->find('count',$params);

?>

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.