php - Yii2. Setting a custom controller namespace -


i have controller in components/test/test/controllers folder, called mycontroller. if set namespace "namespace app\components\test\test", , try call controller if says "page not found".

i have been reading , know default yii2 sets namespace controllers "app\controllers".

also know can change namespace controllers config:

'controllernamespace' => 'app\\components\test...' 

but wanted change 1 controller not all. similar modules, there can do:

$this->controllernamespace = 'app\modules\test\test'; 

i found there called "controllermap", maybe solution? ideas?

example have created inside "components" (basic template) controller locationcontroller content:

namespace app\components;  use yii\web\controller;  class locationcontroller extends controller  {      public function actionadd() {          return "hola1";     }      public function actionremove() {         return "hola2";     }  } 

when created link yii::$app->urlmanager->createabsoluteurl("location/add"); , click on "page not found" error.

update have found possible add classes classmap, not sure place it:

yii::$classmap['app\components\locationcontroller'] = '..path.../components/locaitoncontroller.php' 

maybe trick?

about "not found" problem, controllernamespace , namespace must have full path of controller, in case:

app\modules\test\test\controllers 

now,to change path single controller can think of creating module inside app (like mentioned):

<?php  namespace app\modules\test\test;  /**  * module definition class  */ class module extends \yii\base\module {     /**      * @inheritdoc      */     public $controllernamespace = 'app\modules\test\test\controllers';      /**      * @inheritdoc      */     public function init()     {         parent::init();          // custom initialization code goes here     } } 

and add in config module:

$config = [     ...     'modules' => [         'module' => 'app\modules\test\test\module'     ] ]; 

edit

you can add in config:

$config = [     ...    'controllermap' => [        'location' => 'app\components\locationcontroller',    ], ]; 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -