6

我有兴趣将 ion auth 用于我在 HMVC 模式上运行的项目。该应用程序是用 Codeigniter 编写的。

我面临的问题是,一旦将 ion auth 放置在 /app/modules/auth 文件夹中,当我尝试访问该模块时,我会收到以下错误:

HTTP 错误 500(内部服务器错误)
服务器尝试完成请求时遇到了意外情况。

请在这里帮助我,我确定我遇到了某种配置/路径问题,但就是不知道在哪里。

我只是从 github 下载了 ion_auth 文件,并将提取的文件原样放在模块文件夹中。我删除了加载数据库、会话等库的所有行,因为我使用了配置来自动加载它们。但是我离开了 ion_auth 库的加载。

在模块文件夹 modules/auth 中,我有一个与模块特定配置、库等文件夹类似的应用程序结构。

让我知道我在哪里做错了,如果我有任何运气,我将继续搜索并修复此问题并发布。

4

6 回答 6

10

试试这个:

  1. 获取:codeigniter.zip (CI2.0)
  2. 解压,确保它正在运行,设置 config/config.php
  3. 获取模块化扩展:HMVC
  4. 安装 - 将 MY_Loader 和 MY_Router 复制到 /core,将 MX 复制到第三方文件夹 不要复制 MY_Controller - 这是用于模块化分离而不是扩展
  5. 获取Ion_auth
  6. 安装 Ion_auth 的 SQL
  7. 将 Ion_auth 放入模块文件夹 /application/modules/users
  8. 在 config/routes.php 中添加路由: $route['auth/(.*)'] = 'users/auth/$1';

  9. 自动加载 ion_auth -$autoload['libraries'] = array('database','session','users/ion_auth');

  10. 在 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');
    
于 2011-08-09T21:22:14.180 回答
10

我得到了 CI 2.1 + Modular Extensions 5.4 + Ion Auth 2 全部工作。

因为,我并没有真正看到任何关于这方面的确切信息,而且我确实看到了很多东西,比如路由和我无法按照他们的方式工作的东西,我决定分享我所做的来实现这一点。

起初我很挣扎,但后来我不得不坐下来想想发生了什么。

在那之后,它实际上非常简单,只有几个问题......</p>

我为使 ION AUTH 与 CodeIgniter + MX HMVC 一起工作而采取的步骤

  1. 安装 CodeIgnter(我实际上使用了一个我正在处理的现有项目,所以它不是全新的安装。我删除了“index.php”并且我已经按照推荐的方式安装了 HMVC。无论如何这都是关于 Ion Auth 的。)

  2. 获取最新版本的 Ion Auth。

  3. 不要在 中安装 Ion Auth application/third_party,而是解压缩它,然后将生成的目录重命名为auth. 把它放在application/modules结果中application/modules/auth

  4. 运行 Ion Auth 的 sql 来设置表。

  5. 将行更新为application/config/autoload.php

    $autoload['libraries'] = array('database','session');
    
  6. 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')
    
  7. 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');
    
  8. auth将控制器 ( )更改modules/auth/controllers/auth.php为扩展MX_Controller而不是默认值CI_Controller

  9. 现在,在 中auth.php,确保将所有内容更改$this->data$data - (请务必阅读下面的内容!!)。

  10. 将文件和目录移动modules/auth/views/auth到没有较低级别modules/auth/views的目录 - (请务必阅读下面的内容!!)。modules/auth/viewsauth

  11. 将 routes.php 文件添加到 modules/auth/config 并添加以下行:

    $route['auth/(:any)'] = "auth/$1";
    
  12. 现在,去http://yoursite/auth,一切都应该很好去!

陷阱

首先.. 不要自动application/config/autoload.php加载文件中的库或模型。用 等在模块中明确地执行它们$this->load->library("whatever")......</p>

那句话难倒了我好一阵子。

我忘了提到,在我当前的安装中,我已经从 URL 中删除了 index.php,并且在我的安装基础中有一个 .htaccess 文件。如果事情不起作用,可能是这里的 RewriteBase 的问题。这是我使用的 .htaccess:

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

==================================

当我更新 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

为了解决此错误,我将所有内容更改$this->data$dataauth.php控制器中。

解决此问题后,当我转到 时auth,我会收到如下错误:

Unable to load the requested file: auth/login.php

views显然,它在自己的目录中找不到视图文件。啊。不过仔细想想也不完全对。原因是因为它试图找到module/file_to_view并且file_to_view应该在views!不在auth/views/auth!!因此,我们需要将所有内容从auth目录中移到views目录中!

