Using Ion Auth as a standalone module in an HMVC framework

I'm interested in using ion auth for my project, which works on the HMVC pattern. The application is written in Codeigniter.

The problem I am facing is when ionic auth is placed in the / app / modules / auth folder, when I try to access the module, I get the following error:

HTTP Error 500 (Internal Server Error) :
An unexpected condition occurred when the server tried to execute the request.

Please help me here, I'm sure I have some kind of configuration / path problem, but I just can't figure out where.

I just downloaded the ion_auth files from github and placed the extracted files as they are in the module folder, I deleted all the lines where it loads the libraries, such as the database, session, since I used the configuration for automatic loading. But I left loading the ion_auth library.

In modules of modules / auth modules, I have a similar application structure with configuration folders, libraries, etc., corresponding to the module.

Let me know where I must have made a mistake, I will continue to search and fix this problem and send it if I'm lucky.

+6
source share
6 answers

Try the following:

  • Get: codeigniter.zip (CI2.0)
  • Extract, make sure it is running, set config / config.php
  • Get Modular Extension: HMVC
  • Install - copy MY_Loader and MY_Router to / core, MX in a third-party folder. Do not copy MY_Controller - this is for modular separation, not for extensions.
  • Get Ion_auth
  • Install SQL for Ion_auth
  • Put Ion_auth in the modules / application / modules / users folder
  • Add route to config / routes.php: $route['auth/(.*)'] = 'users/auth/$1';

  • Autostart ion_auth - $autoload['libraries'] = array('database','session','users/ion_auth');

  • Change the following paths in the / users / library / ion _auth.php modules:

     $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'); 
+9
source

I got CI 2.1 + Modular Extensions 5.4 + Ion Auth 2, all working.

Since I did not see any specific information about this and the materials that I saw, had a bunch of things, such as routing and stuff, that I could not work the way they were done, I decided to share what I did for this.

At first I struggled with this, but then I had to sit back and think about what was happening.

After that, in fact, it was pretty straightforward, only a couple of mistakes ...

The steps I took to get ION AUTH to work with CodeIgniter + MX HMVC

  • Install CodeIgnter (I actually used an existing project that I was working on, so it wasnโ€™t a clean clean install. I uninstalled โ€œindex.phpโ€ and HMVC already installed the recommended method. Ion Auth anyway.)

  • Get the latest version of Ion Auth.

  • Instead of setting Ion Auth to application/third_party , unzip it and rename the resulting directory to auth . Put it in application/modules , which will lead to application/modules/auth .

  • Run Ion Auth sql to configure the tables.

  • In application/config/autoload.php update the line to:

     $autoload['libraries'] = array('database','session'); 
  • In modules/auth/libraries/Ion_auth.php update the lines in __construct to:

     $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') 
  • In modules/auth/models/ion_auth_model.php update the lines in __construct to:

     $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'); 
  • Modify the auth controller ( modules/auth/controllers/auth.php ) to extend MX_Controller instead of the standard CI_Controller .

  • Now, in auth.php , make sure you change all $this->data to $data - (be sure to read about it below!).

  • Move the files and directories in modules/auth/views/auth to modules/auth/views , which will lead to modules/auth/views without the bottom level auth dir - (be sure to read about it below!).

  • Add the route.php file to modules / auth / config and add the following line:

     $route['auth/(:any)'] = "auth/$1"; 
  • Now go to http://yoursite/auth and everything should be fine!

Gotchas

First, do not use AUTOLOAD LIBRARIES OR MODELS in the file application/config/autoload.php . Make them explicit in the modules using $this->load->library("whatever") , etc.

It delayed me a bit.

I forgot to mention that in my current installation I already deleted index.php from the url and I have a .htaccess file in my installation database. If something doesn't work, maybe something with RewriteBase is here. This .htaccess I use:

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

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

When I updated the modules /auth/controllers/auth.php to extend the MX_Controller instead of CI_Controller, after that I got a number of errors. The first of these errors:

  A PHP Error was encountered Severity: Notice Message: Undefined property: CI::$data Filename: MX/Controller.php 

To fix this error, I changed all $this->data to $data in the auth.php controller.

After fixing this problem, when I go to auth , I get this error:

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

Apparently, he cannot find the view files in his own views directory. Ahh. Not quite right, though thinking about it. The reason is that the search for module/file_to_view and file_to_view should be in views ! Not in auth/views/auth !! So, we need to move all the values โ€‹โ€‹from auth dir to the views directory!

After that, everything works fine! I can overload models, libraries, and controllers in other modules, and I can execute Modules :: run () in views and everything else!

Hope this helps someone else. Good luck

+10
source

I see no reason for it not to work. check pyrocms

They use ionauth with hmvc.

if you donโ€™t get it working, just upload the files to regular ci directories and check if this works.

+1
source

This is what I did as ciuser recommended, but with some changes:

  • Make a clean installation of Codeigniter. Configure config.php, database.php, etc.
  • Install modular extension:
    Move third_party / MX to CI / application / third_party.
    Move the core /MY_Loader.php and core / MY_Router.php to CI / application / core.
  • Install Ion Auth:
    Move the following Ion Auth folders to the CI / application / modules / auth folder: config, controllers, language, libraries, models.
    Move the files in the Ion Auth / views folder to CI / application / modules / auth / views. (Without one extra auth level as in Ion Auth.)
    Run Ion Auth sql in the database.
  • Check it in yourbaseurl / index.php / auth file.
+1
source

I wrote a bash script to get and install CodeIgniter 2 + Modular Extensions 5.4 + Ion Auth 2.

There he is. Good luck and let me know if any problems arise.

 #! /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* 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! " 
+1
source

The solutions given by @ciuser and @Dash worked for me, but the automatic loading of ion_auth is not related to language files. Therefore, I saved the contents of the language folder in the application / language folder and remained as a module that works like a charm.

0
source

Source: https://habr.com/ru/post/890570/


All Articles