如何使用Zend Framework中没有驼峰的名称创建操作?

时间:2011-12-12 05:31:44

标签: php zend-framework

我的控制器名称为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

1 个答案:

答案 0 :(得分: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