Welcome Guest, Not a member yet? Register   Sign In
[Plugin] CodeIgniterPhp5 (Autoloader, Modularity, Fast Coding)
#31

[eluser]Dewos[/eluser]
[quote author="AgentPhoenix" date="1262032549"]
Code:
switch ($library_name)
{
    case 'user_agent':
        $lib_name = 'agent';
        break;
            
    default:
        $lib_name = $library_name;
}
[/quote]

Nice! Actually i switch to Kohana3, but if you can post the tested core i'll update the plugin.
#32

[eluser]AgentPhoenix[/eluser]
I changed up my approach since using a switch statement wouldn't be very dynamic in the event EllisLab added more libraries that did something similar. Now, I just check to see if the object name parameter is still NULL and if it is, I set it to the library name. I've tested it and it seems to work just fine.

Code:
<?php

/**
* Php5 Loader Plugin for Codeigniter
*
* @author        Piro Fabio (1.2++) - Jonathon Hill (<= 1.1)
* @version        Version 1.8 (works on Codeigniter <= 1.7.3)
* @link        Userguide at: http://ellislab.com/forums/viewthread/99960/P15/
*/

// Init
CI::$ci    = & get_instance();

class CI
{
    public static $ci;

    // Library
    public static function library($library = '', $params = NULL, $object_name = NULL)
    {
        $suffix = '';
        $library_name = $library.$suffix;

        if (strpos($library_name, '/') !== FALSE)
        {
            $sub_directory = explode('/', $library_name);
            $library_name = end($sub_directory);
        }

        if ( ! isset(self::$ci->$library_name))
        {
            if ($object_name === NULL)
            {
                self::$ci->load->library($library_name, $params, $library_name);
            }
            else
            {
                self::$ci->load->library($library_name, $params, $object_name);
            }
        }

        return self::$ci->$library_name;
    }

    // Model
    public static function model($model, $name = '', $db_conn = FALSE)
    {
        $suffix = '_model';
        $model_name = $model.$suffix;

        if (strpos($model_name, '/') !== FALSE)
        {
            $sub_directory = explode('/', $model_name);
            $model_name = end($sub_directory);
        }

        if ( ! isset(self::$ci->$model_name))
        {
            self::$ci->load->model($model_name, $name, $db_conn);
        }

        return self::$ci->$model_name;
    }

    // View
    public static function view($view, $vars = array(), $return = FALSE, $template = TRUE)
    {
        $suffix = '_view';
        $view_name = $view.$suffix;

        return self::$ci->load->view($view_name, $vars, $return);
    }

    // Vars
    public static function vars($vars = array(), $val = '')
    {
        return self::$ci->load->vars($vars, $val);
    }

    // Helper
    public static function helper($helper = array())
    {
        $suffix = '_helper';
        $helper_name = $helper.$suffix;

        if ( ! empty($helper) && ! isset(self::$ci->load->_ci_helpers[$helper_name]))
        {
            self::$ci->load->helper($helper);
        }

        return new Modularity('helper');
    }

    // Plugin
    public static function plugin($plugin = array())
    {
        $suffix = '_pi';
        $plugin_name = $plugin.$suffix;

        if ( ! empty($plugin) && ! isset(self::$ci->load->_ci_plugins[$plugin_name]))
        {
            self::$ci->load->plugin($plugin_name);
        }

        return new Modularity('plugin');
    }

    // Config
    public static function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
    {
        if ( ! empty($file) && ! in_array($file, self::$ci->config->is_loaded))
        {
            self::$ci->load->config($file, $use_sections, $fail_gracefully);
        }

        return new Modularity('config');
    }

    // Lang
    public static function lang($file = array(), $lang = '')
    {
        if ( ! empty($file) && ! in_array($file.'_lang.php', self::$ci->lang->is_loaded))
        {
            self::$ci->load->language($file, $lang);
        }

        return new Modularity('lang');
    }

    // Db
    public static function db($db = '', $return = FALSE, $active_record = FALSE)
    {
        if(empty($db))
        {
            if ( ! isset(self::$ci->db))
            {
                include(APPPATH.'config/database'.EXT);
                self::$ci->load->database($active_group, $return, $active_record);// default
            }

            return self::$ci->db;
        }
        else
        {
            return self::$ci->load->database($db, TRUE, $active_record);
        }
    }
}

// Modularity
class Modularity
{
    public function __construct($type)
    {
        $this->type = $type;
    }

    public function __call($name, $args)
    {
        switch ($this->type)
        {
            case 'config' :
                return call_user_func_array(array(CI::$ci->config, $name), $args);
                break;

            case 'lang'      :
                return call_user_func_array(array(CI::$ci->lang, $name), $args);
                break;

            case 'helper' :
            case 'plugin' :
                return call_user_func_array($name, $args);
                break;
        }
    }
}
#33

[eluser]Benedikt[/eluser]
Dewos, you said you would switch to Kohana, this means you wont support this library anymore?

Thanks for the info.
#34

[eluser]Dewos[/eluser]
[quote author="Benedikt" date="1265596321"]Dewos, you said you would switch to Kohana, this means you wont support this library anymore?

Thanks for the info.[/quote]

Hi Benedikt.
The library is really 100% Back\Forward for Compatibility, so you're not gonna need so much support i think.
#35

[eluser]sergi81[/eluser]
Hi,

When I try use this plugin i got error :/

Code:
Fatal error: Access to undeclared static property: CI::$ci in /home/site/public_html/application/libraries/loader_php5_pi.php on line 12


Something I do wrong ??
#36

[eluser]sihijau[/eluser]
nice plugin, will you make it compatible with next version CI ?
#37

[eluser]Peter Ivanov[/eluser]
I dont see how to get template variables...

For example how i can get variable like this one

$test = $this->template ['posts'];

how can i do this with the new syntax?
#38

[eluser]Peter Ivanov[/eluser]
The download link is not working

Please re-upload
#39

[eluser]Peter Ivanov[/eluser]
Please update download link
#40

[eluser]Unknown[/eluser]
Really Great ,

But the download link not working -> blank page !

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB