4

Hi I'm a new bie to YII 2 framework,

I'm currently learning from following tutorial http://www.yiiframework.com/wiki/490/creating-a-simple-crud-app-with-yii2-revised-12-20-2013/

Everything worked well but when I created a function within SiteController.php

i.e

 public function actionLogin()
    {

        if (!\Yii::$app->user->isGuest) {
            return $this->goHome();
        }

        $model = new LoginForm();
        if ($model->load(Yii::$app->request->post()) && $model->login()) {
            return $this->goBack();
        } else {
            return $this->render('login', [
                'model' => $model,
            ]);
        }
    }

and when I access it from the browser as follow,

http://localhost/basic/web/site/login/

I'm getting

Object not found! in my browser but I can access the SiteController.php index function as follow http://localhost/basic/web/

Not sure what I'm missing here, could you please let me know the issue?

Thanks in Adavance

EDIT : For debug purpose I placed die statement in the \basic\web\index.php apparently it's not hitting that file also

FR STAR
  • 662
  • 4
  • 24
  • 50

1 Answers1

5

Ok. I understand. You not use .htaccess. Please put this .htaccess in web folder. And you need check to Apache modue mod_rewrite is avaible now.

#Options +FollowSymLinks
#IndexIgnore */*

#RewriteEngine on

# 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


    # use mod_rewrite for pretty URL support
    RewriteEngine on
    # If a directory or a file exists, use the request directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # Otherwise forward the request to index.php
    RewriteRule . index.php

    # ...other settings...

See more in https://github.com/yiisoft/yii2/blob/master/docs/guide/start-installation.md#recommended-apache-configuration-

And urlManager in components like that https://yadi.sk/i/TIKuhYPHehMJq

'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'enableStrictParsing' => true,          
            'rules' => [
                '<_c:[\w\-]+>' => '<_c>/index',
                '<_c:[\w\-]+>/<_a:[\w\-]+>' => '<_c>/<_a>',
                '<_c:[\w\-]+>/<_a:[\w\-]+>/<id:\d+>' => '<_c>/<_a>',
            ],
        ],

It is work - https://yadi.sk/i/7iOzHBm1ehMFE

vitalik_74
  • 4,573
  • 2
  • 19
  • 27