【问题标题】:How to copy Joomla administrator component as a site one?如何将 Joomla 管理员组件复制为站点之一?
【发布时间】:2016-03-30 12:10:19
【问题描述】:

我已经安装了Joomla v3.4.7来测试和准备我的项目。我按照官方教程一步一步创建了一个组件'HelloWorld' [https://docs.joomla.org/J3.x:Developing_an_MVC_Component/Using_the_database][1] ,我成功地显示了数据列表,然后在编辑页面添加或编辑现有数据,从管理员部分,就像

localhost/joomla-test/administrator/index.php?option=com_helloworld

完成这些后,我只是将/Administrator/components/com_helloworld中的文件复制到/components/com_helloworld并覆盖之前的文件,然后访问站点组件:

localhost/joomla-test/index.php?option=com_helloworld

没用!我用萤火虫调试,我得到了一个

NetworkError: 500 内部服务器错误 - http://localhost/joomla-test/index.php?option=com_helloworld

错误....发生了什么?

我的代码:

网站/helloworld.php:

<?php
 // import joomla controller library
 jimport('joomla.application.component.controller');

 // Get an instance of the controller prefixed by HelloWorld
 $controller = JControllerLegacy::getInstance('HelloWorld');

 // Perform the Request task
 $controller->execute(JFactory::getApplication()->input->getCmd('task'));

 // Redirect if set by the controller
 $controller->redirect();

网站/controller.php

<?php
// No direct access to this file
defined('_JEXEC') or die;

// import Joomla controller library
jimport('joomla.application.component.controller');

/**
 * General Controller of HelloWorld component
*/
class HelloWorldController extends JControllerLegacy
{
    /**
     * display task
     *
     * @return void
     */
    protected $default_view = 'helloworlds';

    public function display($cachable = false)
    {              
        parent::display($cachable);
        echo "controller";
        return $this;
    }
}

站点/视图/helloworlds/view.html.php:

<?php
   // No direct access to this file
   defined('_JEXEC') or die;

   // import Joomla view library
   jimport('joomla.application.component.view');

   /**
    * HelloWorlds View
    */
   class HelloWorldViewHelloWorlds extends JViewLegacy
   {
    /**
     * HelloWorlds view display method
     * @return void
     */
    function display($tpl = null) 
    {
        // Get data from the model
        $items = $this->get('Items');
        $pagination = $this->get('Pagination');

        // Check for errors.
        if (count($errors = $this->get('Errors'))) 
        {
            JError::raiseError(500, implode('<br />', $errors));
            return false;
        }
        // Assign data to the view
        $this->items = $items;
        $this->pagination = $pagination;

        // Set the toolbar
        $this->addToolBar();

        // Display the template
        parent::display($tpl);
    }

    /**
     * Setting the toolbar
     */
    protected function addToolBar() 
    {
            JToolBarHelper::title(JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLDS'));
        JToolBarHelper::deleteList('', 'helloworlds.delete');
        JToolBarHelper::editList('helloworld.edit');
        JToolBarHelper::addNew('helloworld.add');
    }
}

请帮忙,谢谢大家。

【问题讨论】:

    标签: php joomla components administrator


    【解决方案1】:

    这种方式不起作用(只需将文件夹复制过来)。您必须通过打包组件然后将其安装在服务器上来安装组件。您需要在服务器上安装压缩组件(具有 XML 清单文件)。

    尝试以下操作:从 Joomla 下载基本的 HelloWorld 组件,然后将其安装到您的网站上,然后用本地主机上的文件覆盖它。

    【讨论】:

      【解决方案2】:

      站点和管理员略有不同;最相关的是与模板相关的,因为在 Admin 中您可以依靠标准布局;这就是为什么在管理员 view.html 中设置工具栏和侧边菜单的原因;在前端,您可以创建指向具有配置的视图的菜单。

      您最好的选择是为控制器和视图创建新文件,然后您可以创建从管理员模块继承的模型,这是避免代码重复的最佳方式,它仍然可以为您提供最大的灵活性来自定义意见。

      【讨论】:

        【解决方案3】:

        工具栏不能在前端工作。是的,这很奇怪,但如果你看它是管理员文件夹中的一个单独的东西。它实际上也检查您是否处于管理员状态。我曾经做了一个补丁来删除检查,但结果证明它会破坏大量可以解决这个问题的组件。
        其次,有许多调用依赖于相对定位或者甚至可能明确需要管理员访问权限的事物。 第三,确实有些东西略有不同,因为在后端你基本上从不渲染普通视图,只渲染列表视图和编辑视图。

        如果您想在前端执行管理功能,最好的通用方法是查看 com_config、Com_templates 和 com_modules 是如何做到的。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-01-24
          • 2017-02-18
          • 2016-09-29
          • 2012-09-30
          • 2018-07-15
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多