Welcome Guest, Not a member yet? Register   Sign In
Determining which module to load with Matchbox modules
#1

[eluser]PeteZahut[/eluser]
Suppose you have this url: http://www.somedomain.com/somename/

I'd like to determine which matchbox-module to load based on the "somename" segment. The segment is checked against the database where the type is pulled:

"select type from content where uri = 'somename'"

if the type is "page", go to the page-module and load "show_page" with seg 1 as value
if the type is "form", go to the form-module and load "show_form" with seg 1 as value
if the type is "module", go to the module using the name in segment 1 and load "index"

I know you can achieve this with custom routes, but how can this be achieved without specifying the custom routes?
#2

[eluser]wiredesignz[/eluser]
Using Matchbox modules without routes this would require a redirect() after choosing the final controller.

If you look at Modular Extensions HMVC you will see this can be achieved using a default controller with CI's remap() method and then loading or running the appropriate module controller.
#3

[eluser]PeteZahut[/eluser]
[quote author="wiredesignz" date="1210617493"]Using Matchbox modules without routes this would require a redirect() after choosing the final controller.

If you look at Modular Extensions HMVC you will see this can be achieved using a default controller with CI's remap() method and then loading or running the appropriate module controller.[/quote]

I see. I don't know if this may work, but here goes.

1. route all requests to deafult conroller using this in routes.php
Code:
$route['(.*)'] = "default_controller/$1";

2. do the redirect in default controller
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Default_controller extends Controller
{
    function Default_controller()
    {
        parent::Controller();
    }
    
    function index()
    {
        $this->db->select('type');
        $this->db->where('uri', $this->uri->segment(1));
        $query = $this->db->get('menu');
        $res = $query->result_array();
            
        if ($res[0]['type'] == 'form')
        {
            redirect('show_form');
        }
        if ($res[0]['type'] == 'page')
        {
            redirect('show_page');
        }
        if ($res[0]['type'] == 'module')
        {
            redirect('module_index');
        }
    }
}
?>

Correct me if i'm wrong but this won't do a background redirect to a controller. This will redirect through the url which leaves redirect() useless i think.
#4

[eluser]wiredesignz[/eluser]
Yes it will, you would need to be more specific with routes to allow calls to those controllers.

Modular Extensions would be a better choice to achieve the functionality you require. See my signature.

And this thread: http://ellislab.com/forums/viewthread/73177/




Theme © iAndrew 2016 - Forum software by © MyBB