之后,一切正常!我可以在其他模块中交叉加载模型、库和控制器,并且可以在视图和其他所有内容中执行 Modules::run()!

我希望这对其他人有帮助。祝你好运!

于 2011-12-24T21:01:37.413 回答
1

我看不出它有任何不工作的理由。检查pyrocms

他们将 ionauth 与 hmvc 一起使用。

如果你不让它工作,只需将文件上传到正常的 ci 目录并检查它是否可以正常工作。

于 2011-06-15T05:52:13.060 回答
1

这是我按照 ciuser 的指南所做的,但有一些变化:

  1. 全新安装 Codeigniter。设置 config.php、database.php 等。
  2. 安装模块化扩展:
    将third_party/MX 移动到CI/application/third_party。
    将 core/MY_Loader.php 和 core/MY_Router.php 移动到 CI/application/core。
  3. 安装 Ion Auth:
    将以下 Ion Auth 文件夹移动到 CI/application/modules/auth 文件夹:配置、控制器、语言、库、模型。
    将 Ion Auth/views 文件夹下的文件移动到 CI/application/modules/auth/views。(没有像 Ion Auth 中那样的额外的 auth 层。)
    在数据库中运行 Ion Auth sql。
  4. 在 yourbaseurl/index.php/auth 检查它。
于 2011-10-29T17:15:32.273 回答
1

我编写了一个 bash 脚本来获取和安装 CodeIgniter 2 + Modular Extensions 5.4 + Ion Auth 2。

这里是。祝你好运,如果有任何问题,请告诉我。

#! /bin/bash

echo "

This will install Codeigniter 2, Modular Extensions 5.4 and Ion Auth 2!

This script will TRY to download the packages for you.
-----------------------------------------------------
The resulting CodeIgniter install is already configured to remove the index.php
from the URL and should ALMOST be ready to run!  Make sure to read the
steps at the end of this.


Good luck..


Hit a key to continue or Ctrl-c to cancel now."


read

## Download the files
echo "Get CodeIgniter"
wget -O CodeIgniter.zip http://codeigniter.com/download.php

echo "Get Ion Auth"
wget --no-check-certificate -O benedmunds-ion-auth.zip https://github.com/benedmunds/CodeIgniter-Ion-Auth/zipball/2

echo "Get Modular Extensions"
wget --no-check-certificate -O wiredesignz.zip https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/get/tip.zip

## Unpack all the files
echo "Unpack Files"
unzip CodeIgniter.zip
rm CodeIgniter.zip
unzip benedmunds-ion-auth.zip
rm benedmunds-ion-auth.zip
unzip wiredesignz.zip
rm wiredesignz.zip

## Get the Dirs
echo "Find Dirs"
CI_DIR=`ls -c1 | grep ^CodeIgniter_`
ME_DIR=`ls -c1 | grep ^wired`
IA_DIR=`ls -c1 | grep ^ben`

## Make Modules Dir
echo "Make Modules Dir"
mkdir $CI_DIR/application/modules

