1

プロジェクト/index.php

<?php
error_reporting(E_ALL|E_STRICT);
date_default_timezone_set('Europe/London');
set_include_path('.' . PATH_SEPARATOR . './library'
. PATH_SEPARATOR . './application/models/'
. PATH_SEPARATOR . get_include_path());
include "Zend/Loader.php";
Zend_Loader::loadClass('Zend_Controller_Front');
// setup controller
$frontController = Zend_Controller_Front::getInstance();
$frontController->throwExceptions(true);
$frontController->setControllerDirectory('./application/controllers');
// run!
$frontController->dispatch();
?>

Zend/コントローラー/Front.php

<?php
...
class Zend_Controller_Front
{
...
    protected static $_instance = null;
...
    protected $_throwExceptions = false;
...
    protected function __construct()
        {
            $this->_plugins = new Zend_Controller_Plugin_Broker();
        }
...
    public static function getInstance()
        {
            if (null === self::$_instance) {
                    self::$_instance = new self();
            }

        return self::$_instance;
        }
...
    public function throwExceptions($flag = null)
        {
            if ($flag !== null) {
                    $this->_throwExceptions = (bool) $flag;
                    return $this;
            }

            return $this->_throwExceptions;
        }
...
}
...
?>

質問:

  1. $this->_plugins = new Zend_Controller_Plugin_Broker(); このクラスの使用法は何ですか: Zend_Controller_Plugin_Broker? project/index.php では何もしていないようです
  2. public function throwExceptions($flag = null) なぜ $flag !== null, return $this;その間に$flag == null, return $this->_throwExceptions;?両方とも $this を返さないのはなぜですか?
  3. $frontController->setControllerDirectory('./application/controllers');「。」現在のディレクトリを意味しますか?なぜ「.」が必要なのですか?
4

1 に答える 1

1

このクラスの使い方: Zend_Controller_Plugin_Broker?

コントローラーのプラグインを管理するためのものです。$front->registerPlugin()プラグイン ブローカーを呼び出すと、その呼び出しが処理されます。詳細については、 http://framework.zend.com/manual/1.12/en/zend.controller.plugins.htmlを参照してください。

$flag !== null の理由 $this を返します。$flag == null の場合、$this->_throwExceptions を返します;?

これにより、関数は 2 つの目的を果たすことができます。パラメータなしで呼び出すと、throwExceptions の現在の値が返されます。パラメータを指定して呼び出すと、値が設定されます。

$frontController->setControllerDirectory('./application/controllers'); 「。」現在のディレクトリを意味しますか?なぜ「.」が必要なのですか?

なぜだめですか?パスが現在のディレクトリからの相対パスであることが明確になります。

于 2013-04-18T11:28:15.567 に答える