Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter Datamapper ORM php 7 static issue

When I upgraded my server to php7 codeigniter and in particular datamapper ORM gives me this error...

Message: Accessing static property DataMapper::$config as non static
Filename: libraries/datamapper.php Line Number: 6474

the function in question is...

protected function _dmz_assign_libraries()
{
    static $CI;
    if ($CI || $CI =& get_instance())
    {
        // make sure these exists to not trip __get()
        $this->load = NULL;
        $this->config = NULL;
        $this->lang = NULL;
        // access to the loader
        $this->load =& $CI->load;
        // to the config
        $this->config =& $CI->config;
        // and the language class
        $this->lang =& $CI->lang;
    }
}
like image 636
galipmedia Avatar asked Jun 12 '17 02:06

galipmedia


People also ask

What is DataMapper in CodeIgniter?

You will be redirected to his documentation website . DataMapper is an Object Relational Mapper written in PHP for CodeIgniter. It is designed to map your Database tables into easy to work with objects, fully aware of the relationships between each other. Everything is an object!

What's new in DataMapper Orm?

If you are an existing Datamapper ORM user, you will find changes in new releases and upgrade instructions . Note: Datamapper ORM is now also available as a CI Spark: check out the cool way of extending CodeIgniter at getsparks.org!

What happened to Phil DeJarnett's DataMapper Orm?

After Phil had indicated he no longer had the time available to support his OverZealous Edition, Datamapper ORM is now being developed and maintained by WanWizard. This came from a desire to continue to enhance and develop DataMapper, and has been developed and maintained by Phil DeJarnett.

What are the new features of DataMapper?

Some of the enhancements to the original DataMapper include: In-table foreign-keys for singular relationships. The ability to view, edit, and query using extra columns on relationship join tables. The ability to include data from singularly related objects. The ability to query and include data from deep relationships.


2 Answers

I have the same problem. To fix it, try to add new protected static method

protected static function get_config_object() {
    $CI =& get_instance();

    return $CI->config;
}

then delete or comment the lines 6474 and 6481 (in _dmz_assign_libraries, where values are assigned to $this->config),

and finally replace all calls $this->config with self::get_config_object()

It should run correctly now.

like image 129
Andrej Jursa Avatar answered Oct 02 '22 04:10

Andrej Jursa


Try to suppress error with @, eg:

@$this->config =& $CI->config;
like image 33
TomoMiha Avatar answered Oct 02 '22 04:10

TomoMiha