मै अपने नियंत्रक वर्ग के साथ Zend_Controller_Action
बढ़ाया और बना दिया है परिवर्तन में जोड़ें:
dispatch($action)
में विधि प्रतिस्थापित
$this->$action();
call_user_func_array(array($this,$action), $this->getUrlParametersByPosition());
साथ
और मेरे कार्रवाई में तरह /mycontroller/myaction/123/321
एक यूआरएल के लिए अब जोड़ा निम्न विधि
/**
* Returns array of url parts after controller and action
*/
protected function getUrlParametersByPosition()
{
$request = $this->getRequest();
$path = $request->getPathInfo();
$path = explode('/', trim($path, '/'));
if(@$path[0]== $request->getControllerName())
{
unset($path[0]);
}
if(@$path[1] == $request->getActionName())
{
unset($path[1]);
}
return $path;
}
मैं नियंत्रक के बाद सभी पैरामीटर मिल जाएगा और कार्रवाई
public function editAction($param1 = null, $param2 = null)
{
// $param1 = 123
// $param2 = 321
}
यूआरएल में अतिरिक्त पैरामीटर किसी भी त्रुटि का कारण नहीं बनेंगे क्योंकि आप परिभाषित विधि के लिए अधिक पैरा भेज सकते हैं। आप उन्हें func_get_args()
से प्राप्त कर सकते हैं और आप अभी भी getParam()
सामान्य तरीके से उपयोग कर सकते हैं। आपके यूआरएल में डिफ़ॉल्ट का उपयोग कर एक्शन नेम नहीं हो सकता है।
असल में मेरे यूआरएल में पैरामीटर नाम नहीं हैं। केवल उनके मूल्य। (जैसा कि यह प्रश्न में था) और आपको फ्रेमवर्क की अवधारणाओं का पालन करने और ज़ेंड विधियों का उपयोग करके यूआरएल बनाने में सक्षम होने के लिए यूआरएल में पैरामीटर पदों को निर्दिष्ट करने के लिए मार्गों को परिभाषित करना होगा। लेकिन यदि आप हमेशा यूआरएल में अपने पैरामीटर की स्थिति जानते हैं तो आप इसे आसानी से प्राप्त कर सकते हैं।
यह प्रतिबिंब विधियों का उपयोग करने के रूप में परिष्कृत नहीं है लेकिन मुझे लगता है कि कम ओवरहेड प्रदान करता है।
डिस्पैच विधि अब इस तरह दिखता है:
/**
* Dispatch the requested action
*
* @param string $action Method name of action
* @return void
*/
public function dispatch($action)
{
// Notify helpers of action preDispatch state
$this->_helper->notifyPreDispatch();
$this->preDispatch();
if ($this->getRequest()->isDispatched()) {
if (null === $this->_classMethods) {
$this->_classMethods = get_class_methods($this);
}
// preDispatch() didn't change the action, so we can continue
if ($this->getInvokeArg('useCaseSensitiveActions') || in_array($action, $this->_classMethods)) {
if ($this->getInvokeArg('useCaseSensitiveActions')) {
trigger_error('Using case sensitive actions without word separators is deprecated; please do not rely on this "feature"');
}
//$this->$action();
call_user_func_array(array($this,$action), $this->getUrlParametersByPosition());
} else {
$this->__call($action, array());
}
$this->postDispatch();
}
// whats actually important here is that this action controller is
// shutting down, regardless of dispatching; notify the helpers of this
// state
$this->_helper->notifyPostDispatch();
}
नाइस, डॉक्स संबंध में इतना स्पष्ट नहीं कर रहे हैं। –