vova07 / yii2-start

Yii2-Start application
Other
273 stars 115 forks source link

frontend url #103

Closed JarkoeSoLnze closed 9 years ago

JarkoeSoLnze commented 9 years ago

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

alexssdd commented 9 years ago

try open frontend/product/index/

vova07 commented 9 years ago

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>'

yiioverflow commented 9 years ago

Me too trying to solve the same issue.

vova07 commented 9 years ago

@yiioverflow did you follow the instruction above?

yiioverflow commented 9 years ago

@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?

  1. in /home/roopz/www/local.topolor.co.uk/vendor/yiisoft/yii2/BaseYii.php at line 291

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;

vova07 commented 9 years ago

What error do you see after you change the controller' namespace?

yiioverflow commented 9 years ago

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?

  1. in /home/roopz/www/local.topolor.co.uk/vendor/yiisoft/yii2/BaseYii.php at line 291 282283284285286287288289290291292293294295296297298299300 return; } } else { return; }
    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.
  1. yii\BaseYii::autoload('app\controllers\CoursesControlle...')
  2. spl_autoload_call('app\controllers\CoursesControlle...')
  3. in /home/roopz/www/local.topolor.co.uk/vendor/yiisoft/yii2/base/Module.php – class_exists('app\controllers\CoursesControlle...') at line 563
  4. in /home/roopz/www/local.topolor.co.uk/vendor/yiisoft/yii2/base/Module.php – yii\base\Module::createControllerByID('courses') at line 521
  5. in /home/roopz/www/local.topolor.co.uk/vendor/yiisoft/yii2/base/Module.php – yii\base\Module::createController('courses/index') at line 449
  6. in /home/roopz/www/local.topolor.co.uk/vendor/yiisoft/yii2/web/Application.php – yii\base\Module::runAction('courses/index', []) at line 83
  7. in /home/roopz/www/local.topolor.co.uk/vendor/yiisoft/yii2/base/Application.php – yii\web\Application::handleRequest(yii\web\Request) at line 375
  8. in /home/roopz/www/local.topolor.co.uk/backend/web/index.php – yii\base\Application::run() at line 17
yiioverflow commented 9 years ago

I dont know why its still checking from app\controllers.

vova07 commented 9 years ago

mmmm ... it's strange. Can you show your full CoursesController code?

JarkoeSoLnze commented 9 years ago

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

vova07 commented 9 years ago

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:

Change your controller namespace to frontend\controllers to fix your problem.

carlos-andres commented 9 years ago

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?..

step1

step2

step3

backendcontroller

vova07 commented 9 years ago

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!

carlos-andres commented 9 years ago

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?

error3

views

vova07 commented 9 years ago

@carlos-andres change your controller namespace to backend\controllers. And try again! About view re-generation I'm not sure, need to check it.

carlos-andres commented 9 years ago

thanks, i decide to work with modules, and works perfectly

joker58 commented 9 years ago

Добрый день Выловил точно такую же ошибку 15952646-8465-11e4-8b58-85ddb76d52a4 В конфиге 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 Спасибо за помощь

vova07 commented 9 years ago

@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.

joker58 commented 9 years ago

Спасибо за помощь! Это действительно сработало!