我在執行Joomla 1.6 Documentation之後的自定義MVC組件。Joomla 1.6 JCategories :: get()方法在自定義MVC組件中產生'PHP致命錯誤:允許的內存耗盡'
我在嘗試使用JCategories::get()
從com_component
獲取類別及其子項列表時遇到問題。我收到以下錯誤:
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 125306881 bytes)
如果我不問題一個print_r($this->items);
列出的項目,我做不收到一個錯誤。如果我更改線路
$categories = JCategories::getInstance('Content');
閱讀
$categories = JCategories::getInstance('banners');
我做不收到錯誤。
我在下面列出了我所有的自定義組件代碼。就像一個供參考,我已經花了幾天的時間在irc.freenode.net/#joomla與任何願意幫助取得很少進展的人交談。任何幫助將非常感激。
控制器代碼:
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import joomla controller library
jimport('joomla.application.component.controller');
$controller = JController::getInstance('CtItem');
$controller->execute(JRequest::getCmd('task'));
$controller->redirect();
型號代碼:
<?php
// No direct access to this file
defined('_JEXEC') or die;
// import Joomla Categories library
jimport('joomla.application.categories');
class CtItemModelCtItem extends JModel
{
private $_items = null;
private $_parent = null;
public function getItems($recursive = false)
{
$categories = JCategories::getInstance('Content');
$this->_parent = $categories->get(15);
if(is_object($this->_parent))
{
$this->_items = $this->_parent->getChildren($recursive);
}
else
{
$this->_items = false;
}
return $this->_items;
}
}
查看代碼:
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla view library
jimport('joomla.application.component.view');
class CtItemViewCtItem extends JView
{
// Overwriting JView display method
function display($tpl = null)
{
// Assign data to the view
$this->items = $this->get('Items');
if(count($errors = $this->get('Errors')))
{
JError::raiseError(500, implode('<br />', $errors));
return false;
}
// Display the view
parent::display($tpl);
}
}
模板代碼:
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
$document = JFactory::getDocument();
?>
<div id="Test"><?=print_r($this->items, true)?></div>