CodeIgniter Forums
Modular Extensions - HMVC version 5.4 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Modular Extensions - HMVC version 5.4 (/showthread.php?tid=38057)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24


Modular Extensions - HMVC version 5.4 - El Forum - 01-25-2012

[eluser]ericrjones1[/eluser]
:red: Fail.

You are right. I didn't notice that you had set the visibility to public.


Modular Extensions - HMVC version 5.4 - El Forum - 01-26-2012

[eluser]ericrjones1[/eluser]
@wiredesignz: Being the smug developer that I am, I followed your solution provided with one exception. I used the following:

Code:
$this->form_validation->CI = $this;

Based upon my PHP version information, I would have assumed that $this would be passed by reference since $this is referring to my controller ( an object - in PHP 5 all objects are passed by reference automatically, right? ).

Code:
$ php -v
PHP 5.3.8 (cli) (built: Sep 28 2011 17:34:36)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
    with Xdebug v2.1.2, Copyright (c) 2002-2011, by Derick Rethans

However, when using the form_validation_helper function validation_errors the conditional statement on line 1054 says that the $CI->form_validation object isn't set even though the $CI->load->is_loaded('form_validation') returns 'form_validation';

Dumping the $CI object, I can see the following loaded classes, but no form_validation object.

Code:
protected '_ci_classes' => &
        array
          'session' => string 'session' (length=7)
          'encrypt' => string 'encrypt' (length=7)
          'form_validation' => string 'form_validation' (length=15)

So the gist is:
Code:
// Doesn't work ( mine )
$this->form_validation->CI = $this;

// Works ( yours )
$this->form_validation->CI =& $this;

I feel like I am totally missing something. If you can, will you please explain to me why my code doesn't work.

Thanks for all your help.


Modular Extensions - HMVC version 5.4 - El Forum - 01-27-2012

[eluser]PhilTem[/eluser]
It won't be passed by reference as long as you use = since = is an assign-operator nothing more.
= doesn't create a pointer but creates a copy. Other than get_instance() does, since this returns a static variable (have a look at the code).

So you really need to do
Code:
$this->form_valdiation->CI =& $this;

to assign it by reference rather than pass by reference (pass by reference basically only works for functions, not assignments Wink )

The & is the reference symbol.


Modular Extensions - HMVC version 5.4 - El Forum - 02-03-2012

[eluser]Philo01[/eluser]
Hi WireDesignz,

I was wondering if you know why the following code is returning "GO" on the main controller, but returns "FAIL" for each module loaded via modules::run inside the views?

third_party/MX/Loader.php

Code:
class MX_Controller
{
public $autoload = array();

public function __construct()
{
  $class = str_replace(CI::$APP->config->item('controller_suffix'), '', get_class($this));
  log_message('debug', $class." MX_Controller Initialized");
  Modules::$registry[strtolower($class)] = $this;
  
  /* copy a loader instance and initialize */
  $this->load = clone load_class('Loader');
  $this->load->_init($this);
  
  /* autoload module items */
  $this->load->_autoloader($this->autoload);

  $this->data = new stdClass;

  // Global information
  $this->data->assets_url = base_url('assets');
  $this->data->title = '';
  $this->data->db = @unserialize($this->session->userdata('db'));

  if(!empty($this->data->db))
  {
   $db_connection = $this->load->database($this->data->db);
   if($db_connection)
   {
    echo 'GO';
   }
   else
   {
    echo 'FAIL';
   }
  }
}

public function __get($class) {

  return CI::$APP->$class;
}
}

Thanks! Smile


Modular Extensions - HMVC version 5.4 - El Forum - 02-07-2012

[eluser]osci[/eluser]
I was trying to make a module for db backup using dbutil.
When in MX controller
Code:
$db1 = $this->load->database($db_group,TRUE);
$this->db = $db1;
$this->load->dbutil();
$backup =& $this->dbutil->backup();
the backup contains the first loaded db, while when in a normal CI Controller it correctly gives backup for the selected group

When I do $this->load->dbutil() in mysql_utility.php in dbutil() $CI =& get_instance(); gives me the db which was autoloaded (from autoload)

Any ideas?


Modular Extensions - HMVC version 5.4 - El Forum - 02-07-2012

[eluser]wiredesignz[/eluser]
@osci, Try this:
Code:
$db1 = $this->load->database($db_group, TRUE);

$this->load->dbutil();

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

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



Modular Extensions - HMVC version 5.4 - El Forum - 02-07-2012

[eluser]osci[/eluser]
This correctly sets the db to the desired one. Thx for the tip.

I also tried
Code:
$db1 = $this->load->database($db_group)
which should set the app db to the one loaded
Code:
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?


Modular Extensions - HMVC version 5.4 - El Forum - 02-07-2012

[eluser]wiredesignz[/eluser]
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.
Code:
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.





Modular Extensions - HMVC version 5.4 - El Forum - 02-11-2012

[eluser]Philo01[/eluser]
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:

Code:
$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):
Code:
<?php echo modules::run('slider/back_end/somemethod'); ?>

If I move the method to the unique named slider controller and try:
Code:
<?php echo modules::run('slider/slider/somemethod'); ?>
or
Code:
<?php echo modules::run('slider/somemethod'); ?>

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

Thanks!


Modular Extensions - HMVC version 5.4 - El Forum - 02-21-2012

[eluser]Dan Tdr[/eluser]
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.

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

here is a sample of my view file.