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/Controller/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;?

它允许函数有两个目的。如果不带参数调用它,则返回 throwExceptions 的当前值。如果您使用参数调用它,则您正在设置值。

$frontController->setControllerDirectory('./application/controllers'); “。” 是指当前目录?为什么我们需要有“。”?

为什么不?它更清楚地表明路径是相对于当前目录的。

于 2013-04-18T11:28:15.567 回答