## Move the Modular Extensions Files Into Place
echo "Move Modular Extensions files"
mv $ME_DIR/third_party/MX $CI_DIR/application/third_party
mv $ME_DIR/core/* $CI_DIR/application/core/

## Remove the Modular Extension Dir
echo "Remove ME Install Dir"
rm -rf $ME_DIR

## Make Welcome Module Dir
echo "Make Modular Welcome Dir"
mkdir -p $CI_DIR/application/modules/welcome/controllers

## Move default welcome controller to the modules dir
echo "Move Welcome Controller into Modules"
mv $CI_DIR/application/controllers/welcome.php $CI_DIR/application/modules/welcome/controllers/


## Make Welcome Views Dir
echo "Make Welcome Views Dir"
mkdir -p $CI_DIR/application/modules/welcome/views

## Move Welcome View into modular dir
echo "Move Welcome views into modular Welcome Dir"
mv $CI_DIR/application/views/welcome_message.php $CI_DIR/application/modules/welcome/views/

## Rename Ion Auths Dir to Auth
echo "Rename Ion Auth Dir to Auth"
mv $IA_DIR $CI_DIR/application/modules/auth

## Update the Welcome Controller to extend MX_Controller instead of CI_Controller
echo "Update Welcome Controller to extend MX_Controller"
sed -i -e "s/CI_Controller/MX_Controller/" $CI_DIR/application/modules/welcome/controllers/welcome.php

## Update the default autoload file to include database and session libraries
echo "Update autoload file to include the database and session libraries"
sed -i -e "s/\$autoload\['libraries'] = array()/\$autoload['libraries'] = array('database','session')/" $CI_DIR/application/config/autoload.php

## Update the config file to remove index.php
echo "Update config file to remove index.php"
sed -i -e "s/\$config\['index_page'] = 'index.php';/\$config['index_page'] = '';/" $CI_DIR/application/config/config.php

## Update the Ion Auth libraries to use the auth resource
echo "Update Ion Auth Lib to use the Auth Resources"
sed -i -e "s/\$this->ci->load->config('ion_auth', TRUE);/\$this->ci->load->config('auth\/ion_auth', TRUE);/" $CI_DIR/application/modules/auth/libraries/Ion_auth.php
sed -i -e "s/\$this->ci->lang->load('ion_auth');/\$this->ci->lang->load('auth\/ion_auth');/" $CI_DIR/application/modules/auth/libraries/Ion_auth.php
sed -i -e "s/\$this->ci->load->model('ion_auth_model');/\$this->ci->load->model('auth\/ion_auth_model');/" $CI_DIR/application/modules/auth/libraries/Ion_auth.php

## Update the Ion Auth model to use the auth resource
echo "Update the Ion Auth Model to use the Auth Resources"
sed -i -e "s/\$this->load->config('ion_auth', TRUE);/\$this->load->config('auth\/ion_auth', TRUE);/" $CI_DIR/application/modules/auth/models/ion_auth_model.php
sed -i -e "s/\$this->lang->load('ion_auth')/\$this->lang->load('auth\/ion_auth')/" $CI_DIR/application/modules/auth/models/ion_auth_model.php

## Update the Auth Controller to extend MX_Controller instead of CI_Controller
echo "Update Auth Controller to extend MX_Controller"
sed -i -e "s/CI_Controller/MX_Controller/" $CI_DIR/application/modules/auth/controllers/auth.php

## Update the Auth Controller so "$this->data" will be "$data"
echo "Update the Auth Controller to change \$this->data to \$data"
sed -i -e "s/\$this->data/\$data/" $CI_DIR/application/modules/auth/controllers/auth.php

## Move auth/views files up 1 level
echo "Move auth/views files up 1 level"
mv $CI_DIR/application/modules/auth/views/auth/* $CI_DIR/application/modules/auth/views/

## Remove the auth/views/auth dir
echo "Remove the auth/views/auth dir"
rmdir $CI_DIR/application/modules/auth/views/auth

## Make the routes.php file
echo "Write the modules/auth/config/routes.php file"
echo "<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------------
| URI ROUTING
| -------------------------------------------------------------------------
*/

\$route['auth/(:any)'] = \"auth/\$1\";

/* End of file routes.php */
/* Location: ./application/config/routes.php */


" > $CI_DIR/application/modules/auth/config/routes.php

echo "Creating the $CI_DIR/.htaccess file"
echo "## 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>" > $CI_DIR/.htaccess

echo "

*********** DON'T FORGET THESE STEPS ***********
====================================================================

6 more steps:
==================
1) Update the \$config['base_url'] var in application/config/config.php
2) Update the \$config['encryption_key'] var in application/config/config.php
3) Update your application/config/database.php file to work with your database,
4) Run the Ion Auth SQL file located in application/modules/auth/sql.
5) Now rename or move everything from $CI_DIR into where you set \$config['base_url']

If you put your CodeIgniter files anywhere other than DOC ROOT you need to do step 6:
6)Update the 'RewriteBase' in the .htaccess file in your CodeIgniter Directory to where your CodeIgniter files are.

If your CodeIgniter files ARE IN the DOC ROOT of your webserver, you should be able to run from there like this:
---------------
yourdomain.com
yourdomain.com/auth


If your CodeIgniter files AREN'T IN the DOC ROOT:
Remember to update the RewriteBase to point to "your_ci_dir" (see below) in the .htaccess file and you should be able to run like this:
--------------------------
yourdomain.com/your_ci_dir
yourdomain.com/your_ci_dir/auth

====================================================================
    YOU SHOULD BE DONE AFTER FOLLOWING THOSE STEPS!

I think you should be up and running!


Hope this all works!


Please let me know if this worked for you or not!
Edmund - edmundchaniii AT gmail.com

C'ya!

"
于 2012-01-05T01:09:23.050 回答
0

@ciuser 和 @Dash 给出的解决方案对我有用,但自动加载 ion_auth 并不是因为语言文件。所以我将语言文件夹的内容保存在应用程序/语言文件夹中,并作为一个像魅力一样工作的模块。

于 2013-07-14T12:26:37.700 回答