Repository Pattern in CodeIgniter 4 |
How to apply, for example, Repository Pattern (or other pattern) in CodeIgniter 4, is it possible?
(04-04-2022, 06:23 AM)iRedds Wrote: What do you mean? I couldn't implement in my controller, which extends from ResourceController or BaseController... I tried in the __construct method and in the index to use like this: TesteRepositoryInterface $testeRepository I have already created the files below: App\Models\TesteModel App\Repositories\AbstractRepository App\Interfaces\TesteRepositoryInterface Where the TesteRepository class extends AbstractRepository implements TesteRepositoryInterface, but I get an error like this: ArgumentCountError Too few arguments to function App\Controllers\TesteController::__construct(), 0 passed in /home/fabiano/api/vendor/codeigniter4/framework/system/CodeIgniter.php on line 809 and exactly 1 expected (04-04-2022, 07:54 AM)fsouzaweb Wrote: I tried in the __construct method and in the index to use like this: TesteRepositoryInterface $testeRepository Why do you inject it? There is no functionality to inject an object to a controller automatically in CI4. If you really want to do it, you need to extend the framework. Add a DI container you like when the framework creates a controller. This is my example: https://github.com/kenjis/ci4-tettei-app...er.php#L11 https://github.com/kenjis/ci4-tettei-app...es.php#L34 |
Welcome Guest, Not a member yet? Register Sign In |