0

私は先週このフレームワークで開発を始めたばかりなので、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 (一部)

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)が、応答がありません。何が欠けている可能性がありますか?


更新: views/HelloWorlds/view.html.php でvar_dumpingを実行すると、次のように返されます。$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();
}
4

2 に答える 2

2

問題は解決しました、それは私が自分自身を恥じている愚かなことでした。admin/access.xmlに記載されていなかっただけですhelloworld.xml

于 2013-03-21T14:59:51.943 に答える
0

私が理解しているように、このチュートリアルに従ってください。コードと作成されたファイルをもう一度確認していただけますか? このチュートリアルの手順が正しいことを 100% 確信しているからです (自分で何度も実行しました)。どこかに欠けているものや少し間違っているものがあります。

于 2013-03-21T13:50:38.833 に答える