Closed JarkoeSoLnze closed 9 years ago
try open frontend/product/index/
The right URL is my-site.com/product/index/
without frontend
and with /
at the end.
Also the namespace must be namespace frontend\controllers;
instead of namespace app\controllers;
.
And also you need to add the rule to your URL Manager
for your new controller, something like: '<_c:\w+>/<_a:\w+>' => '<_c>/<_a>'
Me too trying to solve the same issue.
@yiioverflow did you follow the instruction above?
@vova07 Yes i followed the instructions above, I am creating controller inside /backend/. And my url looks like http://local.topolor.co.uk/backend/courses/index/
I am getting one error like
Unknown Class – yii\base\UnknownClassException
Unable to find 'app\controllers\CoursesController' in file: /home/roopz/www/local.topolor.co.uk/backend/controllers/CoursesController.php. Namespace missing?
I change my namespace to
<?php
namespace backend\controllers;
use Yii; use common\models\Courses; use common\models\CoursesSearch; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter;
What error do you see after you change the controller' namespace?
Please see the error line number 2. and 3.
Unknown Class – yii\base\UnknownClassException
Unable to find 'app\controllers\CoursesController' in file: /home/roopz/www/local.topolor.co.uk/backend/controllers/CoursesController.php. Namespace missing?
include($classFile);
if (YII_DEBUG && !class_exists($className, false) && !interface_exists($className, false) && !trait_exists($className, false)) {
throw new UnknownClassException("Unable to find '$className' in file: $classFile. Namespace missing?");
}
}
/**
* Creates a new object using the given configuration.
*
* You may view this method as an enhanced version of the `new` operator.
* The method supports creating an object based on a class name, a configuration array or
* an anonymous function.
I dont know why its still checking from app\controllers.
mmmm ... it's strange. Can you show your full CoursesController
code?
I put '<_c:\w+>/<_a:\w+>' => '<_c>/<_a>' into frontend/config/main.php
'urlManager' => [ 'rules' => [ '<_c:\w+>/<_a:\w+>' => '<_c>/<_a>', '' => 'site/default/index', '<_a:(about|contacts|captcha)>' => 'site/default/<_a>' ]
and ProductController namespace is
namespace app\controllers;
and url is
yii2-start/product/index/ with / at the end
and ProductController namespace is namespace app\controllers;
Remember that in advanced
and yii2-start
templates doesn't exist namespace app
. There is 4 different namespaces instead:
backend
frontend
common
console
Change your controller namespace to frontend\controllers
to fix your problem.
Good Day, i try to use GII but for backend and also it not working.
here are my steps, 1 in gii, 2 in backend app, 3, check te files and it generated under backend\web not backend\views, 4. controller code, and also i try to move views and not work.
is there another alternative to create crud?..
Good day @carlos-andres
Please add a url
rule for your backend controllers, in backend/config/main
. Something like this: '<_c>/<_a>' => '<_c>/<_a>'
After try to access your CRUD
controller on URL address: http://my-site.com/backend/proyectos/index/
Good luck!
greetins @vova07 amazing support.
one step closer :D thanks again but i get another error, and extra answer why views are re-generated again under backend\web\backend\web\views and not in backend\views check my config params in the last post please?
@carlos-andres change your controller namespace to backend\controllers
. And try again!
About view re-generation I'm not sure, need to check it.
thanks, i decide to work with modules, and works perfectly
Добрый день Выловил точно такую же ошибку В конфиге backend/main.php 'rules' => [ '' => 'admin/default/index', '<_c>/<_a>' => '<_c>/<_a>'
В контроллере прописан неймспейс namespace backend\controllers;
Но если заменить неймспейс на !!!! namespace app\controllers; то все отлично начинает работать http://test.ru/backend/citys/index/ Что довольно странно, и противоречит советам выше 0_o Спасибо за помощь
@joker58 добавьте в backend/config/main.php
контроллер нэймспэйс: 'controllerNamespace' => 'backend\controllers'
должно помочь!
If somebody still have the same issue, you must add 'controllerNamespace' => 'backend\controllers'
to backend/config/main.php
file.
Спасибо за помощь! Это действительно сработало!
Hello
I use gii for crud generator for "product" (frontend) and I try to open frontend/product/index or frontend/product/index/
Not Found (#404) Unable to resolve the request "frontend/product/index".
I try without "frontend" and I get
Not Found (#404) Page not found.
Strucrure frontend -controllers ---ProductController Models -Product -ProductSearch Views -Product --- index ---... ---update
ProductController namespace app\controllers;
Whats wrong? Thanks