Welcome Guest, Not a member yet? Register   Sign In
Extending controller-class to another controller-class?
#1

(This post was last modified: 07-09-2018, 12:08 AM by kaitenz.)

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.
Reply
#2

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/g...asses.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/g...uting.html)

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

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

Reply




Theme © iAndrew 2016 - Forum software by © MyBB