3

嗨,我是 YII 2 框架的新手,

我目前正在学习以下教程http://www.yiiframework.com/wiki/490/creating-a-simple-crud-app-with-yii2-revised-12-20-2013/

一切正常,但是当我在 SiteController.php 中创建一个函数时

IE

 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,
            ]);
        }
    }

当我从浏览器访问它时,如下所示,

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

我越来越

找不到对象!在我的浏览器中,但我可以访问 SiteController.php 索引函数,如下所示http://localhost/basic/web/

不知道我在这里缺少什么,你能告诉我这个问题吗?

提前感谢

编辑:出于调试目的,我在\basic\web\index.php中放置了 die 语句,显然它也没有击中该文件

4

1 回答 1

5

行。我明白。你不使用.htaccess. 请把它.htaccess放在网络文件夹中。你需要检查 Apachemod_rewrite模式现在可用。

#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...

在https://github.com/yiisoft/yii2/blob/master/docs/guide/start-installation.md#recommended-apache-configuration-中查看更多信息

就像urlManager那样https://yadi.sk/i/TIKuhYPHehMJq _components

'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>',
            ],
        ],

这是工作 - https://yadi.sk/i/7iOzHBm1ehMFE

于 2015-02-16T05:12:40.297 回答