我正在做整個孩子的生成鏈接。因爲View不允許使用Model。這就是爲什麼我必須讓自己的助手生成。然後我用$this->Model->children($current_id, false, 'category');
但問題我有錯誤這樣如何在CakePHP 2.0中將子項()導入Helper?
Fatal error: Call to a member function children() on a non-object in /user/app/View/Helper/my_helper.php on line 193
我的代碼:
<?php
class MyHelperHelper extends AppHelper {
var $helpers = array('Html','Paginator','Tree');
function makechildrenlink($current_id, $category_id, $item_id) {
$this->Category->children($current_id, false, 'category');
}
}
?>
你爲什麼使用視圖層從模型中獲取數據?讓控制器/組件執行該操作並將其傳遞給幫助器。另外,'my_helper.php'不是蛋糕2中文件名的樣子2.x – mark
my_helper.php是我自己做的工具。因爲從那個my_helper.php中有很多項使用函數,但是Helper不能使用children()來創建Parent的所有子項列表。 – user453089
Geeze - '$ this-> Category'。如果你從未宣佈這應該是這個幫手的內容,這怎麼可能起作用呢? PHP並不神奇。 CakePHP在某種程度上是這樣,但也不是那麼重要。 – mark