【问题标题】:Zend View Action Helper $params questionsZend View Action Helper $params 问题
【发布时间】:2010-07-22 13:12:20
【问题描述】:

我想知道 zend 视图动作助手的参数是通过什么方法传递的? getpost。是因为我似乎无法通过$_GET$_POST 访问它们,但我可以通过$this->getRequest()->getParam("xxx") 访问它们

然后我想在使用它之前检查变量是否存在,所以我这样做了

$itemsPerPage = isset($this->getRequest()->getParam("itemsPerPage")) ? $this->getRequest()->getParam("itemsPerPage") : 5;

失败了

致命错误:无法使用方法返回 写入上下文中的值 D:\Projects\Websites\php\ZendFramework\LearningZF\application\controllers\IndexController.php 第 21 行

不知道怎么了

【问题讨论】:

    标签: zend-framework


    【解决方案1】:

    如果没有设置参数,你可以设置一个默认值返回

    $itemsPerPage = $this->getRequest()->getParam('itemsPerPage', 5)
    

    查看there 的错误原因,isset() 也是如此。

    function getFoo()
    {
        return 'foo';
    }
    
    var_dump(isset(getFoo()); // causes Fatal error
    
    $foo = getFoo();
    var_dump(isset($foo)); // prints "boolean true"
    

    【讨论】:

    • 哦,所以isset 只会检查变量而不是函数返回值?
    • 完全正确:“isset() 仅适用于变量,因为传递任何其他内容都会导致解析错误。”
    猜你喜欢
    • 2011-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多