Codeigniter HMVC bug ? |
[eluser]r4f[/eluser]
Hello there I have a question, whether this is a bug or perhaps I'm doing something wrong.... I use the CI 2.1 with HMVC 5.3. Everything works out as a charm, until I do this: I auto-load a model, that runs through all the modules and runs them one by one like this: Modules::run('module_name'); each of the modules then gets initiated and the code inside the index() function runs. Everything works okay until I write in the addressbar (example module "Gallery): /gallery/load/1 The gallery.php (/modules/gallery/controllers/gallery.php) file looks like this: Code: <?php The error I get is: Fatal error: Class 'Gallery' not found in /Applications/XAMPP/xamppfiles/www/DOMAIN/system/application/third_party/MX/Modules.php on line 105 I tried playing around inside the Modules.php file and it seems that the file gets included, but for some reason the class can't be found!!! If I move the file inside /system/application/controllers/gallery.php then it works! It's a problem with the MX I think. Please help.... is this a bug or...?
[eluser]wiredesignz[/eluser]
@r4f, Your code works as it should in my test environment when called from the URL. I have no idea what you are trying to achieve with the code in the index method.
[eluser]r4f[/eluser]
Okay I will try to explain it here the best I can: I have a small custom CMS system, where we use it with MX to include different kind of modules. The auto-load model includes this code in the __construct method: Code: // load the modules This loads the modules_model model and runs the __construct method which is this: Code: class Modules_model extends CI_Model One of the rows from DB is for example "gallery". So it for example looks like this "Modules::run('gallery')". Inside the gallery controller: Code: class Gallery extends MX_Controller { The error that comes up says that class Gallery is not found. The controller is in /modules/gallery/controllers/ The other files mentioned are in /system/application/models/ folder. If you can get this to work then something is wrong with my setup.....
[eluser]wiredesignz[/eluser]
Your use of Modular Extensions looks rather whacked. But make sure the controller which loads the model that uses HMVC also extends the MX_Controller class. @InsiteFX, FYI, empty constructors are not required in a php5. The parent constructor will be called by default.
[eluser]r4f[/eluser]
There is no controller in the beginning, since the model is loaded automatically, defined in autoload.php. Well, I might have to change the structure, you're right about that, but I still think it's a bug. One should be able to run Modules::run() redundantly... for example a model that loads another model, that loads another model, and uses Modules::run, that again uses Modules::run, and again.... and it should also work if I step into the controller from the browsers address bar. It's a really weird bug, because I use Modules::run in an autoloaded model. And that works fine, but if I enter one of the loaded controllers from the browser, it cannot find the class. I will try to dig deeper into this matter and see if I can locate a specific error/bug in the code, and post it here. I still think MX is an fantastic piece of work that perhaps should be a standard part of CI. ![]()
[eluser]wiredesignz[/eluser]
[quote author="r4f" date="1340622248"]There is no controller in the beginning, since the model is loaded automatically, defined in autoload.php... [/quote] In fact there is a controller in action because the autoload sequence is initiated in the controller constructor. Modules::run was never intended to be used from a model. The HMVC design pattern focuses on controller to controller communications. |
Welcome Guest, Not a member yet? Register Sign In |