Welcome Guest, Not a member yet? Register   Sign In
BaseController & __construct
#1

(This post was last modified: 05-12-2020, 02:10 PM by jreklund.)

Hi

I have a controller that extends BaseController.

I also need to execute some code in the controllers __construct method.

The __construct gets called before the initController function in the BaseController.

Is there a "2ndary" controller init that I can use that will get called after initController ?

PS. I don't want to start using Filters for this.

PHP Code:
class BaseController extends Controller
{
    public function initController()
    {
        
echo 'basecontroller init<br/>';
        
// ..........


class Search extends BaseController
{
    public function __construct()
    {
        echo 'search __construct<br/>';
        
//......... 

OUTPUT:
search __construct
basecontroller init
Reply
#2

(This post was last modified: 05-12-2020, 02:14 PM by jreklund.)

You can create your own initController() in your Search class.

PHP Code:
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
    
parent::initController($request$response$logger);

    
// Your code here

Reply




Theme © iAndrew 2016 - Forum software by © MyBB