7.3. ¼­ºê Ŭ·¡½ºÈ­

7.3.1. µµÀÔ

Zend_Controller ½Ã½ºÅÛÀº, È®À强À» °í·ÁÇØ ÀÛ¼ºµÇ°í ÀÖ½À´Ï´Ù. È®Àå ¹æ¹ýÀ¸·Î¼­´Â, ±âÁ¸ÀÇ Å¬·¡½º¸¦ °è½ÂÇÏ´Â °Í ¿Ü¿¡µµ Zend_Controller_Router_Interface ¹× Zend_Controller_Dispatcher_Interface (À»)¸¦ ½ÇÀåÇÑ »õ·Î¿î Ŭ·¡½º¸¦ ÀÛ¼ºÇÏ´Â ¹æ¹ýÀÌ ÀÖ½À´Ï´Ù.¶Ç, Zend_Controller_Request_Abstract (ÀÌ)³ª Zend_Controller_Response_Abstract ±×¸®°í Zend_Controller_Action (À»)¸¦ °è½ÂÇÑ Å¬·¡½º¸¦ ÀÛ¼ºÇÒ ¼öµµ ÀÖ½À´Ï´Ù.

Ŭ·¡½º¸¦ È®ÀåÇÏ´Â ÀÌÀ¯·Î¼­´Â, ÀÌÇÏ¿Í °°Àº °ÍÀ» »ý°¢ÇÒ ¼ö ÀÖ°ÚÁö¿ä.

  • ±âÁ¸ÀÇ URI ·çÆÃÀÌ ¾î¶°ÇÑ ÀÌÀ¯·Î Àû¿ëÇÒ ¼ö ¾ø´Â °æ¿ì. ¿¹¸¦ µé¸é, ±âÁ¸ÀÇ À¥ »çÀÌÆ®¿Í ÅëÇÕÇÒ ¿¹Á¤ÀÌÁö¸¸, °Å±â¼­ ä¿ëÇϰí ÀÖ´Â ±Ô¾àÀÌ Zend Framework ÀÇ ·çÆÃ ±â±¸¿Í ÇÕÄ¡ÇÏÁö ¾Ê´Â µî.

  • ¿ÏÀüÈ÷ º°°³ÀÇ ·çÆÃÀ» ½ÇÀåÇØ¾ß ÇÏ´Â °æ¿ì. Zend_Controller_Router Ŭ·¡½º´Â URI ¸¸À» ´ë»óÀ¸·Î Çϰí ÀÖ½À´Ï´Ù. ¿¹¸¦ µé¸é ÄÜ¼Ö ÇÁ·Î±×·¥À̳ª GUI ¾îÇø®ÄÉÀ̼ǵîÀÇ ´Ù¸¥ Çü½ÄÀÇ ÇÁ·Î±×·¥¿¡µµ MVC ÆÐÅÏÀ» »ç¿ëÇÏ°í ½Í¾îÁö±âµµ ÇϰÚÁö¿ä. ÄÜ¼Ö ÇÁ·Î±×·¥ÀÇ °æ¿ì¶ó¸é, µ¶ÀÚÀûÀÎ ¶ó¿ìÅ͸¦ ½ÇÀåÇϸé Ä¿¸àµå ¶óÀÎ Àμö¿¡ ÀÇÇÑ ·çÆÃÀ» ½Ç½ÃÇÒ ¼öµµ ÀÖ½À´Ï´Ù.

  • Zend_Controller_Dispatcher ÀÇ Á¦°øÇÏ´Â ±â´ÉÀÌ Àß µé¾î¸ÂÁö ¾Ê´Â °æ¿ì. µðÆúÆ® ¼³Á¤¿¡¼­´Â, ÄÜÆ®·Ñ·¯´Â Ŭ·¡½ºÀ̸ç, ¾×¼ÇÀº Ŭ·¡½ºÀÇ ¸Þ¼ÒµåÀÎ °ÍÀ» ÀüÁ¦·Î Çϰí ÀÖ½À´Ï´Ù. ±×·¯³ª, À̿ܿ¡µµ ¿©·¯°¡Áö ¹æ½ÄÀÌ ÀÖ°ÚÁö¿ä. ¿¹¸¦ µé¸é, µð·ºÅ丮¸¦ ÄÜÆ®·Ñ·¯, µð·ºÅ丮³»ÀÇ ÆÄÀÏÀ» ¾×¼ÇÀ̶ó°í »ý°¢ÇÒ ¼öµµ ÀÖ½À´Ï´Ù.

  • ¸ðµç ÄÜÆ®·Ñ·¯·Î »ç¿ëÇϱâ À§ÇÑ ±â´ÉÀ» Ãß°¡ÇÏ°í ½ÍÀº °æ¿ì. ¿¹¸¦ µé¸é, µðÆúÆ®¿¡¼­´Â Zend_Controller_Action ÇÏ Zend_View (¿Í)°ú ÅëÇյǰí ÀÖÁö ¾Ê½À´Ï´Ù.±×·¯³ª, ÄÜÆ®·Ñ·¯¸¦ °è½ÂÇÑ Å¬·¡½º¿¡¼­ ÀÌ ±â´ÉÀ» °®°ÔÇÒ ¼ö ÀÖ½À´Ï´Ù. ±×·¯¸é, ¿ø·¡ÀÇ Zend_Controller_Router (ÀÌ)³ª Zend_Controller_Dispatcher ¿¡ ¼Õº¸Áö ¾Ê°í ³¡³³´Ï´Ù.

  • ¾îÇø®ÄÉÀ̼ÇÀ¸·Î ¹ß»ýÇÑ ¿¹¿Ü¸¦ ±â·ÏÇØ, °øÅëÀÇ ¿¡·¯ ÆäÀÌÁö¿¡ ¸®µð·ºÆ® ½ÃŰ°í ½ÍÀº °æ¿ì.±âÁ¸ÀÇ Zend_Controller_Response_Http (À»)¸¦ È®ÀåÇØ, __toString() (À»)¸¦ º¯°æÇÏ´Â °ÍÀ¸·Î, µî·ÏµÈ ¿¹¿ÜÀÇ Ã¼Å©¿Í ±× ±â·Ï, ¿¡·¯ ÆäÀÌÁö·ÎÀÇ ¸®µð·ºÆ®°¡ °¡´ÉÇØÁý´Ï´Ù.

