CodeIgniter Forums
Extending controller-class to another controller-class? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10)
+--- Thread: Extending controller-class to another controller-class? (/showthread.php?tid=71117)



Extending controller-class to another controller-class? - kaitenz - 07-08-2018

Hi,

Just out of curiosity, can I extend my controller-class with another controller-class?
I don't know what term to use but here's an example:

PHP Code:
// Location: application/controllers/Welcome.php

class Welcome extends CI_Controller
{
    
// Some code here
}

class 
Valkommen extends Welcome
{
    
// Another code here


If this is possible, maybe I can use this technique in the future.
Thank you.


RE: Extending controller-class to another controller-class? - Pertti - 07-09-2018

Yes, you can extend core CI_Controller, then make your controllers use your new extended controller class.

Some more information over here:
https://www.codeigniter.com/user_guide/general/core_classes.html

From your example I guess you were looking to use same controller code for different URL? You can do that via routing (https://www.codeigniter.com/user_guide/general/routing.html)

PHP Code:
$route['valkommen'] = 'welcome/index/se'

PHP Code:
class Welcome extends CI_Controller
{
    public function 
index($language 'en')
    {
        
// ...
    
}