【发布时间】: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