Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Yii未检测到驼峰案例行动_Php_Yii_Yii2_Camelcasing - Fatal编程技术网

Php Yii未检测到驼峰案例行动

Php Yii未检测到驼峰案例行动,php,yii,yii2,camelcasing,Php,Yii,Yii2,Camelcasing,如果我声明这样的操作,Yii将给我404错误: SiteController.php public function actionRegisterUser() 这就是我在main.php ['label' => 'Register User', 'url' => ['/site/RegisterUser']], 我尝试了几种不同的组合。唯一有效的组合是这两个地方的命名约定: public function actionRegisteruser 'url' => [

如果我声明这样的操作,Yii将给我
404错误

SiteController.php

public function actionRegisterUser()
这就是我在
main.php

 ['label' => 'Register User', 'url' => ['/site/RegisterUser']],

我尝试了几种不同的组合。唯一有效的组合是这两个地方的命名约定:

 public function actionRegisteruser

 'url' => ['/site/registeruser']
我曾经在另一个Yii项目(yii1.0)上工作,我可以用camel case命名我的操作,并毫无问题地调用它们我是否需要打开某种设置才能执行此操作


我还尝试过使用控制器的
规则,但没有解决任何问题。

您需要像这样指定操作
['/site/register user']
。正如关于内联操作所说:

index
变成
actionIndex
helloworld
变成
actionHelloWorld


在某些情况下,您需要camelcase链接。例如,出于SEO目的(保留入站链接)。您可以在web服务器端创建重写规则,或者将内联规则添加到应用程序端的URL管理器中。例如:

'urlManager' => [
    'rules' => [
        '<controller:RegisterUser>/<action:\w+>'=>'register-user/<action>',
    ],
],
namespace app\components;

use yii\web\UrlRuleInterface;
use yii\base\Object;

class CarUrlRule extends Object implements UrlRuleInterface
{

    public function createUrl($manager, $route, $params)
    {
        if ($route === 'car/index') {
            if (isset($params['manufacturer'], $params['model'])) {
                return $params['manufacturer'] . '/' . $params['model'];
            } elseif (isset($params['manufacturer'])) {
                return $params['manufacturer'];
            }
        }
        return false;  // this rule does not apply
    }

    public function parseRequest($manager, $request)
    {
        $pathInfo = $request->getPathInfo();
        if (preg_match('%^(\w+)(/(\w+))?$%', $pathInfo, $matches)) {
            // check $matches[1] and $matches[3] to see
            // if they match a manufacturer and a model in the database
            // If so, set $params['manufacturer'] and/or $params['model']
            // and return ['car/index', $params]
        }
        return false;  // this rule does not apply
    }
}
并在[[yii\web\UrlManager::rules]]配置中使用新的规则类:

[
    // ...other rules...

    [
        'class' => 'app\components\CarUrlRule', 
        // ...configure other properties...
    ],
]