doufu9521 2015-12-24 01:36
浏览 69

如何将Joomla管理员组件复制为站点组件?

I've installed Joomla v3.4.7 to test and prepare my project.I created a component 'HelloWorld' step by step according the official tutorial [https://docs.joomla.org/J3.x:Developing_an_MVC_Component/Using_the_database][1] ,and I succeeded to show the data list,and then the editing page to add or edit existing data, from the Administrator part, just like

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

After finishing these, I simply copied the files in /Administrator/components/com_helloworld to /components/com_helloworld and overwrite previous files, and access the site component:

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

It didn't work! I used firebug to debug and I got a

NetworkError: 500 Internal Server Error - http://localhost/joomla-test/index.php?option=com_helloworld

error.... What's happened?

My code:

Site/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();

site/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;
    }
}

site/views/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');
    }
}

Please help, thank you all.

  • 写回答

3条回答 默认 最新

  • doukesou4452 2015-12-24 12:37
    关注

    It doesn't work this way (by just copying the folder over). You will have to install the component by packaging it and then installing it on the server. You will need to install the zipped component (that has the XML manifest file) on the server.

    Try the following: download the basic HelloWorld component from Joomla, and then install it on your website, and then overwrite it with the files from your localhost.

    评论

报告相同问题?

悬赏问题

  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划