Front controller-view for advanced module

edited February 2014 in Share
So. I've build advanced module with a few simple modules models inside. Admin works fine. I'm very happy with the elegant relationship model!
Now I need to have some controllers for frontend. I have success with a traditional CI controllers, but want to put them in a module directory. I have looking around how is build the blog module, but looking strange for me and confusing me.
Is there are simple way to render a views from module controller for front-end.
Also I want to use a layouts that is in my main codeigniter application view folder.
In forum found found some examples using fuel_page class. But in version 1.4 there is no fuel_page class (or my mistake?).

And second question - how to use fuel_base_model to retriving record(s) (again for front end). For example:
I have a "course" that has many "teachers" and belongs to "member". What is the right way to get the record with relationships records from model and populate in the view.

Sorry for tedious question, but can't find the examples.

Comments

  • edited February 2014
    Finally catch the idea...
    1. Make base module controller library.
    2. Include in front module controller and extend it.
    3. In base controller make some method to render views:
    function _render($view, $vars = array(), $return = FALSE, $layout = '') { //get body for view in layout $vars['body'] = $this->load->module_view({MODULE_NAME}_FOLDER, $view, $vars, TRUE); // get any global variables for the headers and footers $uri_path = trim($this->fuel->{MODULE_NAME}->config('uri'), '/'); $_vars = $this->fuel->pagevars->retrieve($uri_path); if (is_array($_vars)) { $vars = array_merge($_vars, $vars); } //Set the default layout $layout = (! empty($layout) ) ? $layout : 'main'; $output = $this->load->view('_layouts/'.$layout, $vars, TRUE); $this->load->module_library(FUEL_FOLDER, 'fuel_pages'); $this->fuel_pages->initialize(); $output = $this->fuel_page->fuelify($output); if ($return) { return $output; } else { $this->output->set_output($output); } }

    4. Call the _render method instead of $this->load->view() after collect the vars from model(s).

    Maybe is good idea to put some base controller in module generator.

    So far so good... now - how to use models and magic methods :)
    .
  • edited 1:52PM
    As an FYI, the _render method is just a convenience method on the Blog_base_controller.php that assembles the views and variables. You can also use the following:
    $this->load->module_view('module_name', 'view_file', $vars);

    For the magic methods, you've probably already seen this documentation, but if not, here it is:
    http://docs.getfuelcms.com/general/models#magic_methods
    http://docs.getfuelcms.com/general/models#formatters
  • edited 1:52PM
    I totally missed this chart for models in user guide... :). Sorry and thanks!
Sign In or Register to comment.