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

[eluser]tomcode[/eluser]
I haven't checked what happens after it, though, but to me it seems my app has become faster !!!

[eluser]wiredesignz[/eluser]
It would be faster if you reuse a lot of classes, there will be less file access. Wink

[eluser]tomcode[/eluser]
So only benefits ?

[eluser]codex[/eluser]
Hey wire, I need some help here.

I love ME, but I think I may be using it the wrong way. Let's say I have a blog module, I first create the main controller that loads the view (just an example):
Code:
class Blog_controller extends MY_Controller {

// ========================================================================

    function Blog_controller()
    {
        parent::MY_Controller();
    }

    function show_blog()
    {    
        $template['content'] = $this->load->view('blog/show_blog', '', true);
        $this->load->view('layout/main_template', $template);
    }
}

The 'showBlog'view holds the module_run code:
Code:
<?=modules::run('blog_module', '', 'showBlog')?>

In modules/controllers I create another controller:
Code:
class Blog_module extends Module {

// ========================================================================

    function Blog_module()
    {
        parent::Module();
    }

    function showBlog()
    {
        $this->load->model('blog_model');
        
        $data['blog_items'] = $this->blog_model->getBlogItems();
        
        return $this->load->view('list_blog_items', $data, TRUE);
    }

In modules/views I create 'list_blog_items'-view, which presents the final data.

Is that correct?

Would it be possible to call the module directly from the url (or make it do that), surpassing the need to create a controller and view?

[eluser]wiredesignz[/eluser]
There's no set way to use ME, but I prefer to use a normal controller to intercept and manage the URI calls, this way I have only one frontend controller and one backend controller each with it's own set of modules.

If you use _remap() you can then load or run a module based on the URI content, something like this:
Code:
//using remap
    function _remap($page, $content = '', $title = '')
    {
     // $module = $this->uri->rsegment(1);  //$page = segment(1) and is already passed to _remap
        $method = $this->uri->rsegment(2);
        $value  = $this->uri->rsegment(3);
        
        switch ($page) // select the module to run
        {
            case 'index':
            
            case 'home':
                $content = modules::run('home', $value, $method);
                break;
            case 'showroom':
                $content = modules::run('showroom', $value, $method);
                break;
            default:
                $content = modules::run('error', $page, 'error_404');
        }
        
        $data = array(
            'title'   => $content['title'].$title,
            'content' => $content['output'],
            'page'    => $page,
        );
    
        $this->load->view('default_layout' , $data);
    }
Let me know if you need more explanation.

[eluser]codex[/eluser]
Thanks!

I see the _remap function is described in the Wiki. Was it always there? Can't believe I missed that :red: (though for some reason you refer to the forum quicker than the wiki)

Nother question though: to check user access to controllers/methods I make use of

Code:
$route =& load_class('Router');
$class = $route->fetch_class();
$method = $route->fetch_method();

But is it possible to do the same with ME, meaning that you can get the module and method name? Something like:

Code:
$module = $mod->fetch_module();
$method = $mod->fetch_method();

[eluser]wiredesignz[/eluser]
Is this so you can prevent a user from accessing certain modules?

I have a system using an auth module which checks the current user credentials, auth is loaded by the front controller before any other modules run, each page module has an minimum access level (an integer value) that is hardcoded into its constructor, if the user access level passed to the module by auth is lower than the required level the module will deny access to that user.

Apart from that ME relies on the developer sorting out which module & method to run, in version 4.0.27 I have added a feature where modules:run() to a non-existent module will return FALSE, rather than generate an error message.

[eluser]codex[/eluser]
[quote author="wiredesignz" date="1209406430"]Is this so you can prevent a user from accessing certain modules?
[/quote]
Exactly.

Quote:I have a system using an auth module which checks the current user credentials, auth is loaded by the front controller before any other modules run, each page module has an minimum access level (an integer value) that is hardcoded into its constructor, if the user access level passed to the module by auth is lower than the required level the module will deny access to that user.
I've been breaking my head over how to tackle user access levels. Your solution was one of the candidates. In the end I decided that access control on controller/method level was the way to go (although I'm still not sure because it poses new problems). See, it's for a CMS and I'd like to give admins the option to specifically define which areas are accessible to user groups.

Quote:Apart from that ME relies on the developer sorting out which module & method to run, in version 4.0.27 I have added a feature where modules:run() to a non-existent module will return FALSE, rather than generate an error message.
Cool. When can we expect 4.0.27? :coolsmirk:

[eluser]wiredesignz[/eluser]
Soon, I'm just running a few trials across different applications I have made using ME.

If you really need dynamic access control, you could have the auth module check the user credentials from a database and instruct (using $data) each module to allow or deny access.

[eluser]wiredesignz[/eluser]
Version 4.0.28 is available on the wiki.

modules::run() returns FALSE on `module not found` rather than an error.
modules::load_file checks if class exists before include.
debug is a now a seperate helper.




Theme © iAndrew 2016 - Forum software by © MyBB