Error While creating a Rest Api in Yii2 Advanced Template [CLOSED]


(Ajith Tejas) #1

Hi,

I tried creating a rest api in yii2 advanced template.

this is my folder structure. Urshow is my folder name.

now there is a controller named movies inside api/modules/v1/controllers. I tried to access it like this

I get a ERROR like this

Not Found (#404)

Page not found.

[font="Verdana"]The above error occurred while the Web server was processing your request.[/font]

[font="Verdana"]Please contact us if you think this is a server error. Thank you.[/font]

myurshow/api/config/main .php[b]

[/b]





<?php

$params = array_merge(

    require(__DIR__ . '/../../common/config/params.php'),

    require(__DIR__ . '/../../common/config/params-local.php'),

    require(__DIR__ . '/params.php'),

    require(__DIR__ . '/params-local.php')

);

return [

    'id' => 'app-api',

    'basePath' => dirname(__DIR__),    

    'bootstrap' => ['log'],

    'modules' => [

        'v1' => [

            'basePath' => '@app/modules/v1',

            'class' => 'api\modules\v1\Module'

        ]

    ],

    'components' => [        

        'user' => [

            'identityClass' => 'common\models\Users',

            'enableAutoLogin' => true,

        ],

        'log' => [

            'traceLevel' => YII_DEBUG ? 3 : 0,

            'targets' => [

                [

                    'class' => 'yii\log\FileTarget',

                    'levels' => ['error', 'warning'],

                ],

            ],

        ],

        'urlManager' => [

            'enablePrettyUrl' => true,

            'enableStrictParsing' => true,

            'showScriptName' => true,

            'rules' => [

                ['class' => 'yii\rest\UrlRule', 'controller' => ['category', 'accounts']],

                ['class' => 'yii\rest\UrlRule', 'controller' => ['user'], 'extraPatterns' => 

                    ['POST login' => 'login', 'POST signup' => 'signup'] ],

                ['class' => 'yii\rest\UrlRule', 'controller' => ['movies'], 'extraPatterns' => ['GET details' => 'details']],

            ],

        ],

    ],

    'params' => $params,

];




So why am i getting a 404 ?


(Ajith Tejas) #2

i think 404 may be due to my .htaccess file







RewriteEngine on


 RewriteBase /urshow/api/web/

# If a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

# Otherwise forward it to index.php

RewriteRule . index.php


(Ajith Tejas) #3

I solved it


(Josimar A K A Jafa) #4

how you solve it?, please.


(Fryser D) #5

Seriously bro?..

Share your answer