Construct this object by extending the basic Controller class
public __construct ( ) |
class AdminController { private $model; public function __construct() { $this->model = new AdminModel(); } public function index() { $data = $this->model->getUsers(); // render view with $data } }
class AdminController { private $userRepository; public function __construct(UserRepository $userRepository) { $this->userRepository = $userRepository; } public function index() { $data = $this->userRepository->getAll(); // render view with $data } }This example injects a UserRepository object into the constructor of the AdminController class. The index() method then uses the $userRepository property to fetch a list of users and renders a view with that data. Package/Library: This example appears to be using a custom package/library that defines the UserRepository class.