Welcome Guest, Not a member yet? Register   Sign In
when will they release code igniter in php5?
#11

[eluser]Phil Sturgeon[/eluser]
[quote author="fayer" date="1264571007"]when do u think they will release code igniter in php5?[/quote]

Tuesday.

[quote author="Demedes" date="1264615545"]So, does anybody interested In php5 only version of CI with all php5 native features?[/quote]

Of course we are all interested in seeing progress in CodeIgniter moving forward, but its not all that simple.

You can create an __autoload() function to use libraries in exactly the way you mentioned or staticly, but how do we then extend those?

If we use:

Code:
custom_library::do_something();
// or
$lib = new Custom_library;

And we then want to extend that library, we have to use:

Code:
MY_custom_library::do_something();
// or
$lib = new MY_Custom_library;

That removes a whole lot of the reason why we are extending libraries in the first place and is a big part of why we have $this->custom_library instead.

If you urgently need more PHP 5 specific syntax, give Kohana a try. They have done a lot of this already but not looked much into how.
#12

[eluser]Jelmer[/eluser]
[quote author="Phil Sturgeon" date="1264617214"]Tuesday[/quote]
LOL

[quote author="GSV Sleeper Service" date="1264617034"]@Jelmer, thanks, I never considered trying that. Won't you end up with two instances of the object if you do that though?
I have set up my own __autoload() to replace the CI models with Doctrine models, this works fine.[/quote]
If you use the $this->load->library('class') you'll indeed end up with 2 instances, which is why I use an autoloader. But that first example is for when you need a second instance, otherwise I don't really see a problem using the normal CI syntax (other than maybe your IDE).

I'm currently using RapidDataMapper for my projects and I've changed the default autoloader in the MY_Loader class to the following to allow for loading non-core libraries & models. You could probably change your Doctrine autoloader like this to allow for autoloading libraries and models.
Code:
public static function load_data_object($class)
{
    $class = preg_replace('/([^a-zA-Z0-9_]*)/', '', $class);
    $class_db = strtolower($class);
    
    if (file_exists(APPPATH . 'data_model/'.$class_db.EXT))
    {
        require APPPATH . 'data_model/'.$class_db.EXT;
        
        return TRUE;
    }
    elseif (file_exists(APPPATH.'libraries/'.$class.'.php'))
    {
        require_once(APPPATH.'libraries/'.$class.'.php');
        
        return TRUE;
    }
    elseif (file_exists(APPPATH.'models/'.strtolower($class).'.php'))
    {
        $ci = get_instance();
        $ci->load->model($class);
        unset($ci->{$class});
        
        return TRUE;
    }
}
(I put models at the bottom as that's the least common usage and data_models are used more often than libraries)

I also added an autoloaded helper that allows me to call CI functions in the same way from everywhere using a static class:
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Ci
{
    // Protect constructor to prevent instantiation
    private function __construct() { }
    
    // Get CI library/model or variable
    static function get($name)
    {
        $ci = get_instance();
        return $ci->{$name};
    }
    
    // Alias for get(), only allows objects
    static function obj($name)
    {
        $return = self::get($name);
        if (is_object($return))
            return $return;
        else
            return NULL;
    }
    
    // Alias for obj()
    static function lib($name)
    {
        return self::obj($name);
    }
    
    // Alias for get(), only allows extentions of the Model class
    static function mod($name)
    {
        $return = self::get($name);
        if (is_subclass_of($return, 'Model'))
            return $return;
        else
            return NULL;
    }
    
    // Load CI application library (not used for system libraries)
    static function library($library = '', $params = NULL, $object_name = NULL)
    {
        $ci = get_instance();
        return $ci->load->library($library, $params, $object_name);
    }
    
    // Load CI application model
    static function model($model, $name = '', $db_conn = FALSE)
    {
        $ci = get_instance();
        return $ci->load->model($model, $name, $db_conn);
    }
    
    // Load CI application view
    static function view($view, $vars = array(), $return = FALSE)
    {
        $ci = get_instance();
        return $ci->load->view($view, $vars, $return);
    }
    
    // Load CI application helper
    static function helper($helpers = array())
    {
        $ci = get_instance();
        return $ci->load->helper($helpers);
    }
    
    // Get config item
    static function config($item, $namespace = NULL)
    {
        $ci = get_instance();
        return $ci->config->item($item, $namespace);
    }
    
    // Get language line
    static function lang($line)
    {
        $ci = get_instance();
        return $ci->lang->line($line);
    }
    
    // Get post variable
    static function post($var)
    {
        $ci = get_instance();
        return $ci->input->post($var);
    }
}

/* End of file short_ci_helper.php */
/* Location: ./system/application/helpers/short_ci_helper.php */
It makes some statements actually longer but it looks better in my opinion, especially in libraries which I used to give a property $this->ci and as such every CI function became something like $this->ci->config->item('') which became Ci::config('') or libraries where $this->ci->image_lib->clear() became Ci::lib('image_lib')->clear(). In controllers though $this->image_lib->clear() is actually shorter than Ci::lib('image_lib')->clear().
I didn't do it because it saves characters but because it makes accessing CI look the same everywhere and because it more clearly differentiates controller functions from CI functions.

Loading libraries/models/helpers is shorter though (Ci::library(), Ci::model(), Ci::helper) as is accessing language lines, post variables and config items (Ci::config(), Ci::lang(), Ci::post())
#13

[eluser]Joshua Logsdon[/eluser]
RE: "So, does anybody interested In php5 only version of CI with all php5 native features?"
Yeah, they were called BlueFlame and are now Kohana Smile




Theme © iAndrew 2016 - Forum software by © MyBB