1. <small id='VX44v'></small><noframes id='VX44v'>

    2. <i id='VX44v'><tr id='VX44v'><dt id='VX44v'><q id='VX44v'><span id='VX44v'><b id='VX44v'><form id='VX44v'><ins id='VX44v'></ins><ul id='VX44v'></ul><sub id='VX44v'></sub></form><legend id='VX44v'></legend><bdo id='VX44v'><pre id='VX44v'><center id='VX44v'></center></pre></bdo></b><th id='VX44v'></th></span></q></dt></tr></i><div id='VX44v'><tfoot id='VX44v'></tfoot><dl id='VX44v'><fieldset id='VX44v'></fieldset></dl></div>

        <legend id='VX44v'><style id='VX44v'><dir id='VX44v'><q id='VX44v'></q></dir></style></legend>

          <bdo id='VX44v'></bdo><ul id='VX44v'></ul>
        <tfoot id='VX44v'></tfoot>

        Joomla 1.6 JCategories::get() 方法在自定义 MVC 组件中产生“PHP 致命错误:允许内存

        时间:2023-10-16
          <tbody id='0q912'></tbody>

      1. <tfoot id='0q912'></tfoot>
        <legend id='0q912'><style id='0q912'><dir id='0q912'><q id='0q912'></q></dir></style></legend>
        <i id='0q912'><tr id='0q912'><dt id='0q912'><q id='0q912'><span id='0q912'><b id='0q912'><form id='0q912'><ins id='0q912'></ins><ul id='0q912'></ul><sub id='0q912'></sub></form><legend id='0q912'></legend><bdo id='0q912'><pre id='0q912'><center id='0q912'></center></pre></bdo></b><th id='0q912'></th></span></q></dt></tr></i><div id='0q912'><tfoot id='0q912'></tfoot><dl id='0q912'><fieldset id='0q912'></fieldset></dl></div>

          • <bdo id='0q912'></bdo><ul id='0q912'></ul>

                1. <small id='0q912'></small><noframes id='0q912'>

                  本文介绍了Joomla 1.6 JCategories::get() 方法在自定义 MVC 组件中产生“PHP 致命错误:允许内存耗尽"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在按照 Joomla 1.6 文档.

                  我在尝试使用 JCategories::get()com_component 获取类别及其子项的列表时遇到问题.我收到以下错误:

                  I am running into a problem when trying to use JCategories::get() to obtain a list of categories and their children from com_component. I receive the following error:

                  PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 125306881 bytes)
                  

                  如果我发出print_r($this->items);来列出项目,我不会收到错误.如果我改变行

                  If I do not issue a print_r($this->items); to list the items, I do not receive an error. If I change the line

                  $categories = JCategories::getInstance('Content');

                  阅读

                  $categories = JCategories::getInstance('banners');

                  没有收到错误消息.

                  我在下面包含了我的所有自定义组件代码.仅供参考,过去几天我一直在 irc.freenode.net/#joomla 与任何愿意提供帮助的人交谈,但进展甚微.任何帮助将不胜感激.

                  I have included all of my custom component code below. Just as an FYI, I've spent the past couple of days in irc.freenode.net/#joomla speaking with anyone willing to help with very little progress made. Any help would be much appreciated.

                  控制器代码:

                    <?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>
                  

                  推荐答案

                  我发现尝试 var_dump()print_r() JCategoryNode 会导致无限循环.因此,我将上面的模型修改为以下内容:

                  I found that attempting to var_dump() or print_r() JCategoryNode results in an endless loop. Therefore, I modified my model above to the following:

                  <?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->loadCats($this->_items);
                      }
                  
                  
                      protected function loadCats($cats = array())
                      {
                  
                          if(is_array($cats))
                          {
                              $i = 0;
                              $return = array();
                              foreach($cats as $JCatNode)
                              {
                                  $return[$i]->title = $JCatNode->title;
                                  if($JCatNode->hasChildren())
                                      $return[$i]->children = $this->loadCats($JCatNode->getChildren());
                                  else
                                      $return[$i]->children = false;
                  
                                  $i++;
                              }
                  
                              return $return;
                          }
                  
                          return false;
                  
                      }
                  
                  }
                  

                  这篇关于Joomla 1.6 JCategories::get() 方法在自定义 MVC 组件中产生“PHP 致命错误:允许内存耗尽"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在使用 Component Creator 构建的 Joomla 3.x 组件的一个视图中包含多个模型 下一篇:邮件内容在 Joomla 3 中显示为 html 代码

                  相关文章

                  <i id='53x3a'><tr id='53x3a'><dt id='53x3a'><q id='53x3a'><span id='53x3a'><b id='53x3a'><form id='53x3a'><ins id='53x3a'></ins><ul id='53x3a'></ul><sub id='53x3a'></sub></form><legend id='53x3a'></legend><bdo id='53x3a'><pre id='53x3a'><center id='53x3a'></center></pre></bdo></b><th id='53x3a'></th></span></q></dt></tr></i><div id='53x3a'><tfoot id='53x3a'></tfoot><dl id='53x3a'><fieldset id='53x3a'></fieldset></dl></div>

                      <bdo id='53x3a'></bdo><ul id='53x3a'></ul>
                    <tfoot id='53x3a'></tfoot>
                  1. <small id='53x3a'></small><noframes id='53x3a'>

                      <legend id='53x3a'><style id='53x3a'><dir id='53x3a'><q id='53x3a'></q></dir></style></legend>