0

ZF2 の方法でオンザフライで ZF1 に示されている次の __construct セクションを実行するにはどうすればよいですか?

$this->headTitle('..');->view 呼び出しを省略してみましたが、それでもスローして失敗します:

Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for headTitle

  public function __construct() { //init is gone 

    $this->_helper->layout()->setLayout('brand');
    $this->HeadTitle($this->title)->setIndent(8);
    $this->view->headMeta()->appendName('keywords', $this->keyword)->setIndent(8);
    $this->view->headMeta()->appendName('description', $this->description)->setIndent(8);
    $this->view->headMeta()->appendName('Language', 'en')->setIndent(8);

    $this->view->headMeta()->appendName('dc.title', $this->title)->setIndent(8);
    $this->view->headMeta()->appendName('dc.keywords', $this->keyword)->setIndent(8);
    $this->view->headMeta()->appendName('dc.description', $this->description)->setIndent(8);

    $this->view->headLink()->appendStylesheet('/css/main.css')->setIndent(8);
    $this->view->headLink()->appendStylesheet('/jquery/css/custom-theme/jquery-ui-
1.8.20.custom.css')->setIndent(8);

    $post = $this->getRequest()->getPost();
    $get = $this->getRequest()->getQuery();
  }
4

4 に答える 4

4

アクション コントローラーで「レンダラー」オブジェクトにアクセスできます。

public function indexAction()
{
    $renderer = $this->getServiceLocator()->get('Zend\View\Renderer\PhpRenderer');
    $renderer->headTitle('My title');

    return new ViewModel();
}
于 2012-10-23T09:11:12.037 に答える
0

同じ質問があり、layout.phtml ファイルのように headTitle を使用する ZF2 プラグインを開発しました。 https://github.com/remithomas/rt-headtitle

public function indexAction(){
  $this->headTitle("My website")->setSeparator(" - ")->append("easy ?!");
  return new ViewModel();
}
于 2013-03-25T15:36:55.283 に答える