• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
load Controller in Controller, CI3

#1
hi
I can't load controller in another controller in CI3, but in CI2 i do this without problem!!!
for test plz create MY_Controller in core and load a test library or model or etc
then in welcome controller or each controller you want, load another controller like my codes then see errors, i cant know why this doesn't work in CI3 plz help me Sad

and other question why CI2 benchmark is very better than CI3? it isn't bad? do you recommended me for use CI2?

"please sorry if you found any mistake in my english"

---

MY_Controller:
PHP Code:
class MY_Controller extends CI_Controller
{
    public function 
__construct()
    {
        
parent::__construct();

        
$this->load->library('cart'); // any library or model you like, you can load
    
}


and this is my welcome controller
PHP Code:
defined('BASEPATH') OR exit('No direct script access allowed');

class 
Welcome extends MY_Controller {

    public function 
index()
    {
        
$this->load->library('../controllers/_404');
        
$this->_404->index();
    }


and my _404 controller
PHP Code:
defined('BASEPATH') OR exit('No direct script access allowed');

class 
_404 extends MY_Controller
{
    public function 
index()
    {
        echo 
'404';
    }

Reply

#2
Not sure if I understand your problem correctly, but I was able to load controller where ever I wan't without errors in CI3 too after I moved most of the autoload stuff to MY_Controller instead autoload config. If Session, Form_validation, Pagination etc. are in autoload, you get bunch of different errors.

http://www.jammeri.com/post/loading-cont...igniter-30
Reply

#3
Why on earth would you want to do something like this?
Practical guide to IgnitedCMS - Book coming soon
Reply

#4
for custom 404 error page i would do this
Reply

#5
(08-03-2015, 12:21 PM)zeos Wrote: for custom 404 error page i would do this

Why wouldn't you use show_404() or the 404_override route?
Reply

#6
(07-31-2015, 11:30 AM)Jammyman Wrote: Not sure if I understand your problem correctly, but I was able to load controller where ever I wan't without errors in CI3 too after I moved most of the autoload stuff to MY_Controller instead autoload config. If Session, Form_validation, Pagination etc. are in autoload, you get bunch of different errors.

http://www.jammeri.com/post/loading-cont...igniter-30

The link you gave is broken. Please update.
Reply

#7
(09-20-2019, 04:18 PM)tatarespecia Wrote: The link you gave is broken. Please update.

I trust you realize this is a 4 year old thread. Jammyman hasn't been active on the forum since early 2016, so you might have a long wait for a reply.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.