{"id":318,"date":"2013-03-12T13:42:09","date_gmt":"2013-03-12T05:42:09","guid":{"rendered":"http:\/\/syarman.com\/soft\/?p=318"},"modified":"2013-03-25T10:29:57","modified_gmt":"2013-03-25T02:29:57","slug":"invalid-argument-supplied-for-foreach-corecakeutilityobjectcollection-php-line-330","status":"publish","type":"post","link":"http:\/\/syarman.com\/soft\/2013\/03\/12\/invalid-argument-supplied-for-foreach-corecakeutilityobjectcollection-php-line-330\/","title":{"rendered":"Invalid argument supplied for foreach() CORE\\Cake\\Utility\\ObjectCollection.php, line 330"},"content":{"rendered":"<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\r\n&lt;a&gt;&lt;b&gt;Warning&lt;\/b&gt; (2)&lt;\/a&gt;: Invalid argument supplied for foreach() &#x5B;&lt;b&gt;CORE\\Cake\\Utility\\ObjectCollection.php&lt;\/b&gt;, line &lt;b&gt;330&lt;\/b&gt;]\r\nCode Context\r\nObjectCollection::normalizeObjectArray() - CORE\\Cake\\Utility\\ObjectCollection.php, line 330\r\nBehaviorCollection::init() - CORE\\Cake\\Model\\BehaviorCollection.php, line 66\r\nModel::__construct() - CORE\\Cake\\Model\\Model.php, line 748\r\nReflectionClass::newInstance() - &#x5B;internal], line ??\r\nClassRegistry::init() - CORE\\Cake\\Utility\\ClassRegistry.php, line 164\r\nModel::_constructLinkedModel() - CORE\\Cake\\Model\\Model.php, line 1031\r\nModel::__isset() - CORE\\Cake\\Model\\Model.php, line 857\r\nModel::__get() - CORE\\Cake\\Model\\Model.php, line 887\r\nDboSource::read() - CORE\\Cake\\Model\\Datasource\\DboSource.php, line 1063\r\nModel::find() - CORE\\Cake\\Model\\Model.php, line 2674\r\nBatch::count_enrolled() - APP\\Plugin\\course\\Model\\batch.php, line 73\r\nCoursesController::index_admin() - APP\\Plugin\\course\\Controller\\CoursesController.php, line 55\r\nReflectionMethod::invokeArgs() - &#x5B;internal], line ??\r\nController::invokeAction() - CORE\\Cake\\Controller\\Controller.php, line 485\r\nDispatcher::_invoke() - CORE\\Cake\\Routing\\Dispatcher.php, line 186\r\nDispatcher::dispatch() - CORE\\Cake\\Routing\\Dispatcher.php, line 161\r\n&#x5B;main] - APP\\webroot\\index.php, line 97\r\n\r\n<\/pre>\n<p>Selama 3 hari saya tersangkut dengan ralat ini. Sungguhpun ianya sekadar amaran(<em>warning<\/em>), tapi saya mahu menjadikan sistem saya bebas ralat. Kod yang pada asalnya menggunakan cakephp 1.3 kini dalam proses migrasi ke cakephp 2.3.<\/p>\n<p>Hasil daripada apa yang saya kesan penggunaan fungsi $this-&gt;NamaModel-&gt;(&#8216;count&#8217;) haruslah mempunyai parameter &#8216;contain&#8217; =&gt; array(). Dimana kesemua hubungan model ini bersama model lain, haruslah diputuskan.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\r\n&lt;?php\r\n\r\n$params = array(\r\n\r\n'conditions' =&gt; array('namaField' =&gt; $value),\r\n\r\n'contain' =&gt; array()\r\n\r\n);\r\n\r\n$this-&gt;NamaModel-&gt;find('count',$params);\r\n\r\n?&gt;\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&lt;a&gt;&lt;b&gt;Warning&lt;\/b&gt; (2)&lt;\/a&gt;: Invalid argument supplied for foreach() &#x5B;&lt;b&gt;CORE\\Cake\\Utility\\ObjectCollection.php&lt;\/b&gt;, line &lt;b&gt;330&lt;\/b&gt;] Code Context ObjectCollection::normalizeObjectArray() &#8211; CORE\\Cake\\Utility\\ObjectCollection.php, line 330 BehaviorCollection::init() &#8211; CORE\\Cake\\Model\\BehaviorCollection.php, line 66 Model::__construct() &#8211; CORE\\Cake\\Model\\Model.php, line 748 ReflectionClass::newInstance() &#8211; &#x5B;internal], line ?? ClassRegistry::init() &#8211; CORE\\Cake\\Utility\\ClassRegistry.php, line 164 Model::_constructLinkedModel() &#8211; CORE\\Cake\\Model\\Model.php, line 1031 Model::__isset() &#8211; CORE\\Cake\\Model\\Model.php, line 857 Model::__get() &#8211; CORE\\Cake\\Model\\Model.php, line 887 DboSource::read() &#8211; CORE\\Cake\\Model\\Datasource\\DboSource.php, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31,3,29,4],"tags":[],"class_list":["post-318","post","type-post","status-publish","format-standard","hentry","category-cakephp","category-code","category-framework","category-php"],"_links":{"self":[{"href":"http:\/\/syarman.com\/soft\/wp-json\/wp\/v2\/posts\/318","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/syarman.com\/soft\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/syarman.com\/soft\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/syarman.com\/soft\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/syarman.com\/soft\/wp-json\/wp\/v2\/comments?post=318"}],"version-history":[{"count":3,"href":"http:\/\/syarman.com\/soft\/wp-json\/wp\/v2\/posts\/318\/revisions"}],"predecessor-version":[{"id":323,"href":"http:\/\/syarman.com\/soft\/wp-json\/wp\/v2\/posts\/318\/revisions\/323"}],"wp:attachment":[{"href":"http:\/\/syarman.com\/soft\/wp-json\/wp\/v2\/media?parent=318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/syarman.com\/soft\/wp-json\/wp\/v2\/categories?post=318"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/syarman.com\/soft\/wp-json\/wp\/v2\/tags?post=318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}