2011-03-24 76 views
0

我知道update-profile-picture轉換爲updateProfilePictureAction()函數。 動作參數的轉換髮生在哪裏? 我想要updateProfilePicture作爲一個值,我可以編寫函數,但它必須已經在圖書館的某處。 使用$this->_getParam('action')時,返回update-profile-picture;如何獲取Zend Framework MVC的「轉換」操作名稱?

/** 
    * Auto call scripts 
    * @see Zend_Controller_Action::postDispatch() 
    */ 
    public function postDispatch(){ 
     $action = $this->_getParam('action',false); 
     $method = $action.'Scripts'; 
     if ($action && method_exists($this, $method)) 
      $this->$method(); 
    } 

這個工作得很好的indexAction - indexScripts而不是updateProfilePictureScripts(尋找更新配置文件的pictureScripts)

回答

3

$this->getFrontController()->getDispatcher()->formatActionName($this->_getParam('action',null)); 

它在

發生得到它

/Zend/Controller/Dispatcher/Abstract.php

/** 
* Formats a string into an action name. This is used to take a raw 
* action name, such as one that would be stored inside a Zend_Controller_Request_Abstract 
* object, and reformat into a proper method name that would be found 
* inside a class extending Zend_Controller_Action. 
* 
* @param string $unformatted 
* @return string 
*/ 
public function formatActionName($unformatted) 
{ 
    $formatted = $this->_formatName($unformatted, true); 
    return strtolower(substr($formatted, 0, 1)) . substr($formatted, 1) . 'Action'; 
} 




/** 
* Formats a string from a URI into a PHP-friendly name. 
* 
* By default, replaces words separated by the word separator character(s) 
* with camelCaps. If $isAction is false, it also preserves replaces words 
* separated by the path separation character with an underscore, making 
* the following word Title cased. All non-alphanumeric characters are 
* removed. 
* 
* @param string $unformatted 
* @param boolean $isAction Defaults to false 
* @return string 
*/ 
protected function _formatName($unformatted, $isAction = false) 
{ 
    // preserve directories 
    if (!$isAction) { 
     $segments = explode($this->getPathDelimiter(), $unformatted); 
    } else { 
     $segments = (array) $unformatted; 
    } 

    foreach ($segments as $key => $segment) { 
     $segment  = str_replace($this->getWordDelimiter(), ' ', strtolower($segment)); 
     $segment  = preg_replace('/[^a-z0-9 ]/', '', $segment); 
     $segments[$key] = str_replace(' ', '', ucwords($segment)); 
    } 

    return implode('_', $segments); 
} 
+0

對不起,我居然在執行postDispatch檢查這,看看編輯 – Moak 2011-03-24 06:56:20

+0

是有可能,當你在這個動作在一些地方保存這個值,並在以後使用在postDispatch? – emaillenin 2011-03-24 07:01:47

+0

我的問題是「動作參數的轉換髮生在哪裏?」 - 在zend框架中。我可以亂搞,並得到它的工作,但我想盡可能重用代碼 – Moak 2011-03-24 07:24:19

相關問題