Namespace and modules


(Anisrehan) #1

Hello All
I am trying to create a module in my yii based app and due to clash in class names I need to use namespaces. The problem is I am constantly facing the

Unable to resolve the request "payroll/department/create".

My directory structure is as follows

protected/modules/payroll

PayrollModule.php

protected/modules/payroll.controllers

DepartmentController.php
TaskController.php

protected/modules/payroll/models

Department.php
Task.php

the initial lines of all files are

PayrollModule.php

namespace payroll;
class PayrollModule extends \CWebModule {

modules/payroll/controllers/DepartmentController.php

namespace payroll\controllers;
class DepartmentController extends \Controller {

modules/payroll/models/Department.php

namespace payroll\models;
class Department extends \CActiveRecord {

Also in config.php
// adding namespaces
Yii::setPathOfAlias('payroll', dirname(__DIR__) . '/protected/modules/payroll');

return array(

‘payroll’ => array(
‘moduleName’ => ‘payroll’,
‘class’ => ‘payroll\PayrollModule’,
),

);

any help is appreciated.


#2

404
It seems you have routing problems.
Check that your namespace Is correctly registered.
Check that your controller is correctly registered.
Then check the create action with no code. Just return simple text.

For namespace settings
https://www.yiiframework.com/doc/guide/1.1/en/basics.namespace