Home » Php » php – How to add modular extension wiredesignz to codeigniter 3.0

php – How to add modular extension wiredesignz to codeigniter 3.0

Posted by: admin July 12, 2020 Leave a comment

Questions:

I’m trying to add third party extension to create a HMVC application using Codeigniter 3.0

But when I’m adding MY_Loader and MY_Router files into the core folder and MX folder in the Third_party folder, it generates a fatal error:

Fatal error: Call to undefined method MY_Loader::_ci_object_to_array()
in C:\xampp\htdocs\codeigniter\application\third_party\MX\Loader.php
on line 300.

When I remove them, the application works perfectly. Are there any additional settings that are needed to get the application running?

How to&Answers:

It happens because the function used in MX/Loader.php no longer exists in CodeIgniter.

You can add it back to Loader.php

protected function _ci_object_to_array($object) {
    return is_object($object) ? get_object_vars($object) : $object;
}

Source

Answer:

Open your file application/third_party/MX/Loader.php

protected function _ci_object_to_array($object) {
    return is_object($object) ? get_object_vars($object) : $object;
}

add above function in Loader class.

Answer:

On Line 300 of application/third_party/MX/Loader.php

This line generates an error with CI 3.1.3

 return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));

Replace with this line.

return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return));
}

Answer:

I’ve found the following solution

In application/third_party/MX/Loader.php you can change the following.

Under public function view($view, $vars = array(), $return = FALSE) Look for… (near about Line 300)

return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));

Replace this with

if (method_exists($this, '_ci_object_to_array'))
{
        return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
} else {
        return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return));
}

Maybe wiredesignz will soon release the update for it. In the meantime, you can implement the above fix and resume coding.

Answer:

I replace on /MX/Loader.php line 300

return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));

with

return (method_exists($this, '_ci_object_to_array') ? $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return)) : $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return)));