Welcome Guest, Not a member yet? Register   Sign In
Modular Extensions - HMVC version 5.3

[eluser]Basketcasesoftware[/eluser]
I know I can extend the MX_Controller class. But I have a situation where it would be nice to extend the class that extends MX_Controller. Hmmm... 8-/

[eluser]wiredesignz[/eluser]
Create your own MY_Controller extending MX_Controller and extend that as needed. Actually any class (in core/ or libraries/) can extend MX_Controller because MX uses spl_autoload to do the magic loading for you.

Here's an example:
Code:
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

/**
* Base Controller
*/
class BaseController extends MX_Controller
{
    function __construct()
    {    
        parent::__construct();
        
        //$this->lang->load('application');
        
        $this->load->library('view');
        $this->load->plugins(array('widget', 'parser'));
                
        modules::run('csv_import');
        
        //$this->output->enable_profiler();
    }
    
    function _remap($action)
    {
        $this->load->vars($this->config->item('settings'));
        
        if (method_exists($this, $action))
        {
            call_user_func_array(array($this, $action), array_slice($this->uri->segments, 2));
        }
        else
        {    
            modules::run('error/error404', trim($this->uri->uri_string, '/'));
        }
        
        $this->view->render();
    }
}
/* End of file BaseController.php */
/* Location: ./application/libraries/BaseController.php */

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

class Showroom extends BaseController
{    
    public $autoload = array(
        'modules' => array('search'),
    );
    
    function index($page = 1)
    {        
        if ($id = $this->input->get('id')) return $this->detail($id);
        
        $page = $this->input->get('page');
        
        $found = $this->search->run($page)/9;
        
        $this->load->vars(array(
            'content'         => View::factory('showroom_content'),
            'current_page'    => 'cars-for-sale',    
            'found'         => $found,
            'page_no'         => $page,
        ));
    }

    function browse() /* modules::run('showroom/browse'); */
    {
        $vehicle = $this->vehicles_model->iterate();
        return ($vehicle) ? View::factory('hot_pick', array('vehicle' => $vehicle)) : FALSE;
    }

    function detail($id = NULL)    
    {
        $this->vehicles_model->findBy("StockNo = '{$id}'");
        
        $vehicle = $this->vehicles_model->iterate();
        $vehicle = modules::run('fuel_saver', $vehicle);

        $this->view->set(array(
            'company_slogan' => $this->config->item('company_name', 'settings'),
            'company_name'      => $vehicle->Description.' '.$vehicle->Year.' for sale - ',
        ));
        
        $this->load->vars(array(
            'content'         => View::factory('detail_content', array('vehicle' => $vehicle)),
            'current_page'  => 'cars-for-sale',
        ));
    }
}
/* End of file showroom.php */
/* Location: ./application/controllers/showroom.php */

[eluser]Basketcasesoftware[/eluser]
Thanks. That's exactly what I've been looking for. Smile I thought that was the case but I was looking for confirmation.

[eluser]darrentaytay[/eluser]
Hi guys, still having trouble having images inside the modules folder and linking to them within a view. I even tried typing in the absolute path of the image and it didn't work.

Has anyone had any joy with this? Regardless, I will keep playing around with it and keep you updated.

[eluser]Basketcasesoftware[/eluser]
[quote author="dt17" date="1297696284"]Hi guys, still having trouble having images inside the modules folder and linking to them within a view. I even tried typing in the absolute path of the image and it didn't work.

Has anyone had any joy with this? Regardless, I will keep playing around with it and keep you updated.[/quote]

Have you tried entering the absolute path to the image in your browser? And not through CodeIgniter? Could be something to do with your web host... you might even have to clear your browser cache (I've had weird problems just from that...)

[eluser]darrentaytay[/eluser]
Hi Basket,
I have tried that yeh - this is just a brand new copy of CI Reactor with HMVC installed and one module created. It's simply a blank page with an image on it. It's installed locally on WAMP. Very strange!

[eluser]Basketcasesoftware[/eluser]
I use XAMPP myself so I have no way of fully reproducing your conditions. If you want you could send me the files and I can try it on my machine and on my remote host. Maybe I can spot something.

[eluser]Glazz[/eluser]
If i try to autoload the language library i get this error:

An Error Was Encountered
Unable to load the requested class: lang

[eluser]Wayne Smallman[/eluser]
[quote author="wiredesignz" date="1285600519"]I have explained this so many times.
Set the Form_validation $CI instance to the object you require to respond to callbacks.

Code:
// Call validation and set rules
$this->load->library('form_validation');

//Set the callback object
$this->form_validation->CI = $this;
[/quote]
I've now run into this problem, and having spent two days cumulatively trying a variety of different techniques, all have failed.

When I tried the above code, I got errors ranging from warnings to fatalities throughout the application.

I tried the My_Form_validation library technique, which yielded nothing.

I tried amending the MX_Controller / MY_Controller files, which resulted in an error:

Code:
Message: Invalid argument supplied for foreach()

Filename: core/MY_Controller.php

I've scoured the internet for suggestions, and tried several other minor alterations, none of which worked, either.

Does anyone have a definitive working solution to what appears to be CodeIgniter not being able to find the callback functions in their respective controllers?

[eluser]wiredesignz[/eluser]
@Wayne Smallman, That code above contains an error.
It is essential to assign the current controller to the $CI variable by reference.

Code:
/* load form validation */
$this->load->library('form_validation');

/* Assign the current controller by reference */
$this->form_validation->CI =& $this;




Theme © iAndrew 2016 - Forum software by © MyBB