½Ã½ºÅÛÀÇ ÁÖ¿äÇÑ ºÎºÐ, ƯÈ÷ µð½ºÆÖÃĸ¦ ¿À¹ö¶óÀ̵å(override) ÇÒ ¶§ ÃæºÐÈ÷ ÁÖÀÇÇØ ÁÖ¼¼¿ä. Zend_Controller (À»)¸¦ »ç¿ëÇÏ´Â ÀÌÁ¡ÀÇ Çϳª¿¡, °øÅëÀÇ ±Ô¾à¿¡ µû¸¥ ¾îÇø®ÄÉÀ̼ÇÀ» ÀÛ¼ºÇÒ ¼ö ÀÖ´Â °ÍÀÌ ÀÖ½À´Ï´Ù. µðÆúÆ®ÀÇ ÇൿÀ» ³Ê¹« º¯°æÇØ ¹ö¸®¸é, ÀÌ ÀÌÁ¡ÀÌ ¾ø¾îÁ® ¹ö¸³´Ï´Ù. ±×·¸Áö¸¸, ¼¼»ó¿¡´Â ´Ù¾çÇÑ ¼ö¿ä°¡ ÀÖ´Â °ÍÀ̰í, ÇϳªÀÇ ¼Ö·ç¼ÇÀ¸·Î ¸ðµÎ ÇØ°áÇÒ ¼ö ÀÖ´Â °ÍÀÌ ¾ø½À´Ï´Ù. ±× ¶§¹®¿¡(À§ÇØ), ÇÊ¿äÇÏ¸é º¯°æÇÒ ¼ö ÀÖµµ·Ï Çϰí ÀÖ½À´Ï´Ù.

7.3.2. ±Ô¾à

Zend_Controller ÀÇ Å¬·¡½º¸¦ °è½ÂÇÏ´Â °æ¿ì´Â, ±× ¸í¸íÀ̳ª º¸Á¸ Àå¼Ò´Â °¡´ÉÇÑ ÇÑ ´ÙÀ½ÀÇ ±Ô¾à¿¡ µû¸£µµ·Ï ÇØ ÁÖ¼¼¿ä. ±×·¸°Ô ÇÏ´Â °ÍÀ¸·Î,Zend Framework ¿¡ Ä£¼÷ÇÔÀÌ ÀÖ´Â ´Ù¸¥ ÇÁ·Î±×·¡¸Ó°¡, ´ç½ÅÀÇ ÇÁ·ÎÁ§Æ®ÀÇ ³»¿ëÀ» °£´ÜÇÏ°Ô ÀÌÇØÇÒ ¼ö ÀÖ°Ô µË´Ï´Ù.

7.3.2.1. ÇÁ·¹ÇȽº

Zend Framework ¿¡ Æ÷ÇԵǴ Ŭ·¡½ºÀÇ À̸§Àº, ¸ðµÎ "Zend_" ±×¸®°í ½ÃÀ۵Ǿî ÀÖ½À´Ï´Ù.À̰ÍÀÌ ÇÁ·¹ÇȽºÀÔ´Ï´Ù. ´ç½ÅÀÌ ÀÛ¼ºÇϴ Ŭ·¡½ºµµ ¶È°°ÀÌ ÇØ µÎ´Â °ÍÀ» Ãßõ ÇÕ´Ï´Ù. ¿¹¸¦ µé¸é, ¸¸¾à ´ç½ÅÀÌ ¼Ò¼ÓÇϴ ȸ»ç¸íÀÌ Widget, Inc. (ÀÌ)¶ó¸é, ÇÁ·¹ÇȽº¸¦ "Widget_" (À¸)·Î ÇÕ´Ï´Ù.

7.3.2.2. µð·ºÅ丮 ±¸¼º

Zend_Controller Ŭ·¡½º´Â, ¶óÀ̺귯¸® µð·ºÅ丮¿¡ ÀÌÇÏ¿Í °°ÀÌ °Ý³³µË´Ï´Ù.


/library
  /Zend
    /Controller
      Action.php
      Dispatcher.php
      Router.php

Zend_Controller Ŭ·¡½º¸¦ °è½ÂÇÏ´Â °æ¿ì´Â, ÀÛ¼ºÇÑ Å¬·¡½º¸¦ ( ´ç½ÅÀÇ ÇÁ·¹ÇȽºÀÇ ¾Æ·¡¿¡¼­) °°Àº ±¸Á¶·Î °Ý³³ÇÏ´Â °ÍÀ» Ãßõ ÇÕ´Ï´Ù.ÀÌ·¸°Ô ÇÏ´Â °ÍÀ¸·Î, ´ç½ÅÀÇ ÇÁ·ÎÁ§Æ®ÀÇ Äڵ带 ¸®ºä ÇÏ´Â »ç¶÷µéÀÌ ±×°ÍÀ» ã¾Æ³»±â ½¬¿öÁö°ÚÁö¿ä.

¿¹¸¦ µé¸é Widget, Inc. ÀÇ ÇÁ·ÎÁ§Æ®°¡ ¶ó¿ìÅ͸¸À» µ¶ÀÚÀûÀ¸·Î ½ÇÀåÇßÀ» °æ¿ì´Â, ´ÙÀ½°ú °°ÀÌ µÇ°ÚÁö¿ä.


/library
  /Zend
  /Widget
    /Controller
      Router.php
      README.txt

ÀÌ ¿¹¿¡¼­´Â,Widget/Controller/ µð·ºÅ丮°¡ Zend/Controller/ µð·ºÅ丮¿Í °°Àº ±¸Á¶°¡ µÇ¾î ÀÖ´Â °Í¿¡ ÁÖÀÇÇսôÙ. ÀÌ °æ¿ì, ÀÌ ÆÄÀÏ¿¡¼­´Â Widget_Controller_Router ±×·¸´Ù°í Çϴ Ŭ·¡½º°¡ Á¦°øµË´Ï´Ù.ÀÌ Å¬·¡½º´Â Zend_Controller_Router (À»)¸¦ °è½ÂÇÑ °ÍÀΰ¡, ȤÀº Zend_Controller_Router_Interface (À»)¸¦ ½ÇÀåÇÑ µ¶ÀÚÀûÀΠŬ·¡½º°¡ µË´Ï´Ù.

¶Ç, À§ÀÇ ¿¹·Î Widget/Controller/ µð·ºÅ丮¿¡ README.txt ÇÏÁö¸¸ ÀÖ°Ôµµ ÁÖÀÇÇØ ÁÖ¼¼¿ä. ´ç½ÅÀÇ ÇÁ·ÎÁ§Æ®¸¦ °í°´¿¡°Ô Á¦°øÇÒ ¶§ , °Å±â¿¡ °üÇÑ ´Üü Å×½ºÆ®³ª ¹®¼­µµ ÀÛ¼ºÇϵµ·Ï,Zend (Àº)´Â °­ÇÏ°Ô Ãßõ ÇÕ´Ï´Ù. °Å±â±îÁö´Â °¡Áö ¾Ê¾Æµµ, °°Àº µð·ºÅ丮¿¡ ½ÉÇÃÇÑ README.txt ÆÄÀÏÀ» µÎ¾î, º¯°æÁ¡À̳ª µ¿ÀÛ ³»¿ëÀ» °£´ÜÇÏ°Ô ¼³¸íÇØ µÎµµ·Ï ÇսôÙ.

7.3.3. ÇÁ·±Æ® ÄÜÆ®·Ñ·¯

Zend_Controller_Front (Àº)´Â, ÇÁ·±Æ® ÄÜÆ®·Ñ·¯¸¦ ½ÇÀåÇÑ °ÍÀÔ´Ï´Ù. °Ô´Ù°¡ À̰ÍÀº ½Ì±Û Åæ Ŭ·¡½ºÀ̱⵵ ÇÕ´Ï´Ù. Áï, ¾î´À ½ÃÁ¡¿¡ À־ ÀνºÅϽº´Â Çϳª ¹Û¿¡ Á¸ÀçÇÏÁö ¾Ê´Â´Ù°í ÇÏ´Â °ÍÀÔ´Ï´Ù.

ÀÌ ¼­ºê Ŭ·¡½º¸¦ ÀÛ¼ºÇϱâ À§Çؼ­ ÃÖÀúÇÑ ÇÊ¿äÇÑ (ÀÏ)°ÍÀº, getInstance() ¸Þ¼Òµå¸¦ ¿À¹ö¶óÀ̵å(override) ÇÏ´Â °ÍÀÔ´Ï´Ù.


class My_Controller_Front extends Zend_Controller_Front
{
    public static function getInstance()
    {
        if (null === self::$_instance) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }
}

getInstance() ¸Þ¼Òµå¸¦ ¿À¹ö¶óÀ̵å(override) ÇÏ´Â °ÍÀ¸·Î, Zend_Controller_Front::getInstance() ÀÇ Äݽÿ¡ Zend_Controller_Front (Àº)´Â ¾Æ´Ï°í ±× ¼­ºê Ŭ·¡½ºÀÇ ÀνºÅϽº¸¦ µ¹·ÁÁÖµµ·Ï(µíÀÌ) ÇÕ´Ï´Ù. À̰Ϳ¡ ÀÇÇØ, ¶ó¿ìÅͳª ºäÇ츣ÆÄÀÇ °Åµ¿À» º¯°æÇÒ ¼ö ÀÖ½À´Ï´Ù.

getInstance() Àܷ̿εµ, ´Ù¸¥ ¸¹Àº ¸Þ¼Òµå¸¦ ¿À¹ö¶óÀ̵å(override) ÇÒ ¼ö ÀÖ½À´Ï´Ù.


/**
     * Resets all object properties of the singleton instance
     *
     * Primarily used for testing; could be used to chain front controllers.
     * 
     * @return void
     */
    public function resetInstance();

    /**
     * Convenience feature, calls setControllerDirectory()->setRouter()->dispatch()
     *
     * In PHP 5.1.x, a call to a static method never populates $this -- so run() 
     * may actually be called after setting up your front controller.
     *
     * @param string|array $controllerDirectory Path to Zend_Controller_Action 
     * controller classes or array of such paths
     * @return void
     * @throws Zend_Controller_Exception if called from an object instance
     */
    static public function run($controllerDirectory);

    /**
     * Add a controller directory to the controller directory stack
     *
     * If $args is presented and is a string, uses it for the array key mapping 
     * to the directory specified.
     * 
     * @param string $directory 
     * @param mixed $args Optional argument; if string value, used as array key map
     * @return Zend_Controller_Front
     */
    public function addControllerDirectory($directory, $args = null);

    /**
     * Set controller directory
     *
     * Stores controller directory to pass to dispatcher. May be an array of 
     * directories or a string containing a single directory.
     *
     * @param string|array $directory Path to Zend_Controller_Action controller 
     * classes or array of such paths
     * @return Zend_Controller_Front
     */
    public function setControllerDirectory($directory);

    /**
     * Retrieve controller directory
     *
     * Retrieves stored controller directory
     *
     * @return string|array
     */
    public function getControllerDirectory();

    /**
     * Set the default controller (unformatted string)
     *
     * @param string $controller
     * @return Zend_Controller_Front
     */
    public function setDefaultController($controller);

    /**
     * Retrieve the default controller (unformatted string)
     *
     * @return string
     */
    public function getDefaultController();

    /**
     * Set the default action (unformatted string)
     *
     * @param string $action
     * @return Zend_Controller_Front
     */
    public function setDefaultAction($action);

    /**
     * Retrieve the default action (unformatted string)
     *
     * @return string
     */
    public function getDefaultAction();

    /**
     * Set request class/object
     *
     * Set the request object.  The request holds the request environment.
     *
     * If a class name is provided, it will instantiate it
     *
     * @param string|Zend_Controller_Request_Abstract $request
     * @throws Zend_Controller_Exception if invalid request class
     * @return Zend_Controller_Front
     */
    public function setRequest($request);

    /**
     * Return the request object.
     *
     * @return null|Zend_Controller_Request_Abstract
     */
    public function getRequest();

    /**
     * Set router class/object
     *
     * Set the router object.  The router is responsible for mapping
     * the request to a controller and action.
     *
     * If a class name is provided, instantiates router with any parameters
     * registered via {@link setParam()} or {@link setParams()}.
     *
     * @param string|Zend_Controller_Router_Interface $router
     * @throws Zend_Controller_Exception if invalid router class
     * @return Zend_Controller_Front
     */
    public function setRouter($router);

    /**
     * Return the router object.
     *
     * Instantiates a Zend_Controller_Router object if no router currently set.
     *
     * @return null|Zend_Controller_Router_Interface
     */
    public function getRouter();

    /**
     * Set the base URL used for requests
     *
     * Use to set the base URL segment of the REQUEST_URI to use when 
     * determining PATH_INFO, etc. Examples:
     * - /admin
     * - /myapp
     * - /subdir/index.php
     *
     * Note that the URL should not include the full URI. Do not use:
     * - http://example.com/admin
     * - http://example.com/myapp
     * - http://example.com/subdir/index.php
     *
     * If a null value is passed, this can be used as well for autodiscovery (default).
     * 
     * @param string $base
     * @return Zend_Controller_Front
     * @throws Zend_Controller_Exception for non-string $base
     */
    public function setBaseUrl($base = null);

    /**
     * Retrieve the currently set base URL
     * 
     * @return string
     */
    public function getBaseUrl();

    /**
     * Set the dispatcher object.  The dispatcher is responsible for
     * taking a Zend_Controller_Request_Abstract object, instantiating the controller, and
     * calling the action method of the controller.
     *
     * @param Zend_Controller_Dispatcher_Interface $dispatcher
     * @return Zend_Controller_Front
     */
    public function setDispatcher(Zend_Controller_Dispatcher_Interface $dispatcher);

    /**
     * Return the dispatcher object.
     *
     * @return Zend_Controller_DispatcherInteface
     */
    public function getDispatcher();

    /**
     * Set response class/object
     *
     * Set the response object.  The response is a container for action
     * responses and headers. Usage is optional.
     *
     * If a class name is provided, instantiates a response object.
     *
     * @param string|Zend_Controller_Response_Abstract $response
     * @throws Zend_Controller_Exception if invalid response class
     * @return Zend_Controller_Front
     */
    public function setResponse($response);

    /**
     * Return the response object.
     *
     * @return null|Zend_Controller_Response_Abstract
     */
    public function getResponse();

    /**
     * Add or modify a parameter to use when instantiating an action controller
     *
     * @param string $name
     * @param mixed $value
     * @return Zend_Controller_Front
     */
    public function setParam($name, $value);

    /**
     * Set parameters to pass to action controller constructors
     *
     * @param array $params
     * @return Zend_Controller_Front
     */
    public function setParams(array $params);

    /**
     * Retrieve a single parameter from the controller parameter stack
     * 
     * @param string $name 
     * @return mixed
     */
    public function getParam($name);

    /**
     * Retrieve action controller instantiation parameters
     *
     * @return array
     */
    public function getParams();

    /**
     * Clear the controller parameter stack
     *
     * By default, clears all parameters. If a parameter name is given, clears 
     * only that parameter; if an array of parameter names is provided, clears 
     * each.
     * 
     * @param null|string|array single key or array of keys for params to clear
     * @return Zend_Controller_Front
     */
    public function clearParams($name = null);

    /**
     * Register a plugin.
     *
     * @param Zend_Controller_Plugin_Abstract $plugin
     * @return Zend_Controller_Front
     */
    public function registerPlugin(Zend_Controller_Plugin_Abstract $plugin);

    /**
     * Unregister a plugin.
     *
     * @param Zend_Controller_Plugin_Abstract $plugin
     * @return Zend_Controller_Front
     */
    public function unregisterPlugin(Zend_Controller_Plugin_Abstract $plugin);

    /**
     * Set whether exceptions encounted in the dispatch loop should be thrown 
     * or caught and trapped in the response object
     *
     * Default behaviour is to trap them in the response object; call this 
     * method to have them thrown.
     * 
     * @param boolean $flag Defaults to true
     * @return boolean Returns current setting
     */
    public function throwExceptions($flag = null);

    /**
     * Set whether {@link dispatch()} should return the response without first 
     * rendering output. By default, output is rendered and dispatch() returns 
     * nothing.
     * 
     * @param boolean $flag 
     * @return boolean Returns current setting
     */
    public function returnResponse($flag = null);

    /**
     * Dispatch an HTTP request to a controller/action.
     *
     * @param Zend_Controller_Request_Abstract|null $request
     * @param Zend_Controller_Response_Abstract|null $response
     * @return void|Zend_Controller_Response_Abstract Returns response object if returnResponse() is true
     */
    public function dispatch(Zend_Controller_Request_Abstract $request = null, Zend_Controller_Response_Abstract $response = null);

