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.
#2

[eluser]portgaz[/eluser]
WooOO! It works perfectly!
You saved my day. I can now use my cron!!!!! :lol:

Thank you so much! God Bless!
#3

[eluser]skunkbad[/eluser]
I was having a problem in that $_SERVER['argv'] is being set when I have a query string, even though there was no CLI usage. Testing for $_SERVER['argv'] may not be a reliable way to determine if the request is from CLI.
#4

[eluser]Eric Barnes[/eluser]
[quote author="skunkbad" date="1296855830"]I was having a problem in that $_SERVER['argv'] is being set when I have a query string, even though there was no CLI usage. Testing for $_SERVER['argv'] may not be a reliable way to determine if the request is from CLI.[/quote]

That should be fixed in the next release: https://bitbucket.org/ellislab/codeignit...bf5de0bde2
#5

[eluser]dougiebear[/eluser]
The PHP docs (http://php.net/manual/en/function.php-sapi-name.php) suggest the following function to check between CGI or CLI invocation.

Code:
if ( strcasecmp( php_sapi_name() ,'cli') === 0 )
{
    // CLI invocation
}

This may make the test more portable.
#6

[eluser]Phil Sturgeon[/eluser]
[quote author="dougiebear" date="1296934981"]The PHP docs (http://php.net/manual/en/function.php-sapi-name.php) suggest the following function to check between CGI or CLI invocation.

Code:
if ( strcasecmp( php_sapi_name() ,'cli') === 0 )
{
    // CLI invocation
}

This may make the test more portable.[/quote]

PHP_SAPI is not always reliable, I have instead used defined('STDIN') which is pretty fool-proof.
#7

[eluser]wyred[/eluser]
[quote author="Eric Barnes" date="1296863242"][quote author="skunkbad" date="1296855830"]I was having a problem in that $_SERVER['argv'] is being set when I have a query string, even though there was no CLI usage. Testing for $_SERVER['argv'] may not be a reliable way to determine if the request is from CLI.[/quote]

That should be fixed in the next release: https://bitbucket.org/ellislab/codeignit...bf5de0bde2[/quote]

After upgrading one of my sites to 2.0 and uploading it to my webhost for testing, my jquery function that uses ajax to fetch data didn't work. The browser would be redirected to the same url and remains in a "loading" state forever.

This apparently fixed it. For anyone else experiencing the same problem, my webhost is Dreamhost.
#8

[eluser]skunkbad[/eluser]
[quote author="Phil Sturgeon" date="1297096967"]
PHP_SAPI is not always reliable, I have instead used defined('STDIN') which is pretty fool-proof.[/quote]

Well, if there's a fool around here, he'll prove you wrong!
#9

[eluser]wyred[/eluser]
I have this weird problem on my Windows PC, Apache server which I suspect might be related to this CLI/CGI issue.

I'm not good at debugging so please bear with me as I try to explain.

My website loads new posts when you click on a button, like old twitter, using jQuery/AJAX.

I get the following error:
Warning: include(application/errors/error_php.php) [function.include]: failed to open stream: No such file or directory in C:\Users\wyred\Documents\wwwroot\ttto\system\core\Exceptions.php on line 167

I made sure the file is there and it is.

I intentionally caused an error on the home page and this file loaded fine. However when the AJAX request was made, that error showed up.

I used getcwd() on the home page, and on the show_php_error() in system/core/Exceptions.php

I get my /wwwroot directory on the home page. And from the function above, the path to the folder where Apache was installed.

Does anyone know what went wrong?




Theme © iAndrew 2016 - Forum software by © MyBB