php - trying to understand some codes in zend framework -


project/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;         } ... } ... ?> 

questions:

  1. $this->_plugins = new zend_controller_plugin_broker(); usage of class:zend_controller_plugin_broker? seems not anyhing in project/index.php
  2. public function throwexceptions($flag = null) why $flag !== null, return $this; while $flag == null, return $this->_throwexceptions;? why not both return $this?
  3. $frontcontroller->setcontrollerdirectory('./application/controllers'); "." means current directory? why need have "."?

what usage of class:zend_controller_plugin_broker?

it managing controller plugins. if call $front->registerplugin() plugin broker handles call. see http://framework.zend.com/manual/1.12/en/zend.controller.plugins.html more info.

why $flag !== null, return $this; while $flag == null, return $this->_throwexceptions;?

it allows function serve 2 purposes. if call no parameters, current value of throwexceptions returned. if call parameter setting value.

$frontcontroller->setcontrollerdirectory('./application/controllers'); "." means current directory? why need have "."?

why not? makes clearer path relative current directory.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -