7.6. µð½ºÆÖÃÄ

7.6.1. °³¿ä

µð½ºÆÌÄ¡ 󸮴Â, ¸®Äù½ºÆ® ¿ÀºêÁ§Æ®ÀÌ´Ù Zend_Controller_Request_Abstract (À»)¸¦ ¹Þ¾Æ, °Å±â¿¡ Æ÷ÇԵǴ Á¤º¸ (¸ðµâ¸í, ÄÜÆ®·Ñ·¯¸í, ¾×¼Ç¸í ¹× ¿É¼ÇÀÇ ÆÄ¶ó¹ÌÅÍ) (À»)¸¦ Àü°³ÇØ, ÄÜÆ®·Ñ·¯ÀÇ ÀνºÅϽº¸¦ ÀÛ¼ºÇØ ±× ÄÜÆ®·Ñ·¯ÀÇ ¾×¼ÇÀ» ÄÝ ÇÕ´Ï´Ù. ¸ðµâÀ̳ª ÄÜÆ®·Ñ·¯, ¾×¼ÇÀÌ ¹ß°ßµÇÁö ¾Ê´Â °æ¿ì´Â, µðÆúƮġ¸¦ »ç¿ëÇÕ´Ï´Ù.Zend_Controller_Dispatcher_Standard ±×·³, ÄÜÆ®·Ñ·¯¿Í ¾×¼ÇÀÇ µðÆúÆ®´Â ¾î´ÀÂÊÀ̳ª index ±×¸®°í, ¸ðµâÀÇ µðÆúÆ®´Â default ÀÔ´Ï´Ù.±×·¯³ª, setDefaultController() ¸Þ¼Òµå³ª setDefaultAction() ¸Þ¼Òµå, ±×¸®°í setDefaultModule() ±×¸®°í À̰͵éÀ» º¯°æÇÒ ¼öµµ ÀÖ½À´Ï´Ù.

µð½ºÆÌÄ¡ 󸮰¡ ¹ß»ýÇÏ´Â °ÍÀº, ÇÁ·±Æ® ÄÜÆ®·Ñ·¯·ÎÀÇ ·çÇÁÀÇ ³»ºÎÀÔ´Ï´Ù. µð½ºÆÌÄ¡ 󸮸¦ ½Ç½ÃÇϱâ Àü¿¡, ÇÁ·±Æ® ÄÜÆ®·Ñ·¯´Â ·çÆÃÀ» ½Ç½ÃÇØ, À¯Àú°¡ ÁöÁ¤ÇÑ ÄÜÆ®·Ñ·¯¿Í ¾×¼Ç, ±×¸®°í Ãß°¡ÀÇ ÆÄ¶ó¹ÌÅ͸¦ ÃëµæÇÕ´Ï´Ù. ±×¸®°í µð½ºÆÌÄ¡¸£ÇÁ¿¡ µé¾î°¡, ¸®Äù½ºÆ®¸¦ ¹è¼ÛÇÕ´Ï´Ù.

·çÇÁ³»¿¡¼­´Â, ¿ì¼± ÃÖÃÊ·Î ¸®Äù½ºÆ® ¿ÀºêÁ§Æ®ÀÇ Ç÷¡±×¸¦ ¼³Á¤ÇÕ´Ï´Ù. ÀÌ Ç÷¡±×´Â, ¾×¼ÇÀÌ µð½ºÆÌÄ¡ µÈ °ÍÀ» ³ªÅ¸³» º¸ÀÌ´Â °ÍÀÔ´Ï´Ù. ¾×¼Ç³»³ª pre/postDispatch Ç÷¯±× ÀÎÀ¸·Î ÀÌ Ç÷¡±×¸¦ ¸®¼ÂÆ® Çϸé, µð½ºÆÌÄ¡¸£ÇÁ°¡ ±×´ë·Î °è¼ÓµÇ¾î Çѹø ´õ ¸®Äù½ºÆ®¸¦ ó¸®ÇÏ·Á°í ÇÕ´Ï´Ù. ¸®Äù½ºÆ®³»ÀÇ ÄÜÆ®·Ñ·¯³ª ¾×¼ÇÀ» º¯°æÇØ Ç÷¡±×¸¦ ¸®¼ÂÆ® ÇÏ´Â °ÍÀ¸·Î, ´Ù¾çÇÑ ¸®Äù½ºÆ®¸¦ °è¼ÓÇØ ½ÇÇà½Ãų ¼ö ÀÖ½À´Ï´Ù.

ÀÌ·¯ÇÑ µð½ºÆÌÄ¡ 󸮸¦ Á¦¾îÇÑ´Ù ¾×¼Ç ÄÜÆ®·Ñ·¯ÀÇ ¸Þ¼Òµå°¡ _forward() ÀÔ´Ï´Ù. ÀÌ ¸Þ¼Òµå¸¦ pre/postDispatch() (ÀÌ)³ª ¾×¼Ç ¸Þ¼Òµå·Î ÄÝ ÇØ, ÄÜÆ®·Ñ·¯³ª ¾×¼Ç, ±×¸®°í »õ·Î¿î ¾×¼Ç¿¡ º¸³»°í ½ÍÀº Ãß°¡ÀÇ ÆÄ¶ó¹ÌÅ͸¦ ÁöÁ¤ÇÕ´Ï´Ù.


<?php
public function fooAction()
{
    
// ÇöÀçÀÇ ¸ðµâ ¹× ÄÜÆ®·Ñ·¯ÀÇ, ´Ù¸¥ ¾×¼Ç¿¡ Àü¼Û ÇÕ´Ï´Ù
    
$this->_forward('bar'nullnull, array('baz' => 'bogus'));
}

public function 
barAction()
{
    
// ÇöÀçÀÇ ¸ðµâ¿¡ ÀÖ´Â, ´Ù¸¥ ÄÜÆ®·Ñ·¯ÀÇ ¾×¼Ç
    // FooController::bazAction() ¿¡ Àü¼Û ÇÕ´Ï´Ù
    
$this->_forward('baz''foo'null, array('baz' => 'bogus'));
}

public function 
bazAction()
{
    
// ´Ù¸¥ ¸ðµâ¿¡ ÀÖ´Â, ´Ù¸¥ ÄÜÆ®·Ñ·¯ÀÇ ¾×¼Ç
    // Foo_BarController::bazAction() ¿¡ Àü¼Û ÇÕ´Ï´Ù
    
$this->_forward('baz''bar''foo', array('baz' => 'bogus'));
}

7.6.2. µð½ºÆÖÃÄÀÇ ¼­ºê Ŭ·¡½ºÀÇ ÀÛ¼º

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

µð½ºÆÖÃİ¡ µ¿ÀÛÇϱâ À§Çؼ­´Â, ´Ù¾çÇÑ µ¥ÀÌÅͰ¡ ÇÊ¿äÇÕ´Ï´Ù. ¿¹¸¦ µé¾î, ÄÜÆ®·Ñ·¯¸íÀ̳ª ¾×¼Ç¸íÀ» °áÁ¤ÇÏ´Â ¹æ¹ý, ÄÜÆ®·Ñ·¯ Ŭ·¡½º¸¦ ã´Â Àå¼Ò, ¸ðµâ¸íÀÌ À¯È¿ÇÒÁö, ±× ¿Ü, ¸®Äù½ºÆ®ÀÇ ³»¿ëÀ» µð½ºÆÌÄ¡ Çϱâ À§Çؼ­ ÇÊ¿äÇÑ Á¤º¸¸¦ ÃëµæÇÑ´Ù API ÇÏÁö¸¸ ÇÊ¿äÇÕ´Ï´Ù.

Zend_Controller_Dispatcher_Interface ±×·³ ´ÙÀ½°ú °°Àº ¸Þ¼Òµå¸¦ Á¤ÀÇÇϰí ÀÖ½À´Ï´Ù.µð½ºÆÖÃÄ´Â, À̰ÍÀ» ½ÇÀåÇÏÁö ¾ÊÀ¸¸é ¾ÈµË´Ï´Ù.


interface Zend_Controller_Dispatcher_Interface
{
    /**
     * Format a string into a controller class name.
     *
     * @param string $unformatted
     * @return string
     */
    public function formatControllerName($unformatted);

    /**
     * Format a string into an action method name.
     *
     * @param string $unformatted
     * @return string
     */
    public function formatActionName($unformatted);

    /**
     * Determine if a request is dispatchable
     *
     * @param  Zend_Controller_Request_Abstract $request
     * @return boolean
     */
    public function isDispatchable(Zend_Controller_Request_Abstract $request);

    /**
     * Set a user parameter (via front controller, or for local use)
     *
     * @param string $name
     * @param mixed $value
     * @return Zend_Controller_Dispatcher_Interface
     */
    public function setParam($name, $value);

    /**
     * Set an array of user parameters
     *
     * @param array $params
     * @return Zend_Controller_Dispatcher_Interface
     */
    public function setParams(array $params);

    /**
     * Retrieve a single user parameter
     *
     * @param string $name
     * @return mixed
     */
    public function getParam($name);

    /**
     * Retrieve all user parameters
     *
     * @return array
     */
    public function getParams();

    /**
     * Clear the user parameter stack, or a single user parameter
     *
     * @param null|string|array single key or array of keys for params to clear
     * @return Zend_Controller_Dispatcher_Interface
     */
    public function clearParams($name = null);

    /**
     * Set the response object to use, if any
     *
     * @param Zend_Controller_Response_Abstract|null $response
     * @return void
     */
    public function setResponse(Zend_Controller_Response_Abstract $response = null);

    /**
     * Retrieve the response object, if any
     *
     * @return Zend_Controller_Response_Abstract|null
     */
    public function getResponse();

    /**
     * Add a controller directory to the controller directory stack
     *
     * @param string $path
     * @param string $args
     * @return Zend_Controller_Dispatcher_Interface
     */
    public function addControllerDirectory($path, $args = null);

    /**
     * Set the directory (or directories) where controller files are stored
     *
     * @param string|array $dir
     * @return Zend_Controller_Dispatcher_Interface
     */
    public function setControllerDirectory($path);

    /**
     * Return the currently set directory(ies) for controller file lookup
     *
     * @return array
     */
    public function getControllerDirectory();

    /**
     * Dispatch a request to a (module/)controller/action.
     *
     * @param  Zend_Controller_Request_Abstract $request
     * @param  Zend_Controller_Response_Abstract $response
     * @return Zend_Controller_Request_Abstract|boolean
     */
    public function dispatch(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response);

    /**
     * Whether or not a given module is valid
     *
     * @param string $module
     * @return boolean
     */
    public function isValidModule($module);
}

±×·¯³ª, ´ëºÎºÐÀÇ °æ¿ì´Â ´Ü¼øÇÏ°Ô Ãß»ó Ŭ·¡½º Zend_Controller_Dispatcher_Abstract (À»)¸¦ °è½ÂÇÏ´Â °Í¸¸À¸·Î ÃæºÐÇϰÚÁö¿ä.¿©±â¿¡´Â, ÀÌ·¯ÇÑ ¸Þ¼Òµå°¡ ¹ú½á Á¤Àǵǰí ÀÖ½À´Ï´Ù. ȤÀº,Zend_Controller_Dispatcher_Standard (À»)¸¦ °è½ÂÇϰí, Ç¥ÁØÀÇ ±â´É°ú ´Ù¸¥ ºÎºÐ¸¸Å­À» º¯°æÇÏ´Â °Íµµ °¡´ÉÇÕ´Ï´Ù.

µð½ºÆÖÃÄÀÇ ¼­ºê Ŭ·¡½º¸¦ ÀÛ¼ºÇÒ Çʿ䰡 ÀÖ´Â Àå¸éÀ¸·Î¼­´Â, ¿¹¸¦ µé¾î ¾×¼Ç ÄÜÆ®·Ñ·¯³»¿¡¼­ Ç¥Áذú´Â ´Ù¸¥ Ŭ·¡½º¸íÀ̳ª ¸Þ¼Òµå¸íÀÇ ¸í¸í ±ÔÄ¢À» »ç¿ëÇÏ°í ½Í´Ù´Â µî ¸»ÇÏ´Â °ÍÀ» »ý°¢ÇÒ ¼ö ÀÖ½À´Ï´Ù. ȤÀº, Ŭ·¡½º ¸Þ¼Òµå¿¡ ¹èºÐÇÏ´Â °ÍÀÌ ¾Æ´Ï¶ó ÄÜÆ®·Ñ·¯ µð·ºÅ丮´Â ÀÌÇÏÀÇ ¾×¼Ç ÆÄÀÏ¿¡ ¹èºÐÇÏ´Â µî, ´Ù¸¥ µð½ºÆÌÄ¡ ¹æ½ÄÀ» »ç¿ëÇÏ°í ½ÍÀº °æ¿ì¿¡µµ ¼­ºê Ŭ·¡½º¸¦ ÀÛ¼ºÇÒ Çʿ䰡 ÀÖ½À´Ï´Ù.