【问题标题】:How do I create actions with names that are not camel cased in Zend Framework?如何在 Zend 框架中创建名称不是驼峰式大小写的操作?
【发布时间】:2011-12-12 05:31:43
【问题描述】:

我的控制器名称是 api,我想创建一个动作 update_user_infoAction(),但是当我尝试创建一个动作 zf create action update_user_info Api 时,我收到一个错误:

动作名称应该是驼峰式的。

这是我的终端命令和输出:

volition@volition-H61M-DS2:/var/www/Dashboard_check$ zf create action update_user_info Api

注意:生成控制器测试存根需要 PHPUnit。
发生错误
动作名称应该是驼峰式的。

Zend Framework 命令行控制台工具 v1.11.10 操作“创建”和提供者“操作”的详细信息 行动 zf create action name controller-name[=Index] view-included[=1] module

有人建议我使用 Zend Router,但我是 Zend Framework 的新手,所以请建议我如何创建此操作。

注意:- 我不想更改我的操作名称

我正在尝试创建一个带有下划线的动作。我已将此代码添加到我的引导程序中:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap 
{ 
    protected function _initDoctype() 
    { 
         $dispatcher = $front->getDispatcher();
         $dispatcher->setWordDelimiter(array('.', '-'))->setPathDelimiter(''); 
    } 
} 

但是,当我执行以下操作时:zf create controller update_user_info,我仍然收到相同的错误。

更新:正如@emaillenin 所建议的那样

我现在正在尝试:

<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initDoctype() 
    {
        $frontController = Zend_Controller_Front::getInstance();
        $dispatcher = $frontController->getDispatcher();
        $dispatcher->setWordDelimiter(array('-', '.', '_'));
    }
}

http://localhost/Dashboard_check/public/api/update_user_info

但同样,它不起作用,因为它适用于

http://localhost/Dashboard_check/public/api/updateuserinfo

【问题讨论】:

    标签: php zend-framework


    【解决方案1】:

    在您的引导程序中,添加以下代码行,

    $frontController = Zend_Controller_Front::getInstance();
    $dispatcher = $frontController->getDispatcher();
    $dispatcher->setWordDelimiter(array('-', '.', '_'));
    

    当您调用 www.example.com/api/update_user_info

    将调用以下函数。

    public function updateUserInfoAction() {
    
    }
    

    将此操作的视图脚本保存在 update-user-info.phtml

    参考资料 -

    http://zend-framework-community.634137.n4.nabble.com/Question-about-underscores-in-controller-and-action-names-td656525.html

    http://www.zfforums.com/zend-framework-general-discussions-1/general-q-zend-framework-2/underscore-action-name-1204.html

    http://zend-framework-community.634137.n4.nabble.com/underscore-in-URL-td648359.html

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-14
    • 1970-01-01
    • 2010-12-09
    • 2014-10-22
    • 1970-01-01
    • 2018-12-18
    相关资源
    最近更新 更多