在Yii2中遇到路由问题。我在camelcase中有控制器操作名称,这是一个使用UrlRule类的url-manager规则。
动作:
public function actionCreateRole()
{
if (!isset($_POST['name'])) {
throw new BadRequestHttpException("Не передан обязательный параметр 'name'");
}
$name = $_POST['name'];
if ($this->getAuthManager()->getRole($name) !== null) {
throw new BadRequestHttpException("Роль уже существует");
}
$role = $this->getAuthManager()->createRole($name);
$role->description = $_POST['description'];
if (!$this->getAuthManager()->add($role)) {
throw new ServerErrorHttpException();
}
return $role;
}
UrlManager配置:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
[
'class' => 'yii\rest\UrlRule',
'controller' => [
'rbac',
],
'patterns'=>[
'POST role' => 'create-role',
],
],
],
],
根据要求有404错误。
我尝试将模式设置为:
'patterns'=>[
'POST role' => 'createRole',
],
回复 - 错误404。
我的错误在哪里?