【问题标题】:restfullyii Defining Custom Routesrestfullyii 定义自定义路由
【发布时间】:2013-12-14 01:09:56
【问题描述】:

我使用 yii restful 扩展 http://www.yiiframework.com/extension/restfullyii/ 构建 api

我想创建一个接受用户名和密码然后返回所有用户的登录 api

我认为正确的方法是在检查后创建自定义路由器

扩展文档部分Defining Custom Routes作者说我必须创建http动词组合(事件名称='req..\.render')

[POST] api/登录/登录

创建网址我这样做

main.php

 array('<controller>/req.post.login', 'pattern'=>'api/<controller:\w+>', 'verb'=>'POST'),


login Controller :
public function restEvents()
    {
        $this->onRest('req.post.login.render', function() {
            echo "sss";
            //Custom logic for this route.
            //Should output results.
            $this->emitRest('req.render.json', [
                    [
                    'type'=>'raw',
                    'data'=>['active'=>true]
                    ]
                    ])
        });
    }

  restEvents  didn't fire any help ??

【问题讨论】:

    标签: api


    【解决方案1】:

    要创建自定义路由,请将其添加到控制器,url 将是http://css.local.com/index.php/api/controlername/test

        $this->onRest('req.post.test.render',function() {
    
    
            $this->emitRest('req.render.json', [
                    [
                    'type'=>'raw',
                    'data'=>data
                    ]
                    ]);
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-01
      • 1970-01-01
      • 2018-10-04
      • 2018-03-12
      • 2016-05-17
      • 2012-01-13
      相关资源
      最近更新 更多