Part of the EllisLab Network
   
23 of 25
23
Modular Extensions - HMVC version 5.4
Posted: 07 February 2012 12:14 PM   [ Ignore ]   [ # 221 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  3216
Joined  06-10-2007

@osci, Try this:

$db1 $this->load->database($db_groupTRUE);
 
$this->load->dbutil();

$this->dbutil->db =& $db1;

$backup =& $this->dbutil->backup(); 
 Signature 

URI Language Identifier | Modular Extensions - HMVC | View Object | Widget plugin | Access Control library

Profile
 
 
Posted: 07 February 2012 02:03 PM   [ Ignore ]   [ # 222 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  439
Joined  01-31-2011

This correctly sets the db to the desired one. Thx for the tip.

I also tried

$db1 $this->load->database($db_group

which should set the app db to the one loaded

if ($return === TRUE) return DB($params$active_record);
CI::$APP->db DB($params$active_record);
return 
CI::$APP->db

but it returned wrong db again. Is this program related to DB class or MX Loader?

 Signature 

Lang uri library - Web Coders Blog (coming… not so…. soon)

Profile
 
 
Posted: 07 February 2012 02:40 PM   [ Ignore ]   [ # 223 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  3216
Joined  06-10-2007

Once a database group is loaded it cannot be changed to another group by calling $this->load->database($db_group) again. This is part of the CI logic in the database loader method.

if (class_exists('CI_DB') AND $return == FALSE AND $active_record == NULL AND isset($CI->db) AND is_object($CI->db))

    
return FALSE;

MX_Loader merely duplicates this method but uses the $CI super object differently when assigning the $db class variable to it.

 

 Signature 

URI Language Identifier | Modular Extensions - HMVC | View Object | Widget plugin | Access Control library

Profile
 
 
Posted: 11 February 2012 03:59 PM   [ Ignore ]   [ # 224 ]  
Grad Student
Rank
Total Posts:  46
Joined  09-21-2009

Hi wiredesignz,

Is it correct that loading modules in views does not work if modules controllers contain the same file / class name?
I have the following routes active and are the reason why controllers share the same name in each module:

$route['(\w{2})/cms/([a-zA-Z_-]+)/(:any)''$2/back_end/$3';
$route['(\w{2})/cms/([a-zA-Z_-]+)''$2/back_end/index';
$route['(\w{2})/cms''back_end'

File structure application/modules:

/slider/controllers/slider.php
/slider/controllers/back_end.php

/products/controllers/products.php
/products/controllers/back_end.php

Now this will fail (returns nothing):

<?php echo modules::run('slider/back_end/somemethod'); ?> 

If I move the method to the unique named slider controller and try:

<?php echo modules::run('slider/slider/somemethod'); ?> 

or

<?php echo modules::run('slider/somemethod'); ?> 

It works fine. Do you know how to solve this?

Thanks!

Profile
 
 
Posted: 21 February 2012 08:09 AM   [ Ignore ]   [ # 225 ]  
Summer Student
Avatar
Total Posts:  29
Joined  09-12-2008

hey wiredesignz,

i kind of bumped into a problem, i am using MX in building a kind of economic application, but i want to be able to let other programmers to develop other modules(plugins) to extend the core modules.

for example: i have the “clients” module that has 3 tabs with informations, and with a module(plugin) i want to add a 4th tab (jquery tabs) how can i do that?

in theory i have the core functionality and view, and i have to somehow extend them to add another tab and functionality for that tab.

<div id="tabs">
 <
ul>
  <
li><a href="#tabs-1"><?php echo lang('client_general_info');?></a></li>
  <
li><a href="#tabs-2"><?php echo lang('client_bank_info');?></a></li>
  <
li><a href="#tabs-3"><?php echo lang('client_contact_person_info');?></a></li>
 </
ul>
 <
div id="tabs-1">
  <
fieldset>
   <
section>
   <
label class="title"><?php echo lang('client_general_info');?></label>
   </
section>
   <
section>
             <
label for="cif"><?php echo lang('client_cif_label');?></label>  
             <
div>
     
<?php echo form_input(array('name'=>'cif''id'=>'text_placeholder''title'=> 'ex: RO17068477''value'=>'''required' => 'required''placeholder'=>'ex: RO17068477')); ?>
                
</div>
            </
section>
    </
fieldset>
 </
div>
 <
div id="tabs-2">
  <
fieldset>
   <
section class="b">
   <
label class="title"><?php echo lang('client_bank_info');?></label>
  </
section>
  <
section>
 </
fieldset>
 </
div>
 <
div id="tabs-3">
 <
fieldset>
  <
section class="cp">
   <
label class="title"><?php echo lang('client_contact_person_info');?></label>
  </
section
 </
fieldset>
 </
div>
</
div

here is a sample of my view file.

 

 Signature 

Portfolio: Daniel Toader

Profile
 
 
Posted: 22 February 2012 08:58 PM   [ Ignore ]   [ # 226 ]  
Summer Student
Total Posts:  28
Joined  11-16-2010

Hi, wiredesignz i made some improvement on this function

when routing error, or invalid URL, it will actually show the URL in the log file which may
be very useful.

hope you can add this in…

on third_party/MX/Router.php

public function _validate_request($segments{

  
if (count($segments) == 0) return $segments;
  
  
/* locate module controller */
  
if ($located $this->locate($segments)) return $located;
  
  
/* use a default 404_override controller */
  
if (isset($this->routes['404_override']) AND $this->routes['404_override']{
   $segments 
explode('/'$this->routes['404_override']);
   if (
$located $this->locate($segments)) return $located;
  
}
  
  
/* no controller found */
  
show_404(implode('/'$segments)); //little enhancement here <<-------
 
Profile
 
 
Posted: 23 February 2012 08:19 AM   [ Ignore ]   [ # 227 ]  
Summer Student
Avatar
Total Posts:  29
Joined  09-12-2008

Hello, i had a problem and needed to load by default a controller with a different name than the module.
All my modules had plural names (modules, clients, projects, examples), i was using gas orm and i had the same table names (plural) as module names and gas orm needed to have the module class the same as the database tables, so if i wanted to have a controller called clients in my clients module it would get in conflict with the clients model. So i wanted to be able to load a different controller by default, i thought that a simple takedown of this problem would be to make it so the modules keep their plural names and the controllers to be put at singular. I did not change the default functionality if you would have a module projects, with a controller projects it would load it by default even if you had another controller project, but, if you had a module projects and a controller project, with the code below, it would first search for the controller with the same name as the module and if not found, it would search for the singular name controller and load it ( so that you would not have to type projects/project to access it, or use routes for every module you have)

the code is:
on third_party/MX/Router.php or libraries/MX/Router.php under line 122 add

/* module singular controller exists? edit dantdr */   
    
if(is_file($source.substr($module0, -1).$ext){
     $segments[0] 
substr($module0, -1);
     return 
$segments;
     
    

this makes it work, but is there a better way to do this? and if it is, could it be added to the next version of Modular Extension?

 Signature 

Portfolio: Daniel Toader

Profile
 
 
Posted: 14 March 2012 03:10 PM   [ Ignore ]   [ # 228 ]  
Summer Student
Total Posts:  15
Joined  12-30-2011

First of all thanks for all your work.

Second I would like to know if I’m actually understanding this correctly how to work with HMVC.

Lets say I have ion auth, and I’m using this in my CMS module:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Cms extends MX_Controller {
 
 
public function __construct()
 
{
  $this
->load->module('auth'); // loading auth. module
 
}
 
 
public function index()
 
{
  
if ($this->ion_auth->logged_in()) // check if you are logged in
  
{
   
echo "you are logged in";
  
}
  
else 
  
{
   
echo "you are not logged in";
  
}
 }

Am I actually using HMVC the correct way at this point?

Thanks

Profile
 
 
Posted: 14 March 2012 05:40 PM   [ Ignore ]   [ # 229 ]  
Lab Assistant
RankRank
Total Posts:  245
Joined  09-20-2009

I read http://codeigniter.com/forums/viewthread/92212/P510/#969568 how to use form_validation in a controller. But how can I use it in a library? It seems not working with the following.

class Auth_form_processing
{
    
public $CI;
    
 function 
__construct()
 
{
      $this
->CI->load->library('form_validation');
      
$this->form_validation->CI =& $this;
        ....
 

Thanks for your help.

 Signature 

Kaimono Kago Daikon Portfolio CMS | Event Calendar

Profile
 
 
Posted: 23 March 2012 04:29 AM   [ Ignore ]   [ # 230 ]  
Summer Student
Total Posts:  28
Joined  11-16-2010

i have new suggestion @wiredesignz !

based on the latest code Loader.php
ORIGINAL

/** Initialize the loader variables **/
 
public function initialize($controller NULL{
  
  
if (is_a($controller'MX_Controller')) 
   
   
/* reference to the module controller */
   
$this->controller $controller;
   
   
/* references to ci loader variables */
   
foreach (get_class_vars('CI_Loader') as $var => $val{
    
if ($var != '_ci_ob_level'{
     $this
->$var =& CI::$APP->load->$var;
    
}
   }
   
  } 
else {
   parent
::initialize();
  
}

  
/* set the module name */
  
$this->_module CI::$APP->router->fetch_module();
  
  
/* add this module path to the loader variables */
  
$this->_add_module_paths($this->_module);
 

change to this

/** Initialize the loader variables **/
 
public function initialize($controller NULL{
  
  
if (is_subclass_of($controller'MX_Controller')) // in case there is exteded controller like mine
   
   /* reference to the module controller */
   
$this->controller $controller;
   
   
/* references to ci loader variables */
   
foreach (get_class_vars('CI_Loader') as $var => $val{
    
if ($var != '_ci_ob_level'{
     $this
->$var =& CI::$APP->load->$var;
    
}
   }
   
  } 
else {
   parent
::initialize();
  
}

  
/* set the module name */
  
$this->_module CI::$APP->router->fetch_module();
  
  
/* add this module path to the loader variables */
  
$this->_add_module_paths($this->_module);
 

and also check it out another enhancement i suggest
http://codeigniter.com/forums/viewreply/981841/

Profile
 
 
   
23 of 25
23