使用Ion Auth作为HMVC结构中的单独模块

时间:2011-06-15 04:23:49

标签: php codeigniter hmvc

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

我遇到的问题是一旦离子auth放在/ app / modules / auth文件夹中,当我尝试访问模块时,我得到以下错误:

  

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

请在这里帮助我,我确信我遇到了某种配置/路径问题但是无法弄清楚在哪里。

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

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

让我知道我一定做错了什么,我会继续搜索并解决这个问题并发布,如果我有运气的话。

6 个答案:

答案 0 :(得分: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. Autoload 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');
    

答案 1 :(得分:10)

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

因为,我没有真正看到任何关于这个和我看到的东西的确切信息,有一些像路由和东西,我不能按照他们的方式工作,我决定分享我做了什么来实现这一目标。

起初我一直在努力,但后来我不得不坐下来思考发生了什么。

在那之后,它实际上非常直接,只有几个陷阱......

我采取的步骤让ION AUTH使用CodeIgniter + MX HMVC

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

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

  3. 而不是在application/third_party中安装Ion Auth,解压缩,并将生成的目录重命名为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/views没有更低级auth目录 - (请务必阅读以下内容! !)。

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

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

  13. 陷阱

    首先关闭..不要在application/config/autoload.php文件中自动删除图书馆或模型。使用$this->load->library("whatever")等明确地在模块中执行这些操作......

    那个人困扰了我一段时间。

    我忘了提到在我当前的安装中,我已经从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控制器中的所有$data更改为auth.php

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

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

    显然,它无法在自己的views目录中找到视图文件。啊。在考虑之后不完全正确。原因是因为它试图找到module/file_to_viewfile_to_view应该在views中!不在auth/views/auth !!所以,我们需要将auth dir的每一个向上移动到views目录!

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

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

答案 2 :(得分:1)

我认为没有任何理由不起作用。 看看pyrocms

他们正在使用ionauth和hmvc。

如果你没有让它工作, 只需将文件上传到普通的ci目录中,然后检查它是否正常工作。

答案 3 :(得分: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文件夹:config,controllers,language,libraries,models。
        将Ion Auth / views文件夹下的文件移动到CI / application / modules / auth / views。 (没有一个额外的auth层     如Ion Auth。)     在数据库中运行Ion Auth sql。
  4. 在yourbaseurl / index.php / auth。
  5. 上查看

答案 4 :(得分: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!

"

答案 5 :(得分:0)

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