EllisLab text mark
Advanced Search
4 of 24
4
   
Modular Extensions - HMVC version 5.4
Posted: 25 April 2011 08:18 AM   [ # 51 ]   [ Rating: 0 ]
Avatar
Joined: 2011-01-31
384 posts

Thanks for the info wiredesignz.
I am basically using core for my commercial projects.
I’ll check it there too and repost.

The vanilla test was on reactor since I wanted to check my projects on reactor too.
I know I might be asking too much but could we have another branch for reactor and another for core?

Thanks again for your contributions.

 Signature 

NetID

 
Posted: 25 April 2011 04:13 PM   [ # 52 ]   [ Rating: 0 ]
Joined: 2010-01-28
40 posts

Hi wiredesignz, was I wrongly extending MX_Lang or is there not a native way to extend that with HMVC?  Also, is there a bug with $this->router->fetch_module() not always returning the correct module in different contexts?

 
Posted: 25 April 2011 10:00 PM   [ # 53 ]   [ Rating: 0 ]
Joined: 2011-01-05
16 posts

Hi! I’m starting to learn HMVC and I really think that it can do wonders. It might be what I need to actually create an admin-member-non-member website.

I’m just running encountering a problem. It seems there’s a problem with calling HMVC from the view. I’m currently following the Net Tuts HMVC: an introduction and application. Let me explain:

Here are the functions:

THE CONTROLLER FUNCTION UNDER “LOGIN” MODULE:

function cp()  
{  
    
if( $this->session->userdata('username') )  
    
{  
        
// load the model for this controller  
        
$this->load->model('membership_model');  
        
// Get User Details from Database  
        
$user $this->membership_model->get_member_details();  
        if( !
$user )  
        
{  
            
// No user found  
            
return false;  
        
}  
        
else  
        
{  
            
// display our widget  
            
$this->load->view('user_widget'$user);  
        
}  
    }  
    
else  
    
{  
        
// There is no session so we return nothing  
        
return false;  
    
}  

and

THE VIEW UNDER THE “SITE” MODULE:

<!DOCTYPE html>  
<
html lang="en">  
<
head>  
    <
meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
    <
title>untitled</title>  
</
head>  
<
body>  
    
<?php echo modules::run('modules/login/cp');?>  
    
<h2>Welcome Back<?php echo $this->session->userdata('username'); ?>!</h2>  
     <
p>This section represents the area that only logged in members can access.</p>  
</
body>  
</
html

THE PROBLEM:

I can’t seem to call cp() from the view using <?php echo modules::run(‘modules/login/cp’);?>. It doesn’t produce the user_widget. If I change the function called in the view (i.e. <?php echo modules::run(‘modules/login/RANDOMFUNCTION’);?>), it don’t get an error.

If I remove the “modules” from the path (as in the original code in the article - <?php echo modules::run(‘login/cp’);?>), I get an error:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Login::$session

Filename: controllers/login.php

Line Number: 91

Is there something wrong with the code? I followed the guide to the letter except when I had to edit the module::run call from module::run(‘login/cp’) to module::run(‘modules/cp’) to follow the format specified:

Format: modules::run(‘module/controller/action’, $param1, $param2, .., $paramN);

 
Posted: 25 April 2011 10:02 PM   [ # 54 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-10
2939 posts

@wilso417, MY_Lang should be located in application/core and should extend MX_Lang. The error with CI_Controller needs to be resolved as a separate issue.

MX_Router::fetch_module() returns the name of the last module controller loaded.

 Signature 

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

 
Posted: 25 April 2011 10:06 PM   [ # 55 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-10
2939 posts

@eldrinofsoalim, Don’t use the word “modules” use the name of your module. The error with Login::$session needs to be resolved as a separate issue.

 Signature 

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

 
Posted: 26 April 2011 05:05 PM   [ # 56 ]   [ Rating: 0 ]
Joined: 2010-01-28
40 posts

I see, thanks wiredesignz. 

Is there any easy way to return or have fetch_module() return the last module being ‘used’ and not just loaded?

 
Posted: 29 April 2011 12:09 PM   [ # 57 ]   [ Rating: 0 ]
Joined: 2009-03-30
1317 posts

Just pulled the latest changes for Reactor. I had to add another public var to MX/Loader.php

public $_ci_classes = array(); 
 
Posted: 04 May 2011 04:42 PM   [ # 58 ]   [ Rating: 0 ]
Joined: 2010-05-13
142 posts

Hi Wiredesignz, any way I can have the HMVC modules load when calling them from a view partial, but have them ignore the url? Ideally configurable per module.

 
Posted: 04 May 2011 05:38 PM   [ # 59 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-10
2939 posts

@Mr. Pickle, Use modules::run(‘module/controller/method’) to load a module from a view partial and add the _remap() method to a controller where you can manage calls from the URL.

class Partial_controller extends MX_Controller
{
    
public function _remap() //trap calls from the URL
    
{        
          show_404
();        //show page not found
    
}

    
public function show_view() 
    
{
         $this
->load->view('what_ever');
    
}
 Signature 

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

 
Posted: 04 May 2011 05:55 PM   [ # 60 ]   [ Rating: 0 ]
Joined: 2010-05-13
142 posts

Hi Wiredesignz,

Thanks for your quick reply!

If I show a 404 the visitor will see a 404 while I just want CI to ignore the module in the process where CI looks for a module in the modules/ directory based on the uri (don’t know the official term for this :D)

I’ll explain my problem further:
I now have a newly developed module called guestbook in the modules/ directory.
I load this module via a view partial:

<?=Modules::run('controller/method');?> 

No problems so far…..

Now one of my sites just got a page called guestbook with the following full url:
http://www.mydomain.com/guestbook

Now the problem starts. I use a single controller ‘page’ (module page within the modules/ dir) handling all my requests. While I want CI to load this controller and handle the requests as it would do if I had no module called guestbook it only shows the module (which is set-up as a partial) Normal behaviour but not for me in this set-up wink
Of course I DO want to load this module this way if I use the view partial method of calling it (and not have CI load the full page guestbook)

Hope I managed to explain it a little, if not feel free to ask for more info wink

 
Posted: 04 May 2011 07:07 PM   [ # 61 ]   [ Rating: 0 ]
Joined: 2010-05-13
142 posts

I think I’ve solved it.
I put all the logic of getting the page stuff from the database (not only content pages but EVERY page) in the page controller within the modules/.

I now put all this logic in a MY_controller so that this logic is not skipped whatever module is loaded (all module controllers extend this MY_Controller)

 
Posted: 04 May 2011 09:24 PM   [ # 62 ]   [ Rating: 0 ]
Joined: 2010-01-28
40 posts

MX_Router::fetch_module() only returning ‘last module controller loaded’ creates a problem with loading/using multiple language files as well. 

This seems to be a pretty big bug if you want to use HMVC in a non-linear fashion of just load/use controller, load/use controller, etc.

 
Posted: 04 May 2011 10:23 PM   [ # 63 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-10
2939 posts

@wilso417,  It is not a bug. The fetch_module() method does the job it was designed to do.

If you care to look you’ll see that each controller loader object stores the correct module name.

If you require more functionality, write it yourself.

 Signature 

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

 
Posted: 04 May 2011 10:36 PM   [ # 64 ]   [ Rating: 0 ]
Joined: 2010-01-28
40 posts

I’m sorry, it just seemed like a bug, I did not mean to offend.  It seemed like a bug because I thought this situation would be possible:

class Test2 extends MX_Controller {

public function index() {

$this->lang->load('test2');
echo $this->lang->line('test_me');
}
}

class Test1 extends MX_Controller {

public function index() {

$this->load->module('test2');
$this->test2->index();

$this->lang->load('test1');
echo $this->lang->line('test_this');
}
}

where the language files are in their respective modules folder.  This will not work because lang is looking in the test2 folder when i try to load ‘test1’ language file.

 
Posted: 04 May 2011 10:43 PM   [ # 65 ]   [ Rating: 0 ]
Joined: 2010-01-28
40 posts

I think the issue is, that ‘lang’ is a library.  Libraries have no way of knowing what module called it as far as I can tell.

 
4 of 24
4