ÇÁ·±Æ® ÄÜÆ®·Ñ·¯ÀÇ ¸ñÀûÀº, ¸®Äù½ºÆ® ȯ°æÀ» ¼³Á¤ÇÏ´Â °Í, ¿À´Â ¸®Äù½ºÆ®¸¦ ·çÆÃ ÇÏ´Â °Í, ¾×¼Ç¿¡ µû¸£°í 󸮸¦ ¹èºÐÇÏ´Â °Í, ±×¸®°í ¸®½ºÆù½º¸¦ ÃëµæÇÏ°í ±×°ÍÀ» µ¹·ÁÁÖ´Â °ÍÀÔ´Ï´Ù.

ÇÁ·±Æ® ÄÜÆ®·Ñ·¯¸¦ È®ÀåÇÏ´Â ÁÖµÈ ÀÌÀ¯·Î¼­´Â, ¾×¼¼½º¿ë ¸Þ¼ÒµåÀÇ ³í¸®¸¦ º¯°æ ( ¿¹¸¦ µé¾î ´Ù¸¥ µðÆúÆ® ¶ó¿ìÅͳª µð½ºÆÖÃĸ¦ ÀоîµéÀ̰ųª ÄÜÆ®·Ñ·¯ µð·ºÅ丮ÀÇ Ã³¸® ¹æ¹ýÀ» ÁöÁ¤ÇÏ´Â µî) Çϰųª ·çÆÃÀ̳ª µð½ºÆÌÄ¡ 󸮸¦ º¯°æÇϰųª¶ó°í Çß´ø ÀûÀÌ ÀÖ½À´Ï´Ù.

7.3.4. ¸®Äù½ºÆ®ÀÇ Ãß»óÈ­

Ãß»ó Ŭ·¡½º Zend_Controller_Request_Abstract ±×¸®°í, ¸î°³ÀÇ ¸Þ¼Òµå¸¦ Á¤ÀÇÇϰí ÀÖ½À´Ï´Ù.


/**
     * @return string
     */
    public function getControllerName();

    /**
     * @param string $value 
     * @return self
     */
    public function setControllerName($value);

    /**
     * @return string
     */
    public function getActionName();

    /**
     * @param string $value 
     * @return self
     */
    public function setActionName($value);

    /**
     * @return string
     */
    public function getControllerKey();

    /**
     * @param string $key 
     * @return self
     */
    public function setControllerKey($key);

    /**
     * @return string
     */
    public function getActionKey();

    /**
     * @param string $key 
     * @return self
     */
    public function setActionKey($key);

    /**
     * @param string $key 
     * @return mixed
     */
    public function getParam($key);

    /**
     * @param string $key 
     * @param mixed $value 
     * @return self
     */
    public function setParam($key, $value);

    /**
     * @return array
     */
     public function getParams();

    /**
     * @param array $array 
     * @return self
     */
    public function setParams(array $array);

    /**
     * @param boolean $flag 
     * @return self
     */
    public function setDispatched($flag = true);

    /**
     * @return boolean
     */
    public function isDispatched();
}

¸®Äù½ºÆ® ¿ÀºêÁ§Æ®´Â, ¸®Äù½ºÆ®ÀÇ ÄÁÅ×À̳ʰ¡ µË´Ï´Ù. ÄÜÆ®·Ñ·¯ ÃÖÀÎÀÌ ÇÊ¿ä·Î ÇÏ´Â °ÍÀº, ÄÜÆ®·Ñ·¯, ¾×¼Ç, ¿É¼Ç ÆÄ¶ó¹ÌÅÍ ¹× µð½ºÆÌÄ¡ »óȲÀ» ¼³Á¤Çϰųª ÃëµæÇϰųª ÇÏ´Â ¹æ¹ý¸¸µË´Ï´Ù. µðÆúÆ®¿¡¼­´Â, ¸®Äù½ºÆ®°¡ ÆÄ¶ó¹ÌÅ͸¦ ãÀ» ¶§ ÄÜÆ®·Ñ·¯ ȤÀº ¾×¼ÇÀÇ Å°¸¦ »ç¿ëÇÕ´Ï´Ù. ã´Â ¼ø¼­´Â ÄÜÆ®·Ñ·¯ ¹× ¾×¼ÇÀ¸·Î Á¤Àǵ˴ϴÙ.

7.3.5. ¶ó¿ìÅÍÀÇ ÀÎÅÍÆäÀ̽º

Zend_Controller_Router_Interface ±×¸®°í Á¤Àǵǰí ÀÖ´Â ¸Þ¼Òµå´Â Çϳª »ÓÀÔ´Ï´Ù.


<?php

  
/**
   * @param  Zend_Controller_Request_Abstract $request
   * @throws Zend_Controller_Router_Exception
   * @return Zend_Controller_Request_Abstract
   */
  
public function route(Zend_Controller_Request_Abstract $request);

?>

·çÆÃÀÌ ¹ß»ýÇÏ´Â °ÍÀº, ½Ã½ºÅÛÀÌ ÃÖÃÊ·Î ¸®Äù½ºÆ®¸¦ ¹Þ¾ÒÀ» ¶§ »ÓÀÔ´Ï´Ù. ¶ó¿ìÅÍÀÇ ¿ªÇÒÀº, ÄÜÆ®·Ñ·¯³ª ¾×¼Ç ±×¸®°í ¸®Äù½ºÆ® ³»¿ë¿¡ ÀÀÇÑ ¿É¼Ç ÆÄ¶ó¹ÌÅ͸¦ °áÁ¤ÇØ, ±×°ÍÀ» ¸®Äù½ºÆ®·Î ¼³Á¤ÇÏ´Â °ÍÀÔ´Ï´Ù. ±× ÈÄ, ¸®Äù½ºÆ® ¿ÀºêÁ§Æ®¸¦ µð½ºÆÖÃÄ¿¡ °Ç³×ÁÝ´Ï´Ù. ·çÆ®¸¦ µð½ºÆÖÃÄ ÅäÅ«¿¡ °ü·ÃÁöÀ» ¼ö ¾ø½À´Ï´Ù. ÀÌ °æ¿ì, ¶ó¿ìÅÍ´Â ¸®Äù½ºÆ® ¿ÀºêÁ§Æ®¿¡ ´ëÇØ¼­ ¾Æ¹«°Íµµ ÇÏÁö ¾Ê½À´Ï´Ù.

7.3.6. µð½ºÆÖÃÄÀÇ ÀÎÅÍÆäÀ̽º

Zend_Controller_Front (Àº)´Â, ¿ì¼± ÃÖÃÊ·Î ¶ó¿ìÅ͸¦ ÄÝ Çϰí, ¸®Äù½ºÆ®³»¿¡¼­ ÃÖÃÊ·Î µð½ºÆÌÄ¡ ÇÒ ¼ö ÀÖ´Â ¾×¼ÇÀ» °áÁ¤ÇÕ´Ï´Ù. ±× ÈÄ, µð½ºÆÖÃÄ ·çÇÁ¿¡ µé¾î°©´Ï´Ù.

·çÇÁ³»¿¡¼­´Â, ¿ì¼± ¸®Äù½ºÆ® ¿ÀºêÁ§Æ®·Î µð½ºÆÌÄ¡ÈĶó±×¸¦ ¼³Á¤ÇØ, ±×¸®°í ¸®Äù½ºÆ®¸¦ ó¸®ÇÕ´Ï´Ù ( ÄÜÆ®·Ñ·¯ÀÇ ÀνºÅϽº¸¦ ÀÛ¼ºÇØ, ¾×¼ÇÀ» ÄÝ ÇÕ´Ï´Ù) .¾×¼Ç ¸Þ¼Òµå ( ȤÀº pre/postDispatch Ç÷¯±× ÀÎ) ÇÏÁö¸¸ µð½ºÆÌÄ¡ÈĶó±×¸¦ ¸®¼ÂÆ® Çϸé, ¸®Äù½ºÆ® ¿ÀºêÁ§Æ®ÀÇ ¼³Á¤ ³»¿ëÀ» ±âÃÊ·Î ÇØ¼­ ÇÁ·±Æ® ÄÜÆ®·Ñ·¯°¡ ·çÇÁ³»ÀÇ ´ÙÀ½ÀÇ Ã³¸®¸¦ ½ÇÇàÇÕ´Ï´Ù. À̰Ϳ¡ ÀÇÇØ, ¸ðµç ¾×¼ÇÀ» ¼ø¼­¿¡ ½ÇÇàÇØ ³ª°¥ ¼ö ÀÖ½À´Ï´Ù.

Zend_Controller_Dispatcher_Interface ÀÎÅÍÆäÀ̽º¿¡¼­´Â, µÎ °³ÀÇ ¸Þ¼Òµå°¡ Á¤Àǵǰí ÀÖ½À´Ï´Ù.


<?php

/**
 * @param  Zend_Controller_Request_Abstract $request
 * @return boolean
 */
public function isDispatchable(Zend_Controller_Request_Abstract $request);

?>

isDispatchable() (Àº)´Â, ¸®Äù½ºÆ®°¡ µð½ºÆÌÄ¡ °¡´ÉÇÒÁö¸¦ Á¶»çÇÕ´Ï´Ù. µð½ºÆÌÄ¡ °¡´ÉÇÑ °æ¿ì¿¡ TRUE , ±× ÀÌ¿ÜÀÇ °æ¿ì¿¡ FALSE (À»)¸¦ µ¹·ÁÁÝ´Ï´Ù.µð½ºÆÌÄ¡ °¡´ÉÇÒÁö¸¦ ÆÇ´ÜÇÏ´Â ±âÁØÀº, ÀÎÅÍÆäÀ̽º¸¦ ½ÇÀåÇÑ Å¬·¡½º¿¡¼­ ±â¼úÇÕ´Ï´Ù. µðÆúÆ®ÀÇ ½ÇÀåÀÌ´Ù Zend_Controller_Dispatcher ±×·³, ÄÜÆ®·Ñ·¯ÀÇ ÆÄÀÏÀÌ Á¸ÀçÇÒÁö, ±× ÆÄÀϷΠŬ·¡½º°¡ Á¤Àǵǰí ÀÖ´ÂÁö ¾î¶²Áö, ±×¸®°í ±× Ŭ·¡½º¿¡¼­ ¾×¼Ç ¸Þ¼Òµå°¡ Á¤Àǵǰí ÀÖ´ÂÁö ¾î¶²Áö¸¦ Á¶»çÇÕ´Ï´Ù.


<?php

/**
 * @param  Zend_Controller_Request_Abstract $route
 * @return Zend_Controller_Request_Abstract
 */
public function dispatch(Zend_Controller_Request_Abstract $request);

?>

dispatch() (Àº)´Â, ½ÇÁ¦ÀÇ Ã³¸®¸¦ ½Ç½ÃÇÒ °÷ÀÔ´Ï´Ù. ÀÌ ¸Þ¼Òµå´Â, ÄÜÆ®·Ñ·¯ÀÇ ¾×¼ÇÀ» ½ÇÇàÇÏÁö ¾ÊÀ¸¸é ¾ÈµË´Ï´Ù. ¶Ç ¸®Äù½ºÆ® ¿ÀºêÁ§Æ®¸¦ µ¹·ÁÁÙ Çʿ䰡 ÀÖ½À´Ï´Ù.

7.3.7. ¾×¼Ç ÄÜÆ®·Ñ·¯

¾×¼Ç ÄÜÆ®·Ñ·¯´Â, ¾îÇø®ÄÉÀ̼ÇÀÇ ´Ù¾çÇÑ ¾×¼ÇÀ» ó¸®ÇÕ´Ï´Ù. ÀÌ Ãß»ó Ŭ·¡½º¿¡¼­´Â ´ÙÀ½ÀÇ ¸Þ¼Òµå¸¦ Á¦°øÇÕ´Ï´Ù.


