Gay*_*ewa 6 php codeigniter hmvc
我有兴趣将离子auth用于我的HMVC模式运行的项目.该应用程序是用Codeigniter编写的.
我面临的问题是,一旦离子auth被放置在/ app/modules/auth文件夹中,当我尝试访问模块时,我得到以下错误:
HTTP错误500(内部服务器错误):
服务器尝试完成请求时遇到意外情况.
请帮帮我,我确信我遇到了某种配置/路径问题但是无法弄清楚在哪里.
我只是从github下载了ion_auth文件并将提取的文件放在模块文件夹中我删除了所有加载库的行,例如数据库,session,因为我已经使用了配置来自动加载它们.但是我离开了ion_auth库的加载.
在模块文件夹modules/auth中,我有一个类似的应用程序结构,具有模块特定的配置,库等文件夹.
让我知道我一定做错了什么,我将继续搜索并解决这个问题并发布如果我有运气的话.
小智 10
试试这个:
在config/routes.php中添加路由: $route['auth/(.*)'] = 'users/auth/$1';
Autoload ion_auth - $autoload['libraries'] = array('database','session','users/ion_auth');
编辑modules/users/library/ion_auth.php中的以下路径:
$this->ci->load->config('users/ion_auth', TRUE);
$this->ci->load->library('email');
$this->ci->load->library('session');
$this->ci->lang->load('users/ion_auth');
$this->ci->load->model('users/ion_auth_model');
Run Code Online (Sandbox Code Playgroud)小智 10
我得到CI 2.1 + Modular Extensions 5.4 + Ion Auth 2全部工作.
既然如此,我没有真正看到关于这个以及我看到的东西的确切信息,有一些像路由和东西这样的东西,我无法按照他们的方式工作,我决定分享我做的事情实现这一目标.
起初我一直在努力,但后来我不得不坐下来思考发生了什么.
在那之后,它实际上非常直接,只有几个陷阱......
安装CodeIgnter(我实际上使用了我正在处理的现有项目,所以它不是一个全新的干净安装.我删除了"index.php",我已经安装了推荐的HMVC方式.无论如何,这是关于Ion Auth.)
获取最新版本的Ion Auth.
而不是安装Ion Auth application/third_party
,解压缩它,并将生成的目录重命名为auth
.把它放在application/modules
哪个结果中application/modules/auth
.
运行Ion Auth的sql来设置表.
在application/config/autoload.php
更新行:
$autoload['libraries'] = array('database','session');
Run Code Online (Sandbox Code Playgroud)在modules/auth/libraries/Ion_auth.php
更新行中__construct
:
$this->ci->load->config('auth/ion_auth', TRUE);
$this->ci->load->library('email');
$this->ci->load->library('session');
$this->ci->lang->load('auth/ion_auth');
$this->ci->load->model('auth/ion_auth_model')
Run Code Online (Sandbox Code Playgroud)在modules/auth/models/ion_auth_model.php
更新行中__construct
:
$this->load->config('auth/ion_auth', TRUE);
$this->load->helper('cookie');
$this->load->helper('date');
$this->load->library('session');
$this->lang->load('auth/ion_auth');
Run Code Online (Sandbox Code Playgroud)将auth
控制器(modules/auth/controllers/auth.php
)更改为扩展MX_Controller
而不是默认值CI_Controller
.
现在, 请确保将auth.php
所有内容更改$this->data
为$data
- (请务必阅读以下内容!).
移动文件和目录modules/auth/views/auth
,以modules/auth/views
导致modules/auth/views
没有下级auth
目录- (请务必阅读关于这个下面!).
将routes.php文件添加到modules/auth/config并添加以下行:
$route['auth/(:any)'] = "auth/$1";
Run Code Online (Sandbox Code Playgroud)现在,去http://yoursite/auth
,一切都应该好!
首先..不要自动将application/config/autoload.php
文件中的图书馆或模型自动化.用明确的方式在模块中做它们$this->load->library("whatever")
等等......
那个人困扰了我很长一段时间.
## Set up mod_rewrite
<IfModule mod_rewrite.c>
Options +MultiViews +FollowSymLinks
DirectoryIndex index.php index.html
# Enable Rewrite Engine
# ------------------------------
RewriteEngine On
# UPDATE THIS TO POINT TO where you installed this FROM YOUR DOC ROOT.
# If this is in the DOC ROOT, leave it as it is
#---------------------
RewriteBase /
# In case your hosting service doesn't add or remove 'www.' for you, you can
# do it here by uncommenting and updating the 'Rewrite*'s below.
#
# Add or remove 'www.' Whichever you prefer.
# This one removes the 'www.' which seems to be the favorable choice these days.
# ------------------------------
#RewriteCond %{HTTP_HOST} ^www.<sitename>.com
#RewriteRule (.*) http://<sitename>.com/$1 [R=301,L]
# Redirect index.php Requests
# ------------------------------
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{THE_REQUEST} !/system/.*
RewriteRule (.*?)index\.php/*(.*) $1$2 [R=301,L]
# Standard ExpressionEngine Rewrite
# ------------------------------
RewriteRule modules/(.+)/controllers/(.+)\.php$ /index.php?/$1/$2 [L,R=301]
RewriteRule controllers/(.+)\.php$ /index.php?/$1 [L,R=301]
RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
=================================
当我更新modules/auth/controllers/auth.php以扩展MX_Controller而不是CI_Controller时,我之后遇到了一系列错误.第一个错误是:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI::$data
Filename: MX/Controller.php
Run Code Online (Sandbox Code Playgroud)
要解决这个错误,我改变了所有$this->data
要$data
在auth.php
controller`.
解决这个问题后,当我去的时候auth
,我会得到这样的错误:
Unable to load the requested file: auth/login.php
Run Code Online (Sandbox Code Playgroud)
显然,它无法在自己的views
目录中找到视图文件.啊.在考虑之后不完全正确.原因是因为它试图找到module/file_to_view
并file_to_view
应该进入views
!不在auth/views/auth
!! 所以,我们需要将每一个从auth
dir 移动到views
dir!
在那之后,一切正常!我可以在其他模块中交叉加载模型,库和控制器,我可以在视图和其他所有内容中执行Modules :: run()!
我希望这有助于其他人.祝好运!