Yii Framework and HTML5 template file together

时间:2017-03-22 18:40:47

标签: yii yii2

I have one question: my website would be localhost/carfinancing/index.php

I have different index.php page right now which is in HTML5 template and Yii is installed in "application" directory.

When I copy paste this directory then localhost/carfinancing/application/web/ shows my yii index page and localhost/carfinancing/application/web/online-car-loan-application shows another page.

Is there way for yii index file to show: localhost/carfinancing/application and for another page, to show: localhost/carfinancing/online-car-loan-application ? I mean to remove the '/web/' word from the url?

1 个答案:

答案 0 :(得分:0)

看起来你有2个问题。我会努力回答这两个问题。

1您的HTML5模板应该是视图/ [控制器名称]

中的视图文件

由于Yii2是MVC框架,因此它被设计为将所有请求都提供给控制器,然后控制器提供视图。如果您要将文件放在Web中直接查看,那么您将失去MVC的好处。

2要从URL中删除Web /目录,您需要使用URL管理器。

config/web.php

的组件中添加urlManager
$config = [
...
'components' => [
'urlManager' => [
    'enablePrettyUrl' => true,
    'showScriptName' => false,
],

您还需要按如下方式设置.htaccess:

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

然后将所有内容移出public_html目录,并将web目录中的所有内容放回public_html

如果您仍有问题,请参阅此文章:http://fellowtuts.com/yii/hide-or-remove-basicweb-from-url-in-yii-2-0/