/**
     * @param Zend_Controller_Request_Abstract $request Request object
     * @param Zend_Controller_Response_Abstract $response Response object
     * @param array $args Optional associative array of
     * configuration/environment settings
     */
    public function __construct(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $args = array());

    /**
     * @return void
     */
    public function init();

    /**
     * @return Zend_Controller_Request_Abstract
     */
    public function getRequest();

    /**
     * @param Zend_Controller_Request_Abstract $request 
     * @return self
     */
    public function setRequest(Zend_Controller_Request_Abstract $request);

    /**
     * @return Zend_Controller_Response_Abstract
     */
    public function getResponse();

    /**
     * @param Zend_Controller_Response_Abstract $response 
     * @return self
     */
    public function setResponse(Zend_Controller_Response_Abstract $response);

    /**
     * @return array
     */
    public function getInvokeArgs();

    /**
     * @return mixed
     */
    public function getInvokeArg($name);

    public function preDispatch();

    public function postDispatch();

    /**
     * @param string $methodName
     * @param array $args
     */
    public function __call($methodName, $args);

    /**
     * @param null|Zend_Controller_Request_Abstract $request Optional request 
     * object to use
     * @param null|Zend_Controller_Response_Abstract $response Optional response 
     * object to use
     * @return Zend_Controller_Response_Abstract
     */
    public function run(Zend_Controller_Request_Abstract $request = null, Zend_Controller_Response_Abstract $response = null);

constructor¡¡ ¡¡ Àº, ¸®Äù½ºÆ® ¿ÀºêÁ§Æ®¿Í ¸®½ºÆù½º ¿ÀºêÁ§Æ®¸¦ µî·ÏÇØ, Ãß°¡ÀÇ ¼³Á¤ ÀμöÀÇ ¹è¿­µµ µî·ÏÇÕ´Ï´Ù.ÀÌ ¹è¿­¿¡´Â, ÇÁ·±Æ® ÄÜÆ®·Ñ·¯ÀÇ setParam() ¸Þ¼Òµå³ª setParams() ¸Þ¼Òµå·Î µî·ÏµÈ ÆÄ¶ó¹ÌÅͰ¡ Æ÷ÇԵ˴ϴÙ. µî·ÏÀ» ³¡¸¶Ä£ ÈÄ¿¡, constructor¡¡ ¡¡ Àº 󸮸¦ init() ¿¡ °Ç³×ÁÝ´Ï´Ù.

constructor¡¡ ¡¡ À» ¿À¹ö¶óÀ̵å(override) ÇÒ ¼öµµ ÀÖ½À´Ï´Ù.´ÜÁö, ÃʱâÈ­ 󸮴 ¸ðµÎ init() ±×¸®°í ½Ç½ÃÇϵµ·Ï(µíÀÌ) ÇØ, ¸®Äù½ºÆ®¿Í ¸®½ºÆù½º¸¦ ÀûÀýÈ÷ µî·ÏÇÒ ¼ö ÀÖµµ·Ï ÇØ µÎ´Â °ÍÀ» Ãßõ ÇÕ´Ï´Ù.

constructor¡¡ ¡¡ ¿¡°Ô °Ç³×Áø ¼³Á¤ Àμö¿¡´Â, getInvokeArg() ¹× getInvokeArgs() ±×¸®°í ¾×¼¼½º ÇÒ ¼ö ÀÖ°Ô µË´Ï´Ù. ÃßõÀÇ ¹æ¹ýÀº, ÀÌ·¯ÇÑ ±âµ¿½Ã Àμö·Î¼­ ºä³ª ÀÎÁõ Á¤º¸, ȤÀº ·¹Áö½ºÆ®¸® ¿ÀºêÁ§Æ®¸¦ °Ç³×ÁÖ´Â °ÍÀÔ´Ï´Ù. ¿¹¸¦ µé¾î ´ÙÀ½°ú °°ÀÌ µË´Ï´Ù.


$front = Zend_Controller_Front::getInstance();
$front->setParam('view', new Zend_View())
      ->setControllerDirectory($config->controller->directory);
$response = $front->dispatch();

//  »ùÇÃÀÇ ¾×¼Ç ÄÜÆ®·Ñ·¯
class FooController extends Zend_Controller_Action
{
    protected $_view = null;

    public function init()
    {
        $this->_view = $this->getInvokeArg('view');
    }
}

¾×¼ÇÀÌ µð½ºÆÌÄ¡ µÉ ¶§ÀÇ ÀüÈÄ¿¡ ÇàÇØÁö´Â 󸮰¡, °¢°¢ preDispatch() ¸Þ¼Òµå ¹× postDispatch() ¸Þ¼ÒµåÀÔ´Ï´Ù. µðÆúÆ®¿¡¼­´Â ÀÌ·¯ÇÑ ¸Þ¼Òµå´Â ÇÏ´ÃÀ̸ç, ¾Æ¹«°Íµµ ÇÏÁö ¾Ê½À´Ï´Ù.

__call() ¸Þ¼Òµå´Â, Ŭ·¡½º³»¿¡¼­ µî·ÏµÇÁö ¾ÊÀº ¾×¼ÇÀ» ó¸®ÇÕ´Ï´Ù. µðÆúÆ®¿¡¼­´Â, À̰ÍÀº ¹ÌÁ¤µµ¸®ÀÇ ¾×¼Ç¿¡ ´ëÇØ¼­ ¿¹¿Ü¸¦ ½½·Î¿ì ÇÕ´Ï´Ù. À̰ÍÀº, µðÆúÆ®ÀÇ ¾×¼Ç ¸Þ¼Òµå°¡ Á¤ÀǵǾî ÀÖÁö ¾ÊÀº °æ¿ì¿¡°Ô¸¸ ¹ß»ýÇÕ´Ï´Ù.

