YII2中的REST web服务的一个小的疑问,Yii2方面的大神请进

WBOY
Release: 2016-06-06 20:39:13
Original
1005 people have browsed it

<code>php</code><code><br><br>配置URL规则

然后,修改有关在应用程序配置的urlManager组件的配置:

'urlManager' => [
    'enablePrettyUrl' => true,
    'enableStrictParsing' => true,
    'showScriptName' => false,
    'rules' => [
        ['class' => 'yii\rest\UrlRule', 'controller' => 'user'],
    ],
]
上面的配置主要是为user控制器增加一个 URL 规则。这样, 用户的数据就能通过美化的 URL 和有意义的 http 动词进行访问和操作。
</code>
Copy after login
Copy after login

原文在这里:
http://www.yiichina.com/doc/guide/2.0/rest-routing

上面的配置主要是为user控制器增加一个 URL 规则。那比如我要为usercontroller 和

postcontroller,commentController都增加一个rules,我该怎么办呢?
是不是这样的:

<code>php</code><code>'rules' => [
        ['class' => 'yii\rest\UrlRule', 'controller' => 'user'],
         ['class' => 'yii\rest\UrlRule', 'controller' => 'post'],
         ['class' => 'yii\rest\UrlRule', 'controller' => 'comment'],
    ],
</code>
Copy after login
Copy after login

回复内容:

<code>php</code><code><br><br>配置URL规则

然后,修改有关在应用程序配置的urlManager组件的配置:

'urlManager' => [
    'enablePrettyUrl' => true,
    'enableStrictParsing' => true,
    'showScriptName' => false,
    'rules' => [
        ['class' => 'yii\rest\UrlRule', 'controller' => 'user'],
    ],
]
上面的配置主要是为user控制器增加一个 URL 规则。这样, 用户的数据就能通过美化的 URL 和有意义的 http 动词进行访问和操作。
</code>
Copy after login
Copy after login

原文在这里:
http://www.yiichina.com/doc/guide/2.0/rest-routing

上面的配置主要是为user控制器增加一个 URL 规则。那比如我要为usercontroller 和

postcontroller,commentController都增加一个rules,我该怎么办呢?
是不是这样的:

<code>php</code><code>'rules' => [
        ['class' => 'yii\rest\UrlRule', 'controller' => 'user'],
         ['class' => 'yii\rest\UrlRule', 'controller' => 'post'],
         ['class' => 'yii\rest\UrlRule', 'controller' => 'comment'],
    ],
</code>
Copy after login
Copy after login

你写的也是个方法,但是 UrlRulecontroller 属性可以使string或者是array.

<code>'rules' => [
    ['class' => 'yii\rest\UrlRule', 'controller' => ['user', 'post', 'comment']],
]
</code>
Copy after login

个人觉得yii并没有实现真正意义上的rest

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template