Yii Framework Forum: How to configuration for module? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to configuration for module? Rate Topic: -----

#1 User is offline   nguoi.tap.code 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 02-October 17

Posted 02 October 2017 - 11:52 AM

I want to use DIRECTORY STRUCTURE for module. see below

config/    -> general config
models/
modules
    api/
        components/
        config/main.php     -> Only config for api
        controllers/
        Module.php
    backend/
        components/
        config/main.php     -> Only config for backend
        controllers/
        views/
        Module.php
    frontend/
        components/
        config/main.php    -> Only config for frontend
        controllers/
        views/
        Module.php
web/
    index.php
    themes/
        backend/     -> theme for backend
        frontend/      -> theme for frontend



I use this guide http://www.yiiframew...re-modules.html , http://www.yiiframew...uick-start.html
And created main.php config for api
<?php
return [

    'components' => [
        // list of component configurations
        'request' => [
            'class' => 'yii\web\Request',
            'parsers' => [
                'application/json' => 'yii\web\JsonParser',
            ]
        ],
        'urlManager' => [
            'class' => 'yii\web\UrlManager',
            'enablePrettyUrl' => true,
            'enableStrictParsing' => true,
            'showScriptName' => false,
            'rules' => [
                ['class' => 'yii\rest\UrlRule', 'controller' => 'user'],
            ],
        ]
    ],
    'params' => [
        // list of parameters
    ],
];

And include it in init() function (Module.php file)
\Yii::configure($this, require(__DIR__ . '/main.php'));


And access to: base_url/api/users, but response is "Page not found."
Please help me
0

#2 User is offline   umneeq 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 149
  • Joined: 10-October 11
  • Location:Russia

Posted 08 October 2017 - 06:39 AM

Check app.log's
Is `UsersController` with `actionIndex()` in `api` module exist?
0

#3 User is offline   nguoi.tap.code 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 02-October 17

Posted 14 October 2017 - 12:20 PM

View Postumneeq, on 08 October 2017 - 06:39 AM, said:

Check app.log's
Is `UsersController` with `actionIndex()` in `api` module exist?

Hi @umneeq,
Controller and action is exist.
My problem is configuration for module.

I have a yii2 basic application with 2 parts (web and service for mobile).

I have created a module to handle the restful requests fired from mobile . I want to configure this module to be rest. So I created a config file for this module in side the module directory. as mentioned in the yii2 documentation for modules

/config/config.php:
return [

'components' => [
  'urlManager' => [
        'class' => 'yii\web\UrlManager',
        // Disable index.php
        'showScriptName' => false,
        // Disable r= routes
        'enablePrettyUrl' => true,
        'enableStrictParsing' => false,
        'rules' => array(

            [
                'class' => 'yii\rest\UrlRule',
                'controller' => 'mobile/mobile-clients',
                'extraPatterns' => ['GET search' => 'search']
            ],

        ),
    ],
    'request' => [
        'class' => '\yii\web\Request',
        'enableCookieValidation' => false,
        'parsers' => [
            'application/json' => 'yii\web\JsonParser',
        ],
    ],
]

];


the module class is as follows:
class Module extends \yii\base\Module
{

    /**
     * @inheritdoc
     */
    public function init()
    {
        parent::init();

        // custom initialization code goes here

        // initialize the module with the configuration loaded from config.php
        Yii::configure($this, require(__DIR__ . '/config/config.php'));
    }
}


The problem is that the request component is not working as expected while it works fine when configured in the application configuration (config/main.php)

same for the urlManager.

Any Ideas?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users