Harro Verton wrote on Sunday 3rd of April 2011:You can add a routes.php file to your module's config folder. This will be read and parsed when a module request is detected (the first URI segment == the module name). This implies that all routes defined must match a URI that starts with the module name: There is no module default route. A default route is defined globally, in your applications routes.php.
Harro Verton wrote on Sunday 3rd of April 2011:Why would you want to do that? If you want to add a global route that points to a module ('test' => 'module/controller/method'), it needs to be in the app's routes.php. You don't want app specific coding in a module, that would ruin portability. If you want module specific routes ('module/test' => 'module/controller/method'), you can do that now using the module routes.php. So I still don't know why you want this. Could you give an example of why you would like to add module routes to the global routes when loading a module, without actually wanting to call the module?
return array( 'main/page' => 'modulename/controller/method' );to a module's routes.php. At the moment, it's not our intention to do so, as that would mean look for and parsing the routes.php of all (loaded) modules, which would quickly become a mess, especially if you start with third-party modules. The only place to put these routes (where you are sure they are available and won't introduce conflicts) is in your app's routes.php. If you feel otherwise, please add a feature request to our bugtracker at [url=http://dev.fuelphp.com,]http://dev.fuelphp.com,[/url] explaining why you need this, and linking to this thread for reference.
namespace Blog; Class Controller_Blog extends [b]\Controller[/b] { public function action_index() { // Here goes index action logic $this->render('index'); // calls for view file index.php located in fuel/app/modules/blog/views/index.php } }Now, let's add model. Blog.php goes to app/modules/blog/classes/model:
namespace Blog; class Model_Blog extends [b]\Model[/b] { public static function hi() { return 'hello world!'; } }SO, we have a model, but how do we get data from it? Here's an update of blog.php controller:
namespace Blog; Class Controller_Blog extends [b]\Controller[/b] { public function action_index() { echo [b]Model_Blog::hi()[/b]; // This will print 'hello world' from our model } }
Steve Wasiura wrote on 03/15/11 1:46 pm:ok thank you. Just so I understand, is a module a way to "group" your code into a folder for organization purposes? If you created a blog module on your website abc.com, and then you wanted to use that same code on your other website def.com, you could copy everything in the module/blog folder to the new site?
Many thanks for your tutorial. I followed the instructions and created "app/modules/blog/views/index.php"Charlie Black wrote on Saturday 22nd of January 2011:I'm writing this very short tutorial/example for those developers who intend to use modular system for their future projects built on Fuel.
...
...
<h4>hello from module -> BLOG - view -> index.php </h4>Unfortunately, the output is identical when the blog view is called from the main view:
<h4>hello from module -> BLOG - view -> index.php </h4>I would be grateful to know how to call the module so that the HTML formatting is correct.
public function action_index() { // HURRAY - CRACKED IT Fuel::add_module('blog'); if(true) { // FORMATS CORRECTLY $tmp = Request::factory('blog', false)->execute(); $this->template->set_global('blog', $tmp, false); unset($tmp); } else { // NOT FORMATTED $data['blog'] = Request::factory('blog', false)->execute(); } // lots more stuff goes here $data = array(); $data['module_title'] = 'John\'s Modules Stuff'; $this->template->content= View::factory('john/v_john', $data); }//endfunc }//endclassfile: ./fuel/app/views/john/v_john.php
<div class='modules'> <h3 class='bga'><?php echo $module_title;?></h3> <h3>Modules Testing</h3> <?php if(1) { echo $blog; } ?> </div>
Class Controller_News extends \Controller {
Class Controller_Blog extends \Controller {
It looks like you're new here. If you want to get involved, click one of these buttons!