2010-10-26 68 views
0

如何在控制器中访问此参数值?如何访问请求中传递的参数

$router->map('Company', 'Company', array( 
'controller' => 'companies', 
'action' => 'add', 
'paramkey' => 'paramvalue', 
'anotherparam' => 'anothervalue')); 

PLZ帮我

回答

0

尝试

$this->getRequest()->getParam('paramkey'); 
+0

我应该在哪里声明getrequest和getparam? – ekta 2010-10-26 11:45:35

+0

insinde控制器方法 – heximal 2010-10-26 12:11:01

+0

可以请你帮我定义方法吗? – ekta 2010-10-28 05:49:56

0

得到一个PARAM:

$this->getRequest()->getParam('paramkey'[, 'default value']); 

得到所有PARAMS:

$this->getRequest()->getAllParams(); 

$this->_getParam('paramkey'[, 'default value']); 
$this->_getAllParams(); 

我真的使用Zend Framework等等方法Zend_Action_Contoller描述:

/** 
* Gets a parameter from the {@link $_request Request object}. If the 
* parameter does not exist, NULL will be returned. 
* 
* If the parameter does not exist and $default is set, then 
* $default will be returned instead of NULL. 
* 
* @param string $paramName 
* @param mixed $default 
* @return mixed 
*/ 
protected function _getParam($paramName, $default = null) 

如果你正在使用CacePHP你可以尝试

$this->params['paramkey']; 

,但我真的不知道它将工作

+0

它显示getParam未知方法 – ekta 2010-10-26 11:43:58

+0

我刚刚测试过,一切正常工作对我来说也许你使用错误或不在控制器? – Vytautas 2010-10-26 13:57:00

+0

你有没有安装zend?我的意思是我猜它应该在zend中定义。但是我必须做定制的s/w有它自己的框架,但它与cakephp类似...所以让我知道我应该在哪里找到getParam? – ekta 2010-10-28 05:52:17