Welcome Guest, Not a member yet? Register   Sign In
Modular Extensions - Version 4.3

[eluser]codex[/eluser]
[quote author="wiredesignz" date="1209470581"]Version 4.0.28 is available on the wiki.[/quote]

Hoorah!

I was wondering if the module can send back data without the use of return $this->load->view()?

For instance, I use a dynamic META title, meaning the title in the browser bar is dependent of the data that's being retrieved. Let's say you have a blog, in the browserbar the title of the post appears. Normally I'd have in my controller the retrieval of data, assign the title to a variable and push that variable to my main_template.

But since the data retrieval is now being done in the module, how would the main_template (that's not in the module but in the controller) get the needed vars?

Know what I mean?

[eluser]wiredesignz[/eluser]
In my example above the module returns an array, one element contains the View, and other data such as the title is returned in the other array elements.

[eluser]wiredesignz[/eluser]
Example:
Code:
class Home extends Module
{
    function Home()
    {
        parent::Module();
    }
    
    function index()
    {
        $this->search->vehicles_model->findPaged("featured = 'Yes'", 4);
        
        $data['home'] =& $this; //the view has access to the module
        
        return array(                
            'output' => $this->load->view('home_content', $data),
            'title'  => 'Welcome to '
        );
    }
    
    function featured()    //used by home_content view as $home->featured()
    {
        $vehicle = $this->search->vehicles_model->iterate();
        
        return ($vehicle) ? $this->load->view('hot_pick', $vehicle) : FALSE;
    }
}

[eluser]codex[/eluser]
[quote author="wiredesignz" date="1209490593"]In my example above the module returns an array, one element contains the View, and other data such as the title is returned in the other array elements.[/quote]

Return as an array, of course! Why didn't I think of that!

Thanks!

[eluser]codex[/eluser]
I'm getting this error (v 4.0.28)

Code:
Fatal error: Call to undefined function: error() in f:\wamp\www\devs\application\helpers\modules_helper.php on line 171

[eluser]wiredesignz[/eluser]
Thanks codex.

Can you give some detail as to how this is occuring, every module has an error() method by default, are you initialising your module correctly? ie: parent::Module() in the constructor

[eluser]codex[/eluser]
[quote author="wiredesignz" date="1209537010"]Thanks codex.

Can you give some detail as to how this is occuring, every module has an error() method by default, are you initialising your module correctly? ie: parent::Module() in the constructor[/quote]

I can't seem to replicate it (I'm now error-free). Obviously I did something wrong, but I'm pretty sure I had initialized everything correct.

If I stumble upon it again I'll let you know.

[eluser]codex[/eluser]
Hey wire, ME is looking better and better, but there's (hopefully Wink) one last thing I'm not certain about.

I'm making use of the _remap function:
Code:
function _remap($page)
{
    $method = $this->uri->rsegment(3);
        $value  = $this->uri->rsegment(4);
        
        
if($this->uri->total_segments() == 0)
        {
            $data['module'] = modules::run('public/pages/pages','', 'index');
        }
        
        elseif($this->uri->total_segments() > 0)
        {
            switch($page)
            {
                case 'blog':
                    $data['module'] = modules::run('public/blog/blog', $this->uri->segment(1), 'index');
                    break;
                case 'portfolio':
                    $data['module'] = modules::run('public/portfolio/portfolio', $value, 'listPortfolioItems');
                    break;                    
                default:
                    $data['module'] = modules::run('public/pages/pages', $this->uri->segment(1), 'show_page');
            }
}

If you look at the second case, it means that "if you encounter portfolio as the pagename, send the request to the portfolio module. When you're in the portfolio module, go to the listPortfolioItems method", right?
The corresponding URL would be
Code:
http://www.domain.com/portfolio/

But what if you have a value after /portfolio/?
Code:
http://www.domain.com/portfolio/some_portfolio_name_here

How do you 'tell' _remap() which method to use then?

I hope you don't mind me asking you a lot of questions ;-)

[eluser]wiredesignz[/eluser]
codex, your questions are welcome, you actually show some code which makes life easy. Wink

Yeah I just did something similar to this, take a look:
Code:
//using remap      
    function _remap($method)
    {
        if (method_exists($this, $method)) // is the method is in this controller?
        {
            $this->$method($this->uri->rsegment(3)); // call it
        }
        else    // the method is a module
        {
            // use url_title helper to convert-this to convert_this            
            $module = url_title($method, 'underscore');

            $method = $this->uri->rsegment(3) OR $method = 'index'; // get the method for the module
            
            $data = array(
                'module_output' => modules::run($module, '', $method)
            );
            
            $this->load->view('module', $data);
        }
    }

if the method is a random value then error will be called in the module:
Code:
//override the default module error method
    function error($some_value)
    {
        $this->model->get($some_value); // the model will hold the resultset in an array
        
        $data['model'] =& $this->model; // pass a reference to the model
        
        return $this->load->view('the_view', $data);
    }

[eluser]codex[/eluser]
How to access models and libraries?

In the wiki there's this:
Code:
The controller also has access to these new libraries via the Module. ie:
$this->module_name->library  or  $this->module_name->model

But when trying to access either
Code:
$this->portfolio->validation->set_rules($rules)
or plain
Code:
$this->validation->set_rules($rules)
you get 'Fatal error: Call to a member function on a non-object'.

Same goes for models. They are being initialized though.
Code:
DEBUG - 2008-04-30 16:18:23 --> File loaded: application/modules/public/portfolio/models/portfolio_model.php
DEBUG - 2008-04-30 16:18:23 --> Validation Class Initialized




Theme © iAndrew 2016 - Forum software by © MyBB