2

我正在使用 yii 框架开发一个 CMS。有前端和后端。我希望用户能够像这样访问后端:http ://www.mysite.com/admin ,现在它的工作方式是这样的:http ://www.mysite.com/admin.php 。

对于后端,我已经定义了不同的部分,它有自己的配置、控制器和......以及用于访问 admin.php 中的后端的页面

这是我的目录结构:

...
admin
     --components
     --config
         ---main.php
     --controllers
         ---NewsController.php
         ---ShowCOntroller.php
         ---SiteController.php
     --models
         ---LoginForm.php
         ---News.php
         ---Show.php
         ---User.php
     --runtime
     ...
     --Views
        ---layouts
        ---news
        ---show
        ---site

protected

    -commands
    -data
    -extentions
    -messages
    -migrations
    -models
    -modules
       --image
    -runtime
    -views


themes
uploads
admin.php
index.php
.htaccess  

这是我的 .htaccess 文件:

Options +FollowSymLinks
IndexIgnore */*
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule admin admin\.php [T=application/x-httpd-php]

 # 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
</IfModule>
4

6 回答 6

3

你可以看看我是如何在 @bool.dev Yii 的帮助下解决的: .htaccess 和 urlManager 用于单独的后端和前端

我希望它有所帮助。

于 2012-06-12T08:36:12.633 回答
2

您可以考虑的一件事是将后端创建为前端内的Yii 模块。模块就像应用程序中的应用程序。您将创建模型、控制器和视图,可能会重用前端的代码。访问模块的 URL 将包含模块名称;例如http://www.example.com/admin/controller/action

另一方面,如果您只想将发出的请求映射/admin到脚本admin.php,您可以在 mod_rewrite 中进行。例如:

# .htaccess
RewriteEngine On

RewriteRule ^admin admin.php     # route requests for /admin to admin.php

# Rest of Yii's rewrite rules:
# 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
于 2012-06-11T14:32:18.993 回答
2

我还建议采用模块方式。

然后,您可以使用 URL 管理器为管理员管理您的 URL。

于 2012-06-13T13:08:20.847 回答
1

您确实需要通过 index.php 引导所有请求。

使用 URL 管理器路由管理员请求。看看这里,http://www.yiiframework.com/doc/guide/1.1/en/topics.url

于 2012-06-12T08:05:09.850 回答
1

我建议你使用 Yii 模块基本概念。因此,管理页面将成为您应用程序中的一个模块。

请看这个链接http://www.yiiframework.com/doc/guide/1.1/en/basics.module

于 2012-06-12T10:45:01.823 回答
0

使用最好的 yii Url Manager,如果后端的所有配置和控制器都不同,那么您可以构建一个名为 AdminController 的控制器。

于 2012-06-12T10:48:01.743 回答