¾×¼Ç ¸Þ¼ÒµåÀÇ µðÆúÆ®ÀÇ ¸í¸í ±Ô¾àÀº lowercaseAction (¿Í)°ú °°ÀÌ µË´Ï´Ù.'lowercase' ÀÇ ºÎºÐ¿¡¼­ ¾×¼Ç¸íÀ» ÁöÁ¤ÇØ, 'Action' ÀÇ ºÎºÐ¿¡¼­ À̰ÍÀÌ ¾×¼Ç ¸Þ¼ÒµåÀÎ °ÍÀ» ÁöÁ¤ÇÕ´Ï´Ù. Áï,http://framework.zend.com/foo/bar ÇÏ FooController::barAction() (À»)¸¦ ÄÝ ÇÕ´Ï´Ù.

¾×¼Ç ÄÜÆ®·Ñ·¯´Â, ÆäÀÌÁö ÄÜÆ®·Ñ·¯·Î¼­ »ç¿ëÇÒ ¼öµµ ÀÖ½À´Ï´Ù. ÀüÇüÀûÀÎ »ç¿ë¹ýÀº, ÀÌ¿Í °°ÀÌ µË´Ï´Ù.


$controller = new FooController(
    new Zend_Controller_Request_Abstract(),
    new Zend_Controller_Response_Abstract()
);
$controller->run();
[
ÁÖÀÇ] ÇÁ·±Æ® ÄÜÆ®·Ñ·¯/ ¾×¼Ç ÄÜÆ®·Ñ·¯ÀÇ »ç¿ë

ÆäÀÌÁö ÄÜÆ®·Ñ·¯ ¹æ½ÄÀÌ ¾Æ´Ï°í, ÇÁ·±Æ® ÄÜÆ®·Ñ·¯/ ÆäÀÌÁö ÄÜÆ®·Ñ·¯ (À»)¸¦ Á¶ÇÕÇÑ ¹æ½ÄÀ» »ç¿ëÇÏ´Â °ÍÀ» Ãßõ ÇÕ´Ï´Ù. À̰Ϳ¡ ÀÇÇØ, »óÈ£ ¿î¿ë °¡´ÉÇÑ ¾îÇø®ÄÉÀ̼ÇÀ» ¾µ ¼ö ÀÖ°Ô µË´Ï´Ù.

7.3.8. ¸®½ºÆù½º ¿ÀºêÁ§Æ®

¸®½ºÆù½º ¿ÀºêÁ§Æ®´Â, ÄÝ µÈ ¾×¼ÇÀ¸·ÎºÎÅÍÀÇ ³»¿ëÀ̳ª Çì´õ¸¦ ¼öÁýÇØ, ±×°ÍÀ» Ŭ¶óÀÌ¾ðÆ®¿¡ µ¹·ÁÁÝ´Ï´Ù. ´ÙÀ½°ú °°Àº ¸Þ¼Òµå°¡ ÀÖ½À´Ï´Ù.


/**
     * @param string $name Header name
     * @param string $value Header value
     * @param boolean $replace Whether or not to replace headers with the same
     * name already registered with the object
     * @return self
     */
    public function setHeader($name, $value, $replace = false);

    /**
     * @return array
     */
    public function getHeaders();

    /**
     * @return void
     */
    public function clearHeaders();

    /**
     * Sends all headers
     * @return void
     */
    public function sendHeaders();

    /**
     * @param string $content
     * @return self
     */
    public function setBody($content);

    /**
     * @param string $content
     * @return self
     */
    public function appendBody($content);

    /**
     * @return string
     */
    public function getBody();

    /**
     * echoes body content
     * @return void
     */
    public function outputBody();

    /**
     * @param Exception $e 
     * @return self
     */
    public function setException(Exception $e);

    /**
     * @return null|Exception
     */
    public function getException();

    /**
     * @return boolean
     */
    public function isException();

    /**
     * @param boolean $flag
     * @return boolean
     */
    public function renderExceptions($flag = null);

    /**
     * @return string
     */
    public function __toString();

setBody() (Àº)´Â, º¸µðºÎÀÇ ³»¿ëÀ» ¸ðµÎ ¿Å°Ü³õ½À´Ï´Ù. ÀÌ ¸Þ¼Òµå ´ë½Å¿¡ appendBody() (À»)¸¦ »ç¿ëÇÏ´Â °ÍÀ» Ãßõ ÇÕ´Ï´Ù. __toString() (Àº)´Â, ³»¿ëÀ» ·»´õ¸µ ÇØ ¸ðµç Çì´õ¸¦ ¼Û½ÅÇÕ´Ï´Ù.

¸®½ºÆù½º ¿ÀºêÁ§Æ®´Â ¶Ç, ¾×¼Ç ÄÜÆ®·Ñ·¯·Î ¹ß»ýÇÑ ¿¹¿Ü°¡ ÃÖÁ¾ÀûÀ¸·Î Æ÷Âø, µî·ÏµÇ´Â °÷(Áß)À̱⵵ ÇÕ´Ï´Ù (Zend_Controller_Front::throwExceptions() ÇÏÁö¸¸ À¯È¿ÇÏ°Ô µÇ¾î ÀÖ´Â °æ¿ì¸¦ Á¦¿ÜÇÏ´Ù) . isException() ÇÏ boolean °ªÀ» µ¹·ÁÁÝ´Ï´Ù. À̰ÍÀº ¿¹¿Ü°¡ ¹ß»ýÇß´ÂÁö¸¦ ³ªÅ¸³À´Ï´Ù. renderExceptions() (À»)¸¦ »ç¿ëÇϸé, ¿¹¿Ü¸¦ Æ÷ÂøÇßÀ» ¶§¿¡ __toString() ÇÏÁö¸¸ ¿¹¿Ü Ãâ·ÂÀ» ·»´õ¸µ Çß´ÂÁö ¾î¶²Áö¸¦ ¾Ë ¼ö ÀÖ½À´Ï´Ù.