我是Joomla的业余爱好者,因为我上周才开始使用此框架进行开发。截至目前,我正在浏览官方Wiki中发现的Joomla官方教程。但是,无论我做错了什么,或者有什么我忘记了,或者在上述教程中没有提及。Joomla!2.5 ACL不显示选项
我经历的最后一步是开发访问控制列表;但是,维护按钮没有显示。
下面的代码我怎么有这么远:
管理/视图/的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');
}
}
管理/助理/ 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->canDo)
来调试,但我没有得到任何回应。我可能错过了什么?
更新:var_dump
的意见荷兰国际集团$this->canDo
/HelloWorlds/view.html.php返回此:
object(JObject)#43 (1) { ["_errors":protected]=> array(0) { } }
这里的呼吁表示,意见函数/ 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();
}
这是我正在遵循的确切教程。我多次检查了代码,并且出于某种原因,我似乎无法做到这一点。 是否有某种注册/调整访问选项,以便按钮显示? – TheGEffect 2013-03-21 13:52:27
如果您以超级用户身份登录,无需进行任何调整。据我所见,视图是正确的。你写了'var_dump($ this-> canDo)'什么也不给。这里我倾倒它:'object(JObject)#164(6){[“_errors”:protected] => array(0){} [“core.admin”] => bool(true)[“core。管理“] => bool(true)[”core.create“] => bool(true)[”core.delete“] => bool(true)[”core.edit“] => bool(true) 。可能是辅助文件中的问题? – 2013-03-21 14:11:45
用佣工代码编辑主帖。 – TheGEffect 2013-03-21 14:16:18