EllisLab text mark
Advanced Search
19 of 23
19
   
Modular Extensions - HMVC version 5.4
Posted: 04 October 2012 12:48 AM   [ Ignore ]   [ # 281 ]   [ Rating: 0 ]
Joined: 2012-06-09
3 posts

Found a bug in HMVC’s Loader that leads to a “Fatal error: Maximum function nesting level of ‘100’ reached, aborting!”

The error can be reproduced by creating an autoload config file within a module and adding a library to load. Ex:

modules/
..
admin/
....
config/
......
autoload.php
....libraries/
......
admin_controller.php 

The problem was that the ‘_autoloader’ function kept recursively trying to “autoload” the library regardless of whether or not it’s already loaded. This lead to an endless loop where the loaded file (which extends the MX_Controller) called it’s parent controller which in turn tried to ‘initialize’ on every call in which ‘_autoloader’ was called again and again (a recursive result of the infamous ‘goto’).

I solved this by adding a line in the Loader to check if the class was already loaded so it doesn’t recurse itself…

// MX/Loader.php
// line (396-398)?:
// -> replace:
// foreach ($autoload['libraries'] as $library) {
//     $this->library($library);
// }
// -> to:
foreach ($autoload['libraries'as $library{
    
if (class_exists($libraryFALSE)) continue;
    
$this->library($library);


~NS

 
Posted: 04 October 2012 02:38 AM   [ Ignore ]   [ # 282 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-10
2919 posts

The problem occurs because you have incorrectly put a controller into the libraries directory.
I don’t agree that altering any code is required because the library loader already checks for the class so you’re just duplicating code to fix your mistake.

 Signature 

URI Language Identifier | Modular Extensions - HMVC | View Object | Widget plugin | Access Control library

 
Posted: 04 October 2012 03:40 AM   [ Ignore ]   [ # 283 ]   [ Rating: 0 ]
Joined: 2012-06-09
3 posts
wiredesignz - 04 October 2012 02:38 AM

The problem occurs because you have incorrectly put a controller into the libraries directory.
I don’t agree that altering any code is required because the library loader already checks for the class so you’re just duplicating code to fix your mistake.

Do the modules support extending the core class? or look for the extensions in a special folder where I can place my custom classes to extend the core through a module? Duplicating code to fix my mistake..? I’m sorry, didn’t know you would be offended by a simple solution that makes it easier to extend core..

I know you can add a separate function in HMVC to look into a “core” folder within the module and extend core classes from thereon but I’m a bit lazy so that was sufficient lol.

 
Posted: 04 October 2012 03:55 AM   [ Ignore ]   [ # 284 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-10
2919 posts

I’m not offended at all. Just stating a fact.

CI conventions indicate that controllers and their ancestors provide core functionality they are not defined as libraries.

If you need a base controller you can create a core directory in your module and include the parent class as per your normal PHP directives or place them into the application/core directory to be autoloaded.

Also if you load a base controller as a library then you are instantiating a redundant controller instance which seems pointless.

In future it might be worth looking at the Modules::autoload() method to accommodate loading core files from modules too.

 Signature 

URI Language Identifier | Modular Extensions - HMVC | View Object | Widget plugin | Access Control library

 
Posted: 04 October 2012 09:09 AM   [ Ignore ]   [ # 285 ]   [ Rating: 0 ]
Joined: 2012-06-09
3 posts
wiredesignz - 04 October 2012 03:55 AM

I’m not offended at all. Just stating a fact.

CI conventions indicate that controllers and their ancestors provide core functionality they are not defined as libraries.

If you need a base controller you can create a core directory in your module and include the parent class as per your normal PHP directives or place them into the application/core directory to be autoloaded.

Also if you load a base controller as a library then you are instantiating a redundant controller instance which seems pointless.

In future it might be worth looking at the Modules::autoload() method to accommodate loading core files from modules too.

Alright awesome then =). I’m new to CI so correct me if I’m wrong. Btw, HMVC is a great addition to CI, I really do like it but of course, stuff needs to be modified when scaling out applications.

Including the parent class as per normal PHP directives defeats the purpose of having the class loaded through the CI system, I’d need to include the class into every controller I make within the module - this is why I wanted to have the class autoloaded since it will be used regardless for all controllers in the module. And placing my extended core classes into core defeats the purpose of individual modularity - and plus, I have other extensions of core classes using the “subclass_prefix.”

The Modules::autoload() function does not go to the depth of /module/module_name/core, but rather stays at application level. I’d need to modify this if I wanted this to look for a core folder within a module.

Just because a core class is placed in a “libraries” folder doesn’t mean that it has to act like a library. Would I rather put it in a folder called “core” for the sake of indicating it is a core class? Yes, I would love to lol.

 
Posted: 11 October 2012 10:20 AM   [ Ignore ]   [ # 286 ]   [ Rating: 0 ]
Avatar
Joined: 2010-01-05
2 posts

I have a question about routing with modules. I have a setup similar to the following:

/application/
|--- 
modules/
   |--- 
somemodule/
      |--- 
config/
         |--- 
routes.php
      
|--- controllers/
         |--- 
admin.php
         
|--- foobar.php
         
|--- somemodule.php
      
|--- models/
      |--- 
views

And inside my routes.php file in the module, I have something similar to the following:

$route['somemodule']        'somemodule';
$route['somemodule/foobar''foobar';
$route['admin/somemodule']  'admin'

The first 2 routes work just fine, but the admin route does not.

Based on the searching/research I’ve done, the Modular Extension script is not made to handle routes (in a routes file within the module) with a path that starts with something other than the module name out-of-the-box. I know that I can put the routes in the main routes file, but I’d like to keep them with the module if at all possible.

Has anyone been able to find a solution to get routes like the 3rd one above to work when put in a module routes file?

 
Posted: 31 October 2012 06:33 PM   [ Ignore ]   [ # 287 ]   [ Rating: 0 ]
Avatar
Joined: 2012-07-19
32 posts

Hey wiredesignz, I have a question.. Suppose you might think it a strange request, especially considering that HMVC is designed to check for a module first, followed by the default location if no module is found.

Is it possible to prevent any views loading from the default ‘views’ folder? For example, using this controller:

class Display extends MX_Controller {
 
public function index() {
  $this
->load->view('display');
 
}

By default, this will look first for ‘application\modules\display\views\display.php’, then if that fails it will look for ‘application\views\display.php’. I want it to only check the modules path for the view and fail if it doesn’t exist.. Is this possible?


For some reason, while under Windows CI with HMVC runs fine when I remove the default views folder, when I run the same app on Linux it tells me it can’t find the controller. When I create the views folder again (even leaving it empty), the error goes away.

I also tried commenting out the middle section of HMVC’s view() method, like this:

/** Load a module view **/
public function view($view$vars = array(), $return FALSE{
 
list($path$_view) = Modules::find($view$this->_module'views/');
 
 
// if ($path != FALSE) {
 //  $this->_ci_view_paths = array($path => TRUE) + $this->_ci_view_paths;
 //  $view = $_view;
 // }
 
return $this->_ci_load(array('_ci_view' => $view'_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));

Thinking that it would try load the module’s view and not the default, but even with the view in the ‘module\views’ folder, I get an error saying it can’t load ‘display.php’.

Any ideas…?

 
Posted: 01 November 2012 01:30 AM   [ Ignore ]   [ # 288 ]   [ Rating: 0 ]
Joined: 2012-11-01
2 posts

Hey,

I’ve wanted to download HMVC, but in the “downloads” it says there is nothing to download. do I have to open everything in source and just copy paste the code ? :O

 
Posted: 01 November 2012 01:59 AM   [ Ignore ]   [ # 289 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-10
2919 posts
ZaLiTHkA - 31 October 2012 06:33 PM

Hey wiredesignz, I have a question..

...Is it possible to prevent any views loading from the default ‘views’ folder? ...

Any ideas…?

Alter the MY_Loader.php file and add a modified view method.

Check after the modules::find() method that $this->_module value is valid and that the $path value is false. This will indicate that the view does not exist in the module.

 Signature 

URI Language Identifier | Modular Extensions - HMVC | View Object | Widget plugin | Access Control library

 
Posted: 01 November 2012 02:26 AM   [ Ignore ]   [ # 290 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-10
2919 posts
GamBeaT - 01 November 2012 01:30 AM

Hey,

I’ve wanted to download HMVC, but in the “downloads” it says there is nothing to download…

Go back to Bitbucket and look more thoroughly.

 Signature 

URI Language Identifier | Modular Extensions - HMVC | View Object | Widget plugin | Access Control library

 
Posted: 01 November 2012 02:30 AM   [ Ignore ]   [ # 291 ]   [ Rating: 0 ]
Avatar
Joined: 2012-07-19
32 posts
GamBeaT - 01 November 2012 01:30 AM

Hey,

I’ve wanted to download HMVC, but in the “downloads” it says there is nothing to download. do I have to open everything in source and just copy paste the code ? :O

That confused me a bit when I first found this as well… On the ‘Downloads’ page, then select the ‘Branches’ tab and you’ll see links on the right hand side.

wiredesignz - 01 November 2012 01:59 AM

Alter the MY_Loader.php file and add a modified view method.

Check after the modules::find() method that $this->_module value is valid and that the $path value is false. This will indicate that the view does not exist in the module.

Ok cool, thanks.. I’ll try that when I get home tonight and see what I can do, not actually sure if what I’m trying to do will actually work anyway, but there’s only one way to find out. smile I think I’ll base it on an optional extra parameter so I don’t end up breaking something else in the process.

 
Posted: 01 November 2012 10:27 AM   [ Ignore ]   [ # 292 ]   [ Rating: 0 ]
Joined: 2012-11-01
2 posts

thanks, got it smile now got a question, how does this feature works with URI language indentifier ?

 
Posted: 01 November 2012 02:10 PM   [ Ignore ]   [ # 293 ]   [ Rating: 0 ]
Avatar
Joined: 2010-08-24
49 posts

I just downloaded codeigniter 2.1.3 and Hmvc 5.4 ,  I found that the controllers method is running two times. here below is the code for

<?php
class Index extends MX_Controller
{
    
function index()
    
{
      
//  $this->load->view('index/index');
       
echo "samit<br>";
    
}
}
?> 

And i Got the result
samit
samit

I think this is a bug.

 Signature 

Murkha Sanga Daiba Daraunchan.(Even gods are afraid of fools)

 
Posted: 02 November 2012 01:14 AM   [ Ignore ]   [ # 294 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-10
2919 posts

@samitrimal, Be sure to post back when you discover that it’s not a bug.

 Signature 

URI Language Identifier | Modular Extensions - HMVC | View Object | Widget plugin | Access Control library

 
Posted: 02 November 2012 11:19 AM   [ Ignore ]   [ # 295 ]   [ Rating: 0 ]
Avatar
Joined: 2010-08-24
49 posts

hi @wiredesignz,Please check the log generated when i used the code. I am using your extension for first time. I don’t know if i am wrong

modules/test/controllers/index.php
<?php
class Index extends MX_Controller
{
    
public function index(){
        
          $this
->load->model('test/tests_m');
         
$this->tests_m->get_();
            
$this->load->view('test/index/welcome_message');
    
}
}
modules
/test/models/test_m.php
<?php
class Tests_m extends CI_Model
{
    
public function get_(){
        
echo get_class();
    
}
}
?>
modules
/test/views/index/welcome_message.php
<?php 
echo __FILE__;?> 

Output :
/var/www/contact_ci/application/third_party/MX/Loader.php
/var/www/contact_ci/application/third_party/MX/Loader.php
Tests_m/var/www/contact_ci/application/third_party/MX/Loader.php
Tests_m/var/www/contact_ci/application/modules/test/views/index/welcome_message.php/var/www/contact_ci/application/modules/test/views/index/welcome_message.php

Finally Log generated when running the code.

DEBUG - 2012-11-02 20:57:50—> Config Class Initialized
DEBUG - 2012-11-02 20:57:50—> Hooks Class Initialized
DEBUG - 2012-11-02 20:57:50—> Utf8 Class Initialized
DEBUG - 2012-11-02 20:57:50—> UTF-8 Support Enabled
DEBUG - 2012-11-02 20:57:50—> URI Class Initialized
DEBUG - 2012-11-02 20:57:50—> Router Class Initialized
DEBUG - 2012-11-02 20:57:50—> Output Class Initialized
DEBUG - 2012-11-02 20:57:50—> Security Class Initialized
DEBUG - 2012-11-02 20:57:50—> Input Class Initialized
DEBUG - 2012-11-02 20:57:50—> Global POST and COOKIE data sanitized
DEBUG - 2012-11-02 20:57:50—> Language Class Initialized
DEBUG - 2012-11-02 20:57:50—> Language Class Initialized
DEBUG - 2012-11-02 20:57:50—> Config Class Initialized
DEBUG - 2012-11-02 20:57:50—> Loader Class Initialized
DEBUG - 2012-11-02 20:57:50—> Database Driver Class Initialized
DEBUG - 2012-11-02 20:57:50—> User Agent Class Initialized
DEBUG - 2012-11-02 20:57:50—> Template Class Initialized
DEBUG - 2012-11-02 20:57:50—> Session Class Initialized
DEBUG - 2012-11-02 20:57:50—> Helper loaded: string_helper
DEBUG - 2012-11-02 20:57:50—> Session routines successfully run
DEBUG - 2012-11-02 20:57:50—> Controller Class Initialized
DEBUG - 2012-11-02 20:57:50—> Model Class Initialized
DEBUG - 2012-11-02 20:57:50—> File loaded: application/modules/test/models/tests_m.php
DEBUG - 2012-11-02 20:57:50—> Model Class Initialized
DEBUG - 2012-11-02 20:57:50—> File loaded: application/modules/test/views/index/welcome_message.php
DEBUG - 2012-11-02 20:57:50—> File loaded: application/modules/test/views/index/welcome_message.php
DEBUG - 2012-11-02 20:57:50—> Final output sent to browser
DEBUG - 2012-11-02 20:57:50—> Total execution time: 0.0311

Hope, you will believe it now.

 Signature 

Murkha Sanga Daiba Daraunchan.(Even gods are afraid of fools)

 
19 of 23
19