Adding property in all Contrellers: MY_Controller vs BaseController |
It's a matter of personal preference. The one possible reason to go with the BaseController is you can still extend CI_Controller without bringing the $controller_url property along if needed.
About the code. You have one syntax error - you're failing to set the class property in the constructor and are setting a local variable instead. PHP Code: $controller_url = config_item('base_url') . $this->uri->segment(1); should be PHP Code: $this->controller_url = config_item('base_url') . $this->uri->segment(1); In case you're interested there are other ways to get the controller. Here's one way that's a tiny bit more efficient than calling $this->uri->segment(1) PHP Code: $this->controller_url = config_item('base_url') . $this->router->class; Or, you could use the PHP magic constant __CLASS__ PHP Code: $this->controller_url = config_item('base_url') . __CLASS__; Or a not so efficient but probably more robust PHP Code: $this->controller_url = $this->config->base_url($this->router->class); |
Messages In This Thread |
Adding property in all Contrellers: MY_Controller vs BaseController - by Balenus - 12-06-2018, 05:53 AM
RE: Adding property in all Contrellers: MY_Controller vs BaseController - by dave friend - 12-06-2018, 08:13 AM
RE: Adding property in all Contrellers: MY_Controller vs BaseController - by Balenus - 12-06-2018, 08:52 AM
RE: Adding property in all Contrellers: MY_Controller vs BaseController - by dave friend - 12-06-2018, 09:07 AM
|