I have this error and I don't know to solved.
I created an api endpoint with Yii2. A few days ago the endpoint was working but now it doesn't and raise this error:
{
name: "Unknown Property",
message: "Setting unknown property: yii\web\UrlRule::GET index",
code: 0,
type: "yii\base\UnknownPropertyException",
file: "C:\xampp\htdocs\forkandjoin\vendor\yiisoft\yii2\base\Object.php",
line: 161,
stack-trace: [
"#0 C:\xampp\htdocs\forkandjoin\vendor\yiisoft\yii2\BaseYii.php(521): yii\base\Object->__set('GET index', 'index')",
"#1 C:\xampp\htdocs\forkandjoin\vendor\yiisoft\yii2\base\Object.php(105): yii\BaseYii::configure(Object(yii\web\UrlRule), Array)",
"#2 [internal function]: yii\base\Object->__construct(Array)",
"#3 C:\xampp\htdocs\forkandjoin\vendor\yiisoft\yii2\di\Container.php(374): ReflectionClass->newInstanceArgs(Array)",
"#4 C:\xampp\htdocs\forkandjoin\vendor\yiisoft\yii2\di\Container.php(153): yii\di\Container->build('yii\\web\\UrlRule', Array, Array)",
"#5 C:\xampp\htdocs\forkandjoin\vendor\yiisoft\yii2\BaseYii.php(344): yii\di\Container->get('yii\\web\\UrlRule', Array, Array)",
"#6 C:\xampp\htdocs\forkandjoin\vendor\yiisoft\yii2\web\UrlManager.php(212): yii\BaseYii::createObject(Array)",
"#7 C:\xampp\htdocs\forkandjoin\vendor\yiisoft\yii2\web\UrlManager.php(154): yii\web\UrlManager->buildRules(Array)",
"#8 C:\xampp\htdocs\forkandjoin\vendor\yiisoft\yii2\base\Object.php(107): yii\web\UrlManager->init()",
"#9 [internal function]: yii\base\Object->__construct(Array)",
"#10 C:\xampp\htdocs\forkandjoin\vendor\yiisoft\yii2\di\Container.php(374): ReflectionClass->newInstanceArgs(Array)",
"#11 C:\xampp\htdocs\forkandjoin\vendor\yiisoft\yii2\di\Container.php(153): yii\di\Container->build('yii\\web\\UrlMana...', Array, Array)",
"#12 C:\xampp\htdocs\forkandjoin\vendor\yiisoft\yii2\BaseYii.php(344): yii\di\Container->get('yii\\web\\UrlMana...', Array, Array)",
"#13 C:\xampp\htdocs\forkandjoin\vendor\yiisoft\yii2\di\ServiceLocator.php(133): yii\BaseYii::createObject(Array)",
"#14 C:\xampp\htdocs\forkandjoin\vendor\yiisoft\yii2\base\Application.php(563): yii\di\ServiceLocator->get('urlManager')",
"#15 C:\xampp\htdocs\forkandjoin\vendor\yiisoft\yii2\web\Request.php(180): yii\base\Application->getUrlManager()",
"#16 C:\xampp\htdocs\forkandjoin\vendor\yiisoft\yii2\web\Application.php(75): yii\web\Request->resolve()",
"#17 C:\xampp\htdocs\forkandjoin\vendor\yiisoft\yii2\base\Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))",
"#18 C:\xampp\htdocs\forkandjoin\api\index.php(13): yii\base\Application->run()",
"#19 {
There is my urlManager configuration:
modules' => [
'v1' => [
'basePath' => '@app/api/modules/v1', // base path for our module class
'class' => 'app\api\modules\v1\Api', // Path to module class
]
]
'components' => [
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [
'class' => 'yii\rest\UrlRule',
'controller' => 'v1/demo',
'patterns' => [
'GET index' => 'index'
]
],
],
I created this simple example with a Demo controller and a simple index endpoint in order to show to get a more clear picture about the problem.
How can I solve this problem? why is return unknown property.
OS: Windows 10.
Composer: version 1.0.0 2016-04-05 13:27:25
Yii version: 2
{
"name": "yiisoft/yii2-app-advanced",
"description": "Yii 2 Advanced Project Template",
"keywords": ["yii2", "framework", "advanced", "project template"],
"homepage": "http://www.yiiframework.com/",
"type": "project",
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/yiisoft/yii2/issues?state=open",
"forum": "http://www.yiiframework.com/forum/",
"wiki": "http://www.yiiframework.com/wiki/",
"irc": "irc://irc.freenode.net/yii",
"source": "https://github.com/yiisoft/yii2"
},
"minimum-stability": "stable",
"require": {
"php": ">=5.4.0",
"yiisoft/yii2": ">=2.0.6",
"yiisoft/yii2-bootstrap": "*",
"yiisoft/yii2-swiftmailer": "*",
"linslin/yii2-curl": "*"
},
"require-dev": {
"yiisoft/yii2-codeception": "*",
"yiisoft/yii2-debug": "*",
"yiisoft/yii2-gii": "*",
"yiisoft/yii2-faker": "*"
},
"config": {
"process-timeout": 1800
},
"extra": {
"asset-installer-paths": {
"npm-asset-library": "vendor/npm",
"bower-asset-library": "vendor/bower"
}
}
}
If you need more information just lemme know but I need to solve this problem now or I'll be a crazy man without return.
It is my controller:
<?php
namespace app\api\modules\v1\controllers;
use yii\rest\Controller;
class DemoController extends Controller
{
public function behaviors() {
return [
[
'class' => \yii\filters\ContentNegotiator::className(),
'formats' => [
'application/json' => \yii\web\Response::FORMAT_JSON,
],
],
];
}
public function actionIndex(){
return "index ";
}
}
I did these configuration following the official guide about Routing:
[
'class' => 'yii\rest\UrlRule',
'controller' => 'user',
'extraPatterns' => [
'GET search' => 'search',
],
]
wow, thank you guys. I had been working the whole weekend trying to solve this problem and based on your feedback and researching I found a little error in the configuration. In Yii2 guide explain the configuration in two piece of code. So I had to change my code from this:
'rules' => [
'class' => 'yii\rest\UrlRule',
'controller' => 'v1/demo',
'extraPatterns' => [
'GET index' => 'index'
]
]
to this one:
'rules' => [
[ // array item
'class' => 'yii\rest\UrlRule',
'controller' => 'v1/demo',
'extraPatterns' => [
'GET index' => 'index'
]
]//close the array item
]
Well, the error is gone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With