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

[eluser]Sam Dark[/eluser]
I'm not too happy about getting base ones from URL. That's true.
Your solution is what actually needed.

So we can use:

Base_Controller
Public_Controller
Secure_Controller

and they will be loaded from correspondind files. Good.

Are you planning to implement this for 4.x version?

btw., is 5025 the last 5.x version you've emailed?
#92

[eluser]wiredesignz[/eluser]
Hi Sam, 5.0.28 is the latest PHP5 version.

I have been away from home for the last 3 weeks so I haven't been able to access the mailing list.

Have no fear I will send out the latest version as soon as I get back.

Thanks for your patience.

EDIT:
PHP4 version can't use __autoload, but I will work something similar out.
#93

[eluser]chuckleberry13[/eluser]
I really like that Base_Controller idea. Could I get on that email list for ME 5? [email protected]
#94

[eluser]autoreverse[/eluser]
I like the elegance of the __autoload solution but, in addition to the PHP 4 incompatibility, autoloading is not available if using PHP from the command line. This probably means that cron jobs have to be run over HTTP rather than via the shell.

The following code added to the end of Controller.php (release 4026 - I've just started looking at the ME project today) after the Controller class declaration works in both PHP 4 and PHP 5 and should also solve the CLI problem:

Code:
/* PHP4/5/CLI autoload helper - PHP4 and CLI require modules.php config file*/
if (phpversion() >= 5 & !isset($argc))
{
    function module_autoloader($class)
    {
        if (is_file($filename = APPPATH.'libraries/'.$class.EXT))
            require_once $filename;
    }
    spl_autoload_register('module_autoloader');
}
else
{
    if (is_file(APPPATH.'config/modules'.EXT))
    {
        require(APPPATH.'config/modules'.EXT);
        foreach ($config['modules_controller_extensions'] as $class)
        {
            require_once APPPATH.'libraries/'.$class.EXT;
        }
    }
}

(note the use of spl_autoload_register to reduce the chance of name clashes with other __autoload functions)

and the corresponding config file, config/modules.php:

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

/*
|--------------------------------------------------------------------------
| Controller Extensions
|--------------------------------------------------------------------------
|
| Contoller extensions to be autoloaded after instantiation of the Modular
| Extensions Controller class. Files are loaded in the order listed in the
| array - list earliest descendants first.
|
*/
$config['modules_controller_extensions']    = array('Base_Controller', 'Public_Controller');

Another approach would be to specify an alternative prefix to 'MY_' in a config file for the controller extension file.

I'd prefer to see a more elegant solution this works for me for now :-)

* Edited to more clearly show that this mod is best used for controller extensions only. Regular custom libraries should be loaded via conventional methods such autoloading.
#95

[eluser]wiredesignz[/eluser]
Thanks autoreverse, this does look nice, I will try it out myself and see how it goes.

Welcome to CI forums also.
#96

[eluser]wiredesignz[/eluser]
Modular Extensions PHP5 version 5.0.31 has been e-mailed out.

Added PHP5 spl_autoload for extending Controller from base class and loading module controllers automatically.

Thanks autoverse Wink
#97

[eluser]Sam Dark[/eluser]
Is there a way to check if HMVC controller is called from URL or not?

It will be good to have something like:

$this->no_uri_access();

I don't like underscores.
#98

[eluser]wiredesignz[/eluser]
Hi Sam,

Yes, add the _remap() method to your module controller. Do what ever you wish there.
Example:
Code:
/* _remap() protects the module controller */

    public function _remap()
    {
        exit('No direct script access allowed');
    }
#99

[eluser]beemr[/eluser]
Anybody here use Callbacks into Models? Please check out the new Form_validation thread. I've updated the extension to work with CI 1.7, but since I don't use Modular Extensions, I can't verify whether it will still work for you guys. Please check it out.

Thanks.

[eluser]m4rw3r[/eluser]
Thanks for the great lib!

Now I'm wondering if there is a way to load a module's library/model from another module or from the main app?




Theme © iAndrew 2016 - Forum software by © MyBB