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 - 05-14-2012

[eluser]rose_anne[/eluser]
Hi!, is it possible to have two or more controllers in one module.


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

[eluser]madmuffin[/eluser]
hello, I am supposed to "modularize" an existing project.

current structure is:
Code:
application/
+ controllers/
    + admin.php (extending MY_Controller)
    + user.php  (extending MY_Controller)
+ core/
    + MY_Controller.php (extending CI_Controller)

the new structure should look loke this:
Code:
application/
+ controllers/
    + admin.php (extending MY_Controller)
    + user.php  (extending MY_Controller)
+ core/
    + MY_Controller.php (extending CI_Controller)
+ modules/
    + mod1/
       + controllers/
          + mod1.php (extending MX_Controller)

admin.php should still create the website's design, propagate a list of avaliable modules, give oppurtinity to "enable/disable" them.

Unfortunately, when I try to call

Code:
Modules::run('mod1/mod1/function');

I get an error

Code:
PHP Fatal error:  Class 'Modules' not found in <path>/application/controllers/admin.php on line 50

Must admin.php also extend MX_Controller? I tried that, but that also gave me an error
Code:
PHP Fatal error:  Class 'MX_Controller' not found in ...


I would really appreciate any hints!

(Running CodeIgniter 2.1.0)

madmuffin


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

[eluser]dmyers[/eluser]
I am having some issues with prefixing the controller (routing) and HMVC and hopefully someone can help me figure it out.

I currently have this in my root router.php file

Code:
$route['default_controller'] = "controller_index";

$route['(:any)/(:any)/(:any)/(:any)/(:any)'] = "controller_$1/$2/$3/$4/$5";
$route['(:any)/(:any)/(:any)/(:any)'] = "controller_$1/$2/$3/$4";
$route['(:any)/(:any)/(:any)'] = "controller_$1/$2/$3";
$route['(:any)/(:any)'] = "controller_$1/$2";
$route['(:any)'] = "controller_$1";

This allows me to prefix my controllers with controller_something. This way I can keep a library like "maintenance" and a controller like "controller_maintenance" since you don't normally access controller by name and you access libraries a lot keeping the library name short seemed to be very helpful.

Unfortunately, This seems to be throwing off the HMVC because it can't find the mvc controllers with the base routing in place? is this possible? do I need to add it to the modules router.php file?

Everything with the normal route seems to work pretty good so I seem to have the basic setup right at this point. Things just get wonky when I add my controller prefix stuff.

Anyone know if/how I can do this as I don't want to get rid of the "controller_" naming spacing.

DMyers


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

[eluser]dmyers[/eluser]
I think I found the answer to my own question above. You seem to have a config setting named controller_suffix. By setting controller_suffix in the root config.php file I am able to tell the Modular Extension all of my controller files end in ####

Code:
$config['controller_suffix'] = '_controller';

So I just added the above and it can suffix all my controllers! Which is fine with me! (prefix / suffix who cares!)

Is this "hidden" variable acceptable to use?


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

[eluser]wiredesignz[/eluser]
Yes, That's exactly what the controller suffix is for, although I didn't think it was a "hidden" variable. Wink


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

[eluser]dmyers[/eluser]
[quote author="wiredesignz" date="1338703708"]Yes, That's exactly what the controller suffix is for, although I didn't think it was a "hidden" variable. Wink[/quote]

I figured I could "hack" your code to add it but I noticed that config setting (hum maybe I should look for others...)

Now I don't even need the router stuff!

Either way it is a excellent piece of code! Thank you for all the great work and continued support! :cheese:



Modular Extensions - HMVC version 5.4 - El Forum - 06-06-2012

[eluser]madmuffin[/eluser]
Bumping this question. Any hints on my issue?

[quote author="madmuffin" date="1338650931"]hello, I am supposed to "modularize" an existing project.

current structure is:
Code:
application/
+ controllers/
    + admin.php (extending MY_Controller)
    + user.php  (extending MY_Controller)
+ core/
    + MY_Controller.php (extending CI_Controller)

the new structure should look loke this:
Code:
application/
+ controllers/
    + admin.php (extending MY_Controller)
    + user.php  (extending MY_Controller)
+ core/
    + MY_Controller.php (extending CI_Controller)
+ modules/
    + mod1/
       + controllers/
          + mod1.php (extending MX_Controller)

admin.php should still create the website's design, propagate a list of avaliable modules, give oppurtinity to "enable/disable" them.

Unfortunately, when I try to call

Code:
Modules::run('mod1/mod1/function');

I get an error

Code:
PHP Fatal error:  Class 'Modules' not found in <path>/application/controllers/admin.php on line 50

Must admin.php also extend MX_Controller? I tried that, but that also gave me an error
Code:
PHP Fatal error:  Class 'MX_Controller' not found in ...


I would really appreciate any hints!

(Running CodeIgniter 2.1.0)

madmuffin[/quote]


Modular Extensions - HMVC version 5.4 - El Forum - 06-06-2012

[eluser]wiredesignz[/eluser]
@madmuffin, Your problem has been answered elsewhere in the forums.


Modular Extensions - HMVC version 5.4 - El Forum - 06-14-2012

[eluser]pyweb1[/eluser]
hi,

i am trying to create a module that connect to a different database with a database group and I would like to keep the codeigniter default database config file untouched (the one not in the module)

what I mean?:
Code:
main_codeigniter_folder/application/config/database.php --&gt; should stay untouched

i would like to use the file
Code:
main_codeigniter_folder/application/modules/my_db_module/config/database.php
wich contains:
Code:
$db['my_module_db']['hostname'] = 'localhost';
$db['my_module_db']['username'] = 'root';
$db['my_module_db']['password'] = '';
/.../
$db['my_module_db']['autoinit'] = TRUE;
$db['my_module_db']['stricton'] = FALSE;

So, in the db related model, i use
Code:
class my_db_module_model extends MX_Model{
// This is the main db related class

private $my_module_db = '';

function __construct(){
  parent::__construct();
  $this->my_module_db = $this->load->database('my_module_db', TRUE);
}

function get_all_images_info(){
  $query = $this->my_module_db->get('my_db_table_name');
  return ($query->result_array());
}

sadly, hmvc don't load the modular database.php file and give me an error
Quote:You have specified an invalid database connection group.

So I tried loading the database config file with
Code:
$this->load->config('database');

and:
Quote:Your application/config/database.php file does not appear to contain a valid configuration array.

I tried this:

I rename my database.php to my_module_database.php
and I tried loading the database config file with
Code:
$this->load->config('my_module_database');

and:
Quote:Your application/config/database.php file does not appear to contain a valid configuration array.

so, how do you load a modular database.php config file with hmvc and use a database connection group?


Modular Extensions - HMVC version 5.4 - El Forum - 06-14-2012

[eluser]wiredesignz[/eluser]
Code:
//application/modules/my_module/config/database.php
$config['my_module_db']['hostname'] = 'localhost';
$config['my_module_db']['username'] = 'root';
$config['my_module_db']['password'] = '';
//...
$config['my_module_db']['autoinit'] = TRUE;
$config['my_module_db']['stricton'] = FALSE;

$this->config->load('my_module/database', TRUE);

$my_module_db_params = $this->config->item('my_module_db');

$this->db = $this->load->database($my_module_db_params, TRUE);