Part of the EllisLab Network
This thread is a discussion for the wiki article: Modular Extensions - HMVC
   
7 of 35
7
Modular Extensions - HMVC
Posted: 24 April 2009 08:35 AM   [ Ignore ]   [ # 91 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  3198
Joined  06-10-2007
dmitrybelyakov - 24 April 2009 12:25 PM

Yes that worked, now i can access the class variables that were set in the default module, but still no assess to default module method’s. Is there a way to access them from other modules?

How about using Modules::run() or load the module as a class variable and call a method like you do already?

 Signature 

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

Profile
 
 
Posted: 24 April 2009 12:59 PM   [ Ignore ]   [ # 92 ]  
Grad Student
Avatar
Rank
Total Posts:  54
Joined  03-19-2008
wiredesignz - 24 April 2009 12:35 PM

How about using Modules::run() or load the module as a class variable and call a method like you do already?

This is exactly what I am doing. I am loading all Modules from Default Module as class variables. _CI is also set in Default Module. Then it is accessible from loaded modules and contain all public methods of the Default Module like this:

$request_parameter=$this->_CI->request('parameter'); 

This was possible in ME 5.1.40. This is not possible now, because _CI (set in Default Module) is not accessible to loaded modules. And if we set _CI inside a loaded module it of course does not contain the Default module methods.

Update:

Here’s a small test case (just to illustrate) with two Modules & two versions of Modular Extensions in Libraries: www.dmitrybelyakov.com/testcase.zip


Update:

There’s one more thing: i discovered a strange problem that i can’t figure out how to fix. I traced it to the place in your Controller.php on line 7 where you call

CI::getInstance(); 

I now try to debug further but no success. Don’t kow maybe i nedd to tweak some application or php settings, but just don’t know what exactly.  Happens only with new version of ME on a fresh php instalation (Zend server, php 5.2.9)

The problem turned out to be because of Zend Optimiser conflicting with ME. Need to turn Zend Optimiser off to run ME.

Profile
 
 
Posted: 29 April 2009 05:48 AM   [ Ignore ]   [ # 93 ]  
Summer Student
Avatar
Total Posts:  11
Joined  03-04-2009

Hi!
Is there a posibility to call model (module/models/my_model) from library (module/libraries/my_library) or which way should I look for??
Thanks!

Profile
 
 
Posted: 29 April 2009 07:27 AM   [ Ignore ]   [ # 94 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  3198
Joined  06-10-2007

Hi yuga,

Using the inbuilt helper function get_instance() will return the application object which contains all ‘loaded’ objects from all modules.

EDIT:
I’m updating Modular Extensions to improve this feature. Will post back.

 Signature 

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

Profile
 
 
Posted: 29 April 2009 01:19 PM   [ Ignore ]   [ # 95 ]  
Summer Student
Avatar
Total Posts:  11
Joined  03-04-2009

Thank you, wiredesignz )
Love your ME ))

Profile
 
 
Posted: 30 April 2009 09:23 AM   [ Ignore ]   [ # 96 ]  
Summer Student
Avatar
Total Posts:  11
Joined  03-04-2009

Hi!

Does Form_validation works fine with HMVC?

I can’t get validation_errors() and can’t find the reason.

If it works, please let me now so I could be more efficient in problem searching.

Profile
 
 
Posted: 30 April 2009 10:38 AM   [ Ignore ]   [ # 97 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  3198
Joined  06-10-2007

Hi yuga,

Yes CI form validation works ok with ME.

The form validation class does not have an validation_errors() method as such. You need to use either error() or error_string().

If you are using the form_helper function validation_errors() try checking the output from the form_validation->error_string() method first.

 Signature 

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

Profile
 
 
Posted: 01 May 2009 02:16 AM   [ Ignore ]   [ # 98 ]  
Summer Student
Avatar
Total Posts:  11
Joined  03-04-2009

Thanks a lot for replying, wiredesignz grin

Profile
 
 
Posted: 02 May 2009 01:24 PM   [ Ignore ]   [ # 99 ]  
Summer Student
Avatar
Total Posts:  11
Joined  03-04-2009

Yes, it works fine when I use
$this->data[‘msg’] = $this->form_validation->error_string(); - Thanks for good answer, wiredesignz)
But still can’t find why
$this->data[‘msg’] = validation_errors(); doesn’t work.
I’ve used the last variant in previous projects where was no ME and everything was ok.
So I’m a little confused)
But the right solution was found so my project is ok now, thanks)

Profile
 
 
Posted: 07 May 2009 04:22 PM   [ Ignore ]   [ # 100 ]  
Grad Student
Rank
Total Posts:  79
Joined  10-18-2008

Today i updated HMVC from 5.1.40 to 5.2.08
I must say it went very smoothly, everything still worked.
I’ve got a performance win from 0.1432 sec to 0.1408 sec.
That’s a lot, thanx!!!

I use the modules:run function to dynamically load all the modules on the page.
In the database i have a lot of tables, most important:
navigations table, module table, a module show table, a layout table and a layoutposition table.

In the module table there are 7 fields, most important: moduleName, moduleController, moduleMethod.
In the layout table you can set per menu item all the modules, in this table are the following fields:
layout_FK_menuId, layout_FK_moduleId, layout_FK_layoutPositionId, layoutWeight, layoutShow
so for instance you have position top left middle right bottom and more,  and you have layoutweight 1 2 3 etc.
In the moduleShow table you can set the modules which are show on all pages. Except if you put a field in the layout table with this module with a certain menuId with layoutShow = 0. I’m planning to make an extra field in the moduleShow table where you can set a categorie and in the navigationstable you can asign a menu item to a categorie.

There are 2 queries to get the modules which will be loaded on the current page.
1 gets all the modules from the layout table, and the other all the modules from the moduleShow table.
Then it combines the 2 objects to 1 and deletes all modules which are set to not show on that page.
Then i create a foreach loop where all the modules will loaded into an array: the key is the layoutpositionname + the layoutweight (for instance left1 or right3 or top1) and the value is this method: modules::run($method_name, $parameter1, $parameter2 etc etc…);

private function build_layout()
{
    
foreach($this->layout_data as $key => $value)
    
{        
        
if($value->layoutShow == TRUE)
        
{
            $module 
$value->layoutPositionName.$value->layoutWeight;
            
$name    $value->moduleName."/".$value->moduleController."_".
                  
$value->moduleName."_controller/".$value->moduleMethod;
            
$layout[$module] modules::run($name$this->sel_lang,  $this->menu_id$value->modulePar1$value->modulePar2);
        
}
    }
    
if(!isset($layout))
    
{
        
return false;
    
}
    
return $layout;

So the value is not a string, but here it executes the modules:run() method. so it load a method from a certain module.
For instance it executes this: modules::run(menu/standard_menu_controller/show, ‘_en’, ‘5’, ‘>= 1’, ‘main-menu’).
So it executes the show method in the standard_menu_controller in the menu module. This show method loads a view file.
So the value is the returned parsed html in the view file.
Then in the main controller in the index i create another loop wich asign each key and value to the main view:

if(is_array($this->layout))
{
    
foreach($this->layout as $key => $value)
    
{
        $data[$key] 
$value;
    
}

So now in the main view i echo all the posible position, if a module is loaded into here:

<?php if(isset($left1)) echo $left1?> 

So it echoes the correct view in a module:  module > controller > method > view

And here you have you dynamic loading!


Thanx wiredesign! 1 question: is this good practice to do it like this? Or do you suppose something else?

Profile
 
 
Posted: 10 May 2009 02:34 PM   [ Ignore ]   [ # 101 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  185
Joined  04-10-2009

Hello all,

I’m sure this has been answered or I am overlooking the answer in the wiki, but I’ve been at it for hours and still stuck. This question itself may even be fundamentally wrong.

I desperately need ME HMVC or I will literally be forced to abandon Codeigniter.

I’m trying to “drop” ME HMVC into my project, and I happen to be using Freakauth_light 1.1. I will use the error I am getting from Freakauth_light as my example, although I’m certain it is not isolated to Freakauth_light usage. I have NOT created any modules yet, but plan to move my existing code into modules, if I can get everything working normally first. Note that any page that doesn’t require authorization works fine so far.

This is with CI 1.7.1 and ME 5.2

A PHP Error was encountered

Severity
Notice

Message
Undefined propertyCI::$fal_validation

Filename
libraries/FAL_front.php

Line Number
88

Fatal error
Call to a member function set_error_delimiters() on a non-object in C:\webroot\application\libraries\FAL_front.php on line 88 

Another

I’m sorry I can’t be more specific, as I have no idea what’s going on. I’ve moved files around to many different places but get the same error. Something to do with $this->CI = &get;_instance(); maybe?

Something to do with FAL_front trying to load libraries?

//lets load the validation class if it hasn't been already loaded
        //it is needed by the FAL_validation library
        
if (!class_exists('CI_Validation'))
        
{
             $this
->CI->load->library('validation');
        
}
        
//let's load the FAL_validation library if it isn't already loaded
        
if (!class_exists('FAL_validation'))
        
{
             $this
->CI->load->library('FAL_validation');
        

I am NOT extending the controller with MY_controller or anything.

I’d paste the rest of the code if only we had spoiler tags oh oh

I can provide more details if needed, thanks in advance - this library should be bundled with CI!!

Profile
 
 
Posted: 10 May 2009 11:24 PM   [ Ignore ]   [ # 102 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  3198
Joined  06-10-2007

@Madmartigan1, I posted this some time ago, it might help.
Freakauth_light and Modular Extensions

 Signature 

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

Profile
 
 
Posted: 13 May 2009 10:54 AM   [ Ignore ]   [ # 103 ]  
Summer Student
Total Posts:  25
Joined  12-01-2008

If I try to update from the 5.1.40 to the last version I get an error:

Undefined property:  Welcome_lib::$CI
Trying to get property of non-object

if I use $this->CI->whatever() in my library, in the doc I don’t find any difference:

$CI is added as a default class variable to libraries loaded by ME. ($CI =& get_instance() is not required), Simply use $this->CI->whatever() in your library.

any suggestion? thanks

Profile
 
 
Posted: 14 May 2009 05:04 AM   [ Ignore ]   [ # 104 ]  
Summer Student
Avatar
Total Posts:  11
Joined  03-04-2009

Hi!
I have problems in using callbacks (form_validation library) with ME - it doesn’t work (but works fine with clean CI). I use validation in methods of modules/some_module/controllers/some_controller.
I believe that trouble is at line 585 (form_validation library) and similar - when we trying to get callback_method.

It seems like I can get methods from module’s library but not from module’s controller (library is loaded in $this->CI).
So I think I can make my callbacks work by using library, but don’t think this is the optimal decision. There must be better way)). May be I should use CI::instance()? But don’t know how)
I’m not such a strong programmer))
And really need your help)
So any suggestions?

Profile
 
 
Posted: 14 May 2009 10:38 AM   [ Ignore ]   [ # 105 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  3198
Joined  06-10-2007

Hi yuga, try adding this MY_Form_validation extension to your application,

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class 
MY_Form_validation extends CI_Form_validation 
{
    
function run($module ''$group ''{        
        
(is_object($module)) AND $this->CI =& $module;
        return 
parent::run($group);
    
}    
}
/* End of file MY_Form_validation.php */
/* Location: ./application/libraries/MY_Form_validation.php */ 

and then add “$this” to your validation run call, which tells form validation on which controller to make callbacks.

if ($this->form_validation->run($this)) {
    
...

Note that using this extension you should be able to make callbacks on any object method including those in libraries and models.

 Signature 

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

Profile
 
 
   
7 of 35
7