CI2 to CI3: Call to a member function helper() on a non-object in ...Session.php - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: CI2 to CI3: Call to a member function helper() on a non-object in ...Session.php (/showthread.php?tid=61901) |
CI2 to CI3: Call to a member function helper() on a non-object in ...Session.php - dimas - 05-29-2015 While migrating from CI 2 to CI 3 I stucked with this error: Code: Call to a member function helper() on a non-object in \system\libraries\Session.php The complete Call Stack: Code: # Time Memory Function Location The error is generated from a controller Controller_A like this: PHP Code: class Controller_A extends CI_Controller And the Plan_Events class is defined like this (without own constructor): PHP Code: class Plan_Events extends CI_Controller { ... } ¿Any idea? RE: CI2 to CI3: Call to a member function helper() on a non-object in ...Session.php - Narf - 05-29-2015 Yes, you must replace the system/ directory, not just copy-paste over it. That means delete the old one first and then put in the new one. RE: CI2 to CI3: Call to a member function helper() on a non-object in ...Session.php - Narf - 05-29-2015 https://github.com/bcit-ci/CodeIgniter/commit/e3216319e56de5e4214e5fec04af5bebaa593d0c RE: CI2 to CI3: Call to a member function helper() on a non-object in ...Session.php - dimas - 06-01-2015 Thx, that solved the previous error but now I've a new one: Code: Unable to locate the specified class: Session.php If I comment the new Plan_Events() line the error is gone, so the problem seems to be related to the own class extending CI_Controller. As I quoted at the first post the Plan_Events class only extends the CI_Controller class and have some public functions using CI models. It doesn't use sessions. Hints please... RE: CI2 to CI3: Call to a member function helper() on a non-object in ...Session.php - mwhitney - 06-01-2015 A class extending CI_Controller can't load another class which also extends CI_Controller. You will probably need to replace the second controller with a library. RE: CI2 to CI3: Call to a member function helper() on a non-object in ...Session.php - dimas - 06-01-2015 I tried to overwrite the CI_Controller construct method inside the Plan_Events class with an empty constructor and now it works! PHP Code: class Plan_Events extends CI_Controller { Is it a desired Behaviour? RE: CI2 to CI3: Call to a member function helper() on a non-object in ...Session.php - dimas - 06-01-2015 (06-01-2015, 08:52 AM)mwhitney Wrote: A class extending CI_Controller can't load another class which also extends CI_Controller. You will probably need to replace the second controller with a library. This is a CI 3.x change? It worked well with CI 2.x. I didn't see nothing at the CI 3 upgrade guide. RE: CI2 to CI3: Call to a member function helper() on a non-object in ...Session.php - mwhitney - 06-01-2015 If it works, it never should have been a controller in the first place. If you remove the "extends CI_Controller" portion and move the file to /application/libraries/, you could load it using $this->load->library() instead of using require_once(). However, if you were using that file as a controller somewhere else on your site, you probably already broke it by removing the base constructor. RE: CI2 to CI3: Call to a member function helper() on a non-object in ...Session.php - dimas - 06-02-2015 (06-01-2015, 09:02 AM)mwhitney Wrote: However, if you were using that file as a controller somewhere else on your site, you probably already broke it by removing the base constructor.You are right, I went too fast, it doesn't work (06-01-2015, 09:02 AM)mwhitney Wrote: A class extending CI_Controller can't load another class which also extends CI_Controller. You will probably need to replace the second controller with a library. It worked with CI2, in my opinion it should be noted in CI3 the upgrade guide. I don't know how to transform this class to a library. I changed the Plan_Events class to not extend the CI_Controller but assigning a CI instance because I need to use the CI models, now it seems to work: PHP Code: class Plan_Events { PHP Code: class Controller_A extends CI_Controller Thx for the support RE: CI2 to CI3: Call to a member function helper() on a non-object in ...Session.php - mwhitney - 06-02-2015 If you're using the controller elsewhere, I would just leave it as a controller, then extract the functionality that needs to be available in other locations into a library (to be called by all of the controllers which need it). Storing the CI instance in a property as you've done is fairly common practice in CI libraries when the instance is needed for multiple calls. However, if you're using it to access data, you may want to consider creating a model instead of a library. As far as I know, calling a model within a model is not an issue. Apparently being able to load a controller within a controller wasn't intended to work, and certainly wasn't a documented feature, which is why it's not mentioned in the upgrade guide. Besides, even though it appeared to work, there are some interesting bugs related to loading a controller from another controller in CI2 which are difficult to track down and nearly impossible to fix (without replacing the loader and/or controller). |