Part of the EllisLab Network
   
1 of 10
1
Wick 0.91 (beta) - Controller Loader
Posted: 22 May 2008 06:37 PM   [ Ignore ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  489
Joined  06-16-2006

Wick is a simple library that provides a method for loading and rendering one controller from within another controller. Some call it HMVC, some yell witchcraft and hunt you down with a pitchfork.

The library is ridiculously simple, and haven’t been tested fully. Please try it out and tell me if it works (and more importantly, if it doesn’t).

The library can be downloaded here.

---

Installation
Installation is easy as pie: Unzip the package and upload the Wick.php file to your application/libraries folder.

Note: If you are running multiple applications from the same CodeIgniter installation which all use the library you may wish to upload the file to the system/libraries folder instead.

Aaand you’re done!

Initialization
First of all you will have to load the library. You can either load it manually in your controller constructor or choose to auto-load it instead.

To initialize the class manually in your controller constructor, use the $this->load->library function:

$this->load->library('Wick');

Once loaded, the controller loader will be available using: $this->wick->light

Usage
The first (and only) parameter is the segments that lead to the controller and method you wish to call. Segments can be a string or an array.

$this->wick->light('news/local/123');

This will call the requested controller and show any output it migth give, before continuing execution of your current controller.

---

I’ve even set up a small site for it here.

 Signature 

Best regards, Zacharias.
Matchbox - Modular Separation | Wick - Controller Loader

Profile
 
 
Posted: 22 May 2008 07:07 PM   [ Ignore ]   [ # 1 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1711
Joined  06-10-2007

Interesting use of EVAL Zach.

Is this PHP4 compatible?

 Signature 

URI Language Identifier | Modular Extensions - HMVC | Validation Callbacks into Models | View Object PHP5 | Read the User Guide

Profile
 
 
Posted: 22 May 2008 07:11 PM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  489
Joined  06-16-2006

Yeah, it’s not the most elegant of hacks, but it works. smile

Regarding PHP4 support, I can’t say for sure, since I recently reinstalled XAMPP and took the lite version (which only comes with PHP5). I’m almost certain it is compatible, though.

 Signature 

Best regards, Zacharias.
Matchbox - Modular Separation | Wick - Controller Loader

Profile
 
 
Posted: 22 May 2008 07:21 PM   [ Ignore ]   [ # 3 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1711
Joined  06-10-2007

The reason I ask is because in PHP4, the Controller extends CI_Loader (via CI_Base) and Wick also has a controller function which may clash with the main Controller constructor.

Hope this helps.

Just a note also that Modular Extensions 4.1 uses CI Controllers in modules, and it is possible to load or run one controller from another, and modules are accessible from the URL now.

 Signature 

URI Language Identifier | Modular Extensions - HMVC | Validation Callbacks into Models | View Object PHP5 | Read the User Guide

Profile
 
 
Posted: 22 May 2008 07:23 PM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  489
Joined  06-16-2006

Neat, thanks for the heads-up. This will require a bit of testing then.

 Signature 

Best regards, Zacharias.
Matchbox - Modular Separation | Wick - Controller Loader

Profile
 
 
Posted: 23 May 2008 08:50 AM   [ Ignore ]   [ # 5 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  489
Joined  06-16-2006

Alright, I can confirm that it is, indeed, PHP4 compatible.

I am aware that Modular Extensions allows this functionality, but I needed a method for doing this without the use of modules, in which case ME might be overkill. smile

 Signature 

Best regards, Zacharias.
Matchbox - Modular Separation | Wick - Controller Loader

Profile
 
 
Posted: 23 May 2008 01:48 PM   [ Ignore ]   [ # 6 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  605
Joined  08-06-2006

wick = wicked cool code. keeping an eye on this thread (as i have been with ME thread which is now over 40 pages long!).

Profile
 
 
Posted: 23 May 2008 03:32 PM   [ Ignore ]   [ # 7 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1089
Joined  01-07-2008

Although I’m usually in the pitchfork camp, I must say that is some very clever code.

 Signature 

Blog | Twitter | Coffee

Profile
 
 
Posted: 23 May 2008 04:52 PM   [ Ignore ]   [ # 8 ]  
Lab Assistant
RankRank
Total Posts:  290
Joined  10-17-2006

Nicely coded. Cool approach by extending the loader class and replace $this->load.

Profile
 
 
Posted: 24 May 2008 02:25 PM   [ Ignore ]   [ # 9 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  489
Joined  06-16-2006

Thanks. smile

I had been thinking a bit about the problems with multiple libraries extending the same library, and this is the cleanest approach I could come up with.

 Signature 

Best regards, Zacharias.
Matchbox - Modular Separation | Wick - Controller Loader

Profile
 
 
Posted: 25 May 2008 09:47 PM   [ Ignore ]   [ # 10 ]  
Grad Student
Rank
Total Posts:  86
Joined  08-23-2007

Hey Zacharias,

Wow, I like this idea a lot, especially the fact that it accepts segments as a parameter! This way it allows you to use the same controller standalone or as part of another page using the same set of segments, which really makes sense from a site-structuring point of view.

Will it be compatible with Matchbox at some point? That would be great!

Thanx!

Profile
 
 
   
1 of 10
1
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 61065 Total Logged-in Users: 14
Total Topics: 73886 Total Anonymous Users: 1
Total Replies: 398529 Total Guests: 332
Total Posts: 472415    
Members ( View Memberlist )
Active Members:    bscottCraig RodwayCrucialEthan DunhamgazzaGDmacLuci3nmwmerzoutrageSarah PearsonSumontgo_detomcode