Welcome Guest, Not a member yet? Register   Sign In
Nested sub-controller folder/directory AND using a3m marshmallow module PLEASE, NEED HELP!!!
#1

[eluser]boltsabre[/eluser]
Hi guys,

Been trying for hours to be able to use sub directories in my controllers, found lots of information, but couldn't get it to work.
(example solution: http://ellislab.com/forums/viewthread/202176/)

I realised that it's because I'm using the a3m marshmallow module, which is already extending the CI_Router class.

Does anyone know how I can use controller sub-dir's AND a3m marshallow? Sorry if it's a stupid question, I've been up all night working to a deadline I'm having a brain fade (my OOP isn't great) :-(

a3m already has extended the core Router class as such:
Code:
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');
/* load the MX_Router class */
require APPPATH."third_party/MX/Router.php";
class MY_Router extends MX_Router {}

Which is extending upon:
Code:
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');
/* load the MX core module class */
require dirname(__FILE__).'/Modules.php';

class MX_Router extends CI_Router
{
private $module;

public function fetch_module() {
  return $this->module;
}

public function _validate_request($segments) {  
  
  /* locate module controller */
  if ($located = $this->locate($segments)) return $located;
  
  /* use a default 404_override controller */
  if (isset($this->routes['404_override']) AND $segments = explode('/', $this->routes['404_override'])) {
   if ($located = $this->locate($segments)) return $located;
  }
  
  /* no controller found */
  show_404();
}

/** Locate the controller **/
public function locate($segments) {  
  
  $this->module = '';
  $this->directory = '';
  $ext = $this->config->item('controller_suffix').EXT;
  
  /* use module route if available */
  if (isset($segments[0]) AND $routes = Modules::parse_routes($segments[0], implode('/', $segments))) {
   $segments = $routes;
  }

  /* get the segments array elements */
  list($module, $directory, $controller) = array_pad($segments, 3, NULL);

  foreach (Modules::$locations as $location => $offset) {
  
   /* module exists? */
   if (is_dir($source = $location.$module.'/controllers/')) {
    
    $this->module = $module;
    $this->directory = $offset.$module.'/controllers/';
    
    /* module sub-controller exists? */
    if($directory AND is_file($source.$directory.$ext)) {
     return array_slice($segments, 1);
    }
    
    /* module sub-directory exists? */
    if($directory AND is_dir($module_subdir = $source.$directory.'/')) {
      
     $this->directory .= $directory.'/';

     /* module sub-directory controller exists? */
     if(is_file($module_subdir.$directory.$ext)) {
      return array_slice($segments, 1);
     }
    
     /* module sub-directory sub-controller exists? */
     if($controller AND is_file($module_subdir.$controller.$ext)) {
      return array_slice($segments, 2);
     }
    }
  
    /* module controller exists? */  
    if(is_file($source.$module.$ext)) {
     return $segments;
    }
   }
  }
  
  /* application controller exists? */  
  if(is_file(APPPATH.'controllers/'.$module.$ext)) {
   return $segments;
  }
  
  /* application sub-directory controller exists? */
  if(is_file(APPPATH.'controllers/'.$module.'/'.$directory.$ext)) {
   $this->directory = $module.'/';
   return array_slice($segments, 1);
  }
}

public function set_class($class) {
  $this->class = $class.$this->config->item('controller_suffix');
}
}

If anyone has a fix for this I'd be extremely greatful!!!
#2

[eluser]boltsabre[/eluser]
No one...???

I'm pretty sure the problem is with this piece of code:
Code:
/* application sub-directory controller exists? */
  if(is_file(APPPATH.'controllers/'.$module.'/'.$directory.$ext)) {
   $this->directory = $module.'/';
   return array_slice($segments, 1);
  }
}
But I'm not sure on how to change it so that it will accept two levels of folders within the controllers.
#3

[eluser]EC[/eluser]
If you add Modular Extensions to allow HMVC, A3M will drop right in as a module, and you can then use separate MVC modules.

It's very easy to do. Then each controller or module has it's own directories.

Don't know if you are interested in using Modular Extensions, but it does add very nice features.

Hope that helps.

Edmund
#4

[eluser]jakub[/eluser]
Not sure if it helps with your issue, but just an FYI, I've updated the A3M code, latest release (with new fixes + CI update) is called A3M - PB&J (running on CI2.1.2)

https://github.com/pengkong/A3M-for-CodeIgniter-2.0




Theme © iAndrew 2016 - Forum software by © MyBB