我调整了模块api,并创建了控制器UserController扩展了ActiveController。所有操作都很好,但是视图返回404错误。
-返回404 (错误)
-返回200 (确定)
为什么yii\rest\UrlRule在这种情况下不起作用?
有关此规则的官方页面信息:
GET /users/123: return the details of the user 123;
答案
将yii\rest\UrlRule:$多元性属性设置为false;
将enableStrictParsing设置为false。
我正在用Yii2实现RESTFUL。问题是我根本不使用模特。我的API只是获取请求并执行一些计算(或者将请求作为代理传递到其他地方)并输出响应。
我在app\modules\api\v1\控制器中有以下控制器:
namespace app\modules\api\v1\controllers;
class CarController extends \yii\rest\Controller
{
// GET /v1/car/:id
public function actionIndex()
{
$carId = \Yii::$app->reque
我在发出post请求时收到以下错误:
XMLHttpRequest cannot load http://api.dev/v1/call-rates/base/search. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not
我编写了一个自定义,它扫描目录,并将名为"*Controller.php“的任何文件添加到应用程序中允许的REST控制器列表中。
use yii\rest\UrlRule;
class RestWildcardUrlRule extends UrlRule
{
public $path = '@app/services/controllers';
public function init()
{
$d = dir(\Yii::getAlias($this->path));
$controllers = []
我正在研究yii2,并在本地机器上创建了一些REST API's. One is for authenticating the user and the second one is for getting the data by using the auth from the 1st API. I am usingxampp``。身份验证API运行得非常好。但是当我试图执行第二个API时,它给了我一个错误。下面是我的代码
main.php
<?php
$params = array_merge(
require(__DIR__ . '/../../common/conf
我有一个现有的Yii2应用程序,并且一直试图将REST作为一个附加模块来实现(也许一个模块不是正确的方法吗?)但我在配置路由结构时遇到了一些问题。它不完全工作,也不遵循预期的结果,基于。
我构建了一个额外的模块,如下所示:
module
api
controllers
UserController.php
Module.php
UserController.php
<?php
namespace app\modules\api\controllers;
use yii\rest\ActiveController;
class UserControll
我有,它为已经存在的用户模型提供了:
namespace app\controllers;
use yii\rest\ActiveController;
class UserController extends ActiveController
{
public $modelClass = 'app\models\User';
}
我修改了模型,使所有字段都是安全的:
public function rules()
{
return [
['status', 'default', 'value'
我正在学习本教程
我得到了这个教程,现在我可以看到GET /books:逐页列出所有书籍;
然而,现在我想创建一些端点,并且在我的控制器中添加了一个方法测试,但是我得到了一个404。这是我的控制器
namespace app\controllers;
use yii\rest\ActiveController;
class BookController extends ActiveController
{
public $modelClass = 'app\models\Book';
public function behaviors()
{
为什么不在Rest Yii2中显示关系数据
我有两张桌子。
示例:类别,子类别
<?php
namespace app\controllers;
use app\models\Category;
use yii\web\NotFoundHttpException;
use yii\web\Response;
use yii\rest\Controller;
class ApiController extends Controller
{
public function behaviors()
{
$behaviors = parent::b
Yii2,基本模板,版本控制。我正在尝试编写一种方法,它将返回令牌。
这是我的TokenController:
class TokenController extends Controller
{
public function actionIndex()
{
$model = new LoginForm();
$model->load(Yii::$app->request->bodyParams, '');
if ($token = $model->auth()) {
re
我正在制作angular 2/ Yii2应用程序
当我从Postman中调用自定义控制器/动作时,如果使用不记名标题,一切都正常,但当我从angular 2应用程序(localhost:4200)中使用相同的标题调用它时,我总是收到未授权的401错误。当我执行标准操作时,比如来自的示例,比如:
GET /users: list all users page by page;
POST /users: create a new user;
一切正常,只有当我创建自定义操作,而不是我得到未经授权。
这是跨域应用程序,angular在web.example.com上可用,yii2应用程序在srv.e