Yii Framework Forum: Error While creating a Rest Api in Yii2 Advanced Template [CLOSED] - Yii Framework Forum

Jump to content

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

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

#1 User is offline   ajith 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 170
  • Joined: 20-March 15
  • Location:Kerala,India

Posted 01 January 2016 - 11:45 PM

Hi,

I tried creating a rest api in yii2 advanced template.
this is my folder structure. Urshow is my folder name.

Quote


api
-config
-modules
--v1
---controllers
---models
-runtime
-tests
-web

backend
common
console
environments
frontend


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

Quote



I get a ERROR like this



Not Found (#404)

Page not found.
The above error occurred while the Web server was processing your request.

Please contact us if you think this is a server error. Thank you.


myurshow/api/config/main .php


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

#2 User is offline   ajith 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 170
  • Joined: 20-March 15
  • Location:Kerala,India

Posted 02 January 2016 - 12:19 AM

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

0

#3 User is offline   ajith 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 170
  • Joined: 20-March 15
  • Location:Kerala,India

Posted 02 January 2016 - 04:32 AM

I solved it Posted ImagePosted ImagePosted Image
0

#4 User is offline   josimarjafa 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 14-December 14

Posted 09 May 2016 - 02:36 PM

View Postajith, on 02 January 2016 - 04:32 AM, said:

I solved it Posted ImagePosted ImagePosted Image


how you solve it?, please.
1

#5 User is offline   Ƒяąȼţąℓ ϻɨɲď 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 119
  • Joined: 04-May 12

Posted 27 June 2017 - 03:37 PM

View Postajith, on 02 January 2016 - 04:32 AM, said:

I solved it Posted ImagePosted ImagePosted Image


Seriously bro?...

Share your answer
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