【问题标题】:Joomla!2.5 ACL doesn't show options [closed]Joomla!2.5 ACL 不显示选项 [关闭]
【发布时间】:2013-03-21 22:59:51
【问题描述】:

我是 Joomla 的业余爱好者,因为我上周才开始使用这个框架进行开发。截至目前,我正在阅读官方的 Joomla 教程,可以在他们的官方 Wiki 中找到。但是要么我做错了什么,要么我忘记了一些东西,或者在所述教程中没有提到。

我完成的最后一步是开发访问控制列表;但是,维护按钮没有显示。

这是我到目前为止的代码:

admin/views/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(部分)

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-&gt;canDo) 对此进行调试,但没有得到任何响应。我可能错过了什么?


更新: var_dumping $this-&gt;canDo 在 vi​​ews/HelloWorlds/view.html.php 中返回:

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();
}

【问题讨论】:

    标签: php joomla2.5 access-control


    【解决方案1】:

    问题解决了,这是一件愚蠢的事情,我为自己感到羞耻,我没有意识到这一点。只是admin/access.xml没有在helloworld.xml中描述。

    【讨论】:

      【解决方案2】:

      据我了解,您关注this tutorial。您能否再检查一次您的代码和创建的文件?因为我 100% 确定本教程的步骤是正确的(我自己做了很多次)。您缺少某些东西或在某处犯了一个小错误。

      【讨论】:

      • 这是我正在关注的确切教程。我已经多次仔细检查了代码,但由于某种原因,我似乎无法正确处理。是否有某种注册/调整访问选项以便显示按钮?
      • 如果您以超级用户身份登录,则无需调整。据我所见,视图是正确的。你写道var_dump($this-&gt;canDo)什么都不给。这是我倾倒它的东西:object(JObject)#164 (6) { ["_errors":protected]=&gt; array(0) { } ["core.admin"]=&gt; bool(true) ["core.manage"]=&gt; bool(true) ["core.create"]=&gt; bool(true) ["core.delete"]=&gt; bool(true) ["core.edit"]=&gt; bool(true) }。可能是帮助文件中的问题?
      • 用助手的代码编辑了主帖。
      • 帮手很好。我有同样的。但是为什么它在 helloworld 和 helloworlds 视图上都没有返回任何内容,这是个问题。您是否也设置了 admin/access.xml 和文件?所有操作都在那里,您可以在组件的配置中配置它们吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-29
      • 2012-08-18
      • 1970-01-01
      • 1970-01-01
      • 2012-12-10
      • 1970-01-01
      相关资源
      最近更新 更多