質問

私は「/アプリケーション/ビュー/スクリプト/フォーム/」の下に私のフォーム要素のビュースクリプトを入れ始め、「形式/ scriptname.phtml」でそれらを参照することができたが、今は「フォームのコントローラを作成する必要がありましたそして私は、これは近視眼的解決策だった実現しています。私が使用することを見てきた例のような何か「/パス/あなた/ビュー/スクリプト/ /」への論理何で私を助けていない/それらを置く場所をお勧めします。

ありがとうございます。

役に立ちましたか?

解決

私は非標準のファイル構造を使用して、私のアプリケーションのためのモジュールを使用します:

/application
  /default
    /controllers
      /IndexController
      /ErrorController
    /views
      /scripts
        /index
          /index.phtml
        /error
          /error.phtml
/configs
  /config.ini
/library
  /Zend
/views
  /layouts
    /default.phtml
  /scripts
    /form
      /_text.phtml

このようにそれを行うには、あなたがZend_Applicationのためにあなたの設定で、モジュールのディレクトリを追加する必要があります:

[production]

phpsettings.display_startup_errors = 0
phpsettings.display_errors = 0
resources.layout.layout = "default"
resources.layout.layoutpath = "c:\xampp\files\views\layouts"
resources.frontcontroller.moduledirectory = "c:\xampp\files\application"

[development : production]

phpsettings.display_startup_errors = 1
phpsettings.display_errors = 1

ビュースクリプトのパスは、LIFO順にロードされます。あなたがアクションコントローラのinit()メソッドでは、このようにあなたのスクリプトのパスを追加することができ、あなたが他のスクリプトのパスを追加していないと仮定します:

<?php

class IndexController extends Zend_Controller_Action {

  public function init() {

    $appScriptPath = 'c:\xampp\files\views\scripts';
    $modScriptPath = array_shift($this->view->getScriptPaths());

    $this->view->setScriptPath(NULL);

    $this->view->addScriptPath($appScriptPath);
    $this->view->addScriptPath($modScriptPath);

  }

  public function indexAction() {

    $form = new Zend_Form();

    $form->addElement(new Zend_Form_Element_Text('text'));
    $form->text->setLabel('Text');
    $options = array('viewScript' => 'form/_text.phtml');
    $decorators = array(array('ViewScript', $options));
    $form->text->setDecorators($decorators);

    $this->view->form = $form;

  }

}

システムが最初にあなたのviewScriptのためのコントローラのビュースクリプトになりますし、それが見つからない場合は、その後、それは/アプリケーション/ビュー/スクリプトの中になります。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top