Welcome Guest, Not a member yet? Register   Sign In
A Few Differences between 1.7.3 and 2.0
#1

[eluser]dougiebear[/eluser]
Firstly, many thanks for providing a great release.

Having just upgraded to 2.0 I wanted to share some differences I have observed.

Model Inheritance
I use a abstract base class for all models (e.g. MY_Model). The latest loader will instantiate both the leaf model and the base model. This caused a problem as my base class was abstract.

Code:
// example of model classes
class MY_Model extends CI_Model { ... }
class A_Model  extends MY_Model { ... }

// example controller
class Blog extended CI_Controller
{
    function __construct()
    {
        $this->load->model('a_model');

        // both model and a_model are loaded onto the controller
        // where model is of type MY_Model
    }
    ...
}

The solution was to make the base model class OK to instantiate. This maybe a code bug in the model loader. The previously version of load_class had a flag to indicate if the class should be instantiated.


Model Auto-complete Behaviour
The CI_Model class now uses a __get() function to make all the libraries loaded onto the Controller object available to the model. These where previously assigned as variables containing object references. I use doc comments on variables to provide type hints for auto complete. This no longer works and will raises an error when accessed.

Code:
class A_Model extends MY_Model
{
    /**
     * @var B_Model */ $var b_model;  // declared to help type hinting

    function __construct()
    {
        $this->load->model('b_model');      
    }
}

The solution was to remove the variable and loose the type hinting. If anyone knows how to declare a type hint for a class variable without making a declaration please let me know how.

HTML Table Generate Data
A change to the generate function exposed a problem with my code for some single row tables.

Code:
$this->table->clear();
$this->table->generate( array('red','green','blue') );  // this worked in 1.7.3 but now fails

$this->table->clear();
$this->table->generate( array( array('red','green','blue') ) );  // this works OK

The solution was to declare the generate data properly!

CLI
I had been using the cron.php script for CLI execution but now that CLI support is built in I have dropped the cron.php script.

A word of warning on some libux systems the index.php file can fail to find the correct system and application directory due to realpath returning an empty string. The reason for this is that the CLI invocation does not change the current directory. Therefore, realpath evaluates against some other directory (maybe the users home directory). I got around this problem by adding the following simple change to the index.php file.

Code:
/*
* ---------------------------------------------------------------
*  Resolve the system path for increased reliability
* ---------------------------------------------------------------
*/
    // FIX for CLI invocation:
    if ( !empty( $_SERVER['argv'] ) ) chdir( dirname(__FILE__) );

    if (realpath($system_path) !== FALSE)
    {
        $system_path = realpath($system_path).'/';
    }

    // ensure there's a trailing slash
    $system_path = rtrim($system_path, '/').'/';

    // Is the system path correct?
    if ( ! is_dir($system_path))
    {
        exit("Your system folder path does not appear to be set correctly. Please open the following file and correct this: ".pathinfo(__FILE__, PATHINFO_BASENAME));
    }

For reference my development system is Ubuntu 10.10 64bit + Zend Server CE using PHP 5.2.3.

I hope this feedback helps.


Messages In This Thread
A Few Differences between 1.7.3 and 2.0 - by El Forum - 02-03-2011, 03:29 PM
A Few Differences between 1.7.3 and 2.0 - by El Forum - 02-03-2011, 09:59 PM
A Few Differences between 1.7.3 and 2.0 - by El Forum - 02-04-2011, 09:43 AM
A Few Differences between 1.7.3 and 2.0 - by El Forum - 02-04-2011, 11:47 AM
A Few Differences between 1.7.3 and 2.0 - by El Forum - 02-05-2011, 07:43 AM
A Few Differences between 1.7.3 and 2.0 - by El Forum - 02-07-2011, 04:42 AM
A Few Differences between 1.7.3 and 2.0 - by El Forum - 02-07-2011, 06:00 AM
A Few Differences between 1.7.3 and 2.0 - by El Forum - 02-07-2011, 11:53 AM
A Few Differences between 1.7.3 and 2.0 - by El Forum - 02-09-2011, 07:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB