Welcome Guest, Not a member yet? Register   Sign In
Modular Extensions - HMVC version 5.4

[eluser]Keat Liang[/eluser]
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
Code:
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 <<-------
}

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

Code:
/* module singular controller exists? edit dantdr */  
    if(is_file($source.substr($module, 0, -1).$ext)) {
     $segments[0] = substr($module, 0, -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?

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

Code:
&lt;?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

[eluser]shinokada[/eluser]
I read http://ellislab.com/forums/viewthread/92...10/#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.

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

Thanks for your help.

[eluser]Keat Liang[/eluser]
i have new suggestion @wiredesignz !

based on the latest code Loader.php
ORIGINAL

Code:
/** 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
Code:
/** 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://ellislab.com/forums/viewreply/981841/

[eluser]wiredesignz[/eluser]
@Keat Liang,

1.) The two PHP functions give the same result in this context.
Quote:is_a — Checks if the object is of this class or has this class as one of its parents

is_subclass_of — Checks if the object has this class as one of its parents
Visit: http://php.net

2.)
You are free to extend the MX_Router class as you wish. Simply add your code to the empty MY_Router class extension.

[eluser]inc[/eluser]
hi wiredesignz,

thank you for hmvc library. it is really great, but i need your assistance. i have a structure like this:

application/modules/institutions/controllers/admin/*
application/modules/institutions/controllers/member/*
application/modules/organizations/controllers/admin/*
application/modules/organizations/controllers/member/*
application/modules/users/controllers/admin/*
application/modules/users/controllers/member/*

module users wants to display some content of institutions and organizations. so:

echo Module::run('institutions/admin/institutions/get_view');
echo Module::run('organizations/admin/organizations/get_view');

and everything will be fine. but if you have the same controller name in different modules it won't.

echo Module::run('institutions/admin/institutions/get_view');
echo Module::run('organizations/admin/institutions/get_view');

it will display the content of first initiated - in this case institutions. but if you make a hack like this:

echo Module::run('institutions/admin/institutions/get_view');
echo Module::run('organizations/admin/somenameanythingyouwant/get_view');

it will work like supposed to. the problem is with Modules.php file LINE 85:

$alias = strtolower(basename($module));

alias is defined by last "dir" entry. i think the problem would exist even if i don't have such a complex structure, because once loaded controller's class name will always stay in registry even if it comes from a different module.

can you suggest me a workaround please? i will have duplicate controller names in a structure... thank you very much.

[eluser]wiredesignz[/eluser]
This problem has nothing to do with Modular Extensions HMVC.

PHP does not allow objects with duplicate class names to exist in the same namespace.

The workaround is not to have duplicate class names.

[eluser]inc[/eluser]
well yes, i knew that, but don't you think if you're running (not loading for later use) something it should be properly executed without the impact of environment?

this could be done by recognizing from which module a class is requested or you can run something, execute it (some random temp name) and at the end destroy it. this way, run and load will have much more different meaning and use.

the code line i've mentioned makes a name alias with basename function which returns the trailing name of the whole path. so if you have a controller's subdir structure like i have, and obviously i will have admin and member sections in all modules, i cannot run a module like this: (controller name is the same as module_name)

Modules::run('module_name1/subdir/method');
Modules::run('module_name2/subdir/method');

because instance will be named in both cases as 'subdir' which is not true.

[eluser]wiredesignz[/eluser]
[quote author="inc" date="1333579114"]well yes, i knew that, don't you think if you're running (not loading for later use) something it should be properly executed without the impact of environment?

this could be done by recognizing from which module a class is requested or you can run something, execute it (some random temp name) and at the end destroy it. this way, run and load will have much more different meaning and use...[/quote]

You obviously do not understand that while you may be able to destroy objects, you cannot (yet) unload classes.




Theme © iAndrew 2016 - Forum software by © MyBB