对于Joomla来说,我是一名业余爱好者,因为我上周才开始使用这个框架进行开发。截至目前,我正在阅读官方Wiki中的官方Joomla教程。但要么是我做错了,要么就是我忘记了,或者说在教程中没有提到。
我经历的最后一步是开发访问控制列表;但是,维护按钮没有显示。
以下是我到目前为止的代码:
管理员/视图/的HelloWorld / view.html.php
class HelloWorldViewHelloWorld extends JView {
protected $form;
protected $item;
protected $script;
protected $canDo;
public function display($tpl = NULL){
$this->form = $this->get('Form');
$this->item = $this->get('Item');
$this->script = $this->get('Script');
$this->canDo = HelloWorldHelper::getActions($this->item->id);
if(count($errors = $this->get('Errors'))){
JError::raiseError(500, implode('<br />', $errors));
return false;
}
$this->addToolBar();
parent::display($tpl);
$this->setDocument();
}
protected function addToolBar(){
$input = JFactory::getApplication()->input;
$input->set('hidemainmenu', true);
$isNew = ($this->item->id == 0);
JToolBarHelper::title($isNew ? JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLD_NEW') : JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLD_EDIT'), 'helloworld');
if($isNew){
if($this->canDo->get('core.create')){
JToolBarHelper::apply('helloworld.apply', 'JTOOLBAR_APPLY');
JToolBarHelper::save('helloworld.save', 'JTOOLBAR_SAVE');
JToolBarHelper::custom('helloworld.save2copy', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AS_COPY', false);
}
JToolBarHelper::cancel('helloworld.cancel', 'JTOOLBAR_CANCEL');
} else {
if($this->canDo->get('core.edit')){
JToolBarHelper::apply('helloworld.apply', 'JTOOLBAR_APPLY');
JToolBarHelper::save('helloworld.save', 'JTOOLBAR_SAVE');
if($this->canDo->get('core.create')){
JToolBarHelper::custom('helloworld.save2copy', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AND_NEW', false);
}
}
if($this->canDo->get('core.create')){
JToolBarHelper::custom('helloworld.save2copy', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AS_COPY', false);
}
JToolBarHelper::cancel('helloworld.cancel', 'JTOOLBAR_CLOSE');
}
}
protected function setDocument(){
$isNew = ($this->item->id < 1);
$document = JFactory::getDocument();
$document->setTitle($isNew ? JText::_('COM_HELLOWORLD_HELLOWORLD_CREATING') : JText::_('COM_HELLOWORLD_HELLOWORLD_EDITING'));
$document->addScript(JURI::root() . $this->script);
$document->addScript(JURI::root() . "/administrator/components/com_helloworld/views/helloworld/submitbutton.js");
JText::script('COM_HELLOWORLD_HELLOWORLD_ERROR_UNACCEPTABLE');
}
}
admin / helpers / helloworld.php(part)
abstract class HelloWorldHelper {
[...]
public static function getActions($messageId = 0){
jimport('joomla.access.access');
$user = JFactory::getUser();
$result = new JObject;
if(empty($messageId)){
$assetName = 'com_helloworld';
} else {
$assetName = 'com_helloworld.message.' . (int) $messageId;
}
$actions = JAccess::getActions('com_helloworld', 'component');
foreach($actions as $action){
$result->set($action->name, $user->authorise($action->name, $assetName));
}
return $result;
}
}
我尝试使用var_dump($this->canDo)
进行调试,但我没有得到回应。我可能错过了什么?
var_dump
$this->canDo
会返回:
object(JObject)#43 (1) { ["_errors":protected]=> array(0) { } }
这是对views / HelloWorlds / view.html.php中所述函数的调用:
function display($tpl = NULL){
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->canDo = HelloWorldHelper::getActions();
if(count($errors = $this->get('Errors'))){
JError::raiseError(500, implode('<br />', $errors));
return false;
}
$this->addToolBar($this->pagination->total);
parent::display($tpl);
$this->setDocument();
}
答案 0 :(得分:2)
问题解决了,这是一个愚蠢的事我自己感到惭愧我没有意识到这一点。只是admin/access.xml
中没有描述helloworld.xml
。
答案 1 :(得分:0)
据我了解,您关注this tutorial。你可以再次检查你的代码和创建文件吗?因为我100%确定本教程的步骤是正确的(多次由我自己完成)。有些东西你在某处丢失或犯了一个小错误。