Welcome Guest, Not a member yet? Register   Sign In
Plain Controller, without extending BaseController ??
#1
Information 

Just want to know if it is possible to have a plain controller class without extending the base controller ?? or without initController() ?? with my own dependency injection in __constuct() ??

I'm doing a test to see if I my plain controller class can be used by other frameworks. It looks something like this:

Code:
<?php

namespace MyPackage\Controller;

use MyPackage\RequestInterface as Request;
use MyPackage\ResponseInterface as Response;

class HealthController
{
    public function __construct(
        public Request $request,
        public Response $response,
    ) {
    }

    public function index()
    {
        $data = [
            'status' => true,
            'queries' => $this->request->allQueries(),
        ];

        return $this->response->setJson($data)
            ->setStatusCode(200)
            ->respond();
    }
}
Reply
#2

Probably possible if you extend the CodeIgniter::createController() method.

See
- https://github.com/kenjis/ci4-tettei-app...gniter.php
- https://github.com/kenjis/ci4-tettei-app...hp#L34-L43
Reply




Theme © iAndrew 2016 - Forum software by © MyBB