CI4 Modules Routing |
Hello, I'm new at CI4, but I used CI3.
I wanted to work with modules at CI4. A tutorial on Youtube helped to set everything necessary. The problem now is that the methods and variables are not recognized by the controller. This message always comes: Controller or its method is not found: App\Controllers\Users:how Users is a controller in the Users module and show is the method. The URL is http://ocanext:8888/users/show/2 If I create a controller under App/Controllers, everything works without problems. Where is the mistake?
And this is my controller:
<?php namespace Modules\Users\Controllers; //use CodeIgniter\Controller; //use CodeIgniter\API\ResponseTrait; class Users extends \CodeIgniter\Controller { //use ResponseTrait; public function index() { //return $this->respond([[1],[2]]); echo 'testme'; } public function show() { //return $this->respond($id); echo '$id'; } public function create($id) { echo $id; } public function update($id) { echo $id; } public function delete($id) { echo $id; } }
(04-04-2020, 09:45 AM)lomali Wrote: Hello, I'm new at CI4, but I used CI3. Can you show how do you call the model? (04-04-2020, 12:11 PM)mjamilasfihani Wrote:(04-04-2020, 09:45 AM)lomali Wrote: Hello, I'm new at CI4, but I used CI3. <?php namespace Modules\Users\Controllers; //use CodeIgniter\Controller; //use CodeIgniter\API\ResponseTrait; class Users extends \CodeIgniter\Controller { //use ResponseTrait; public function index() { //return $this->respond([[1],[2]]); echo 'testme'; } public function show() { //return $this->respond($id); echo '$id'; } public function create($id) { echo $id; } public function update($id) { echo $id; } public function delete($id) { echo $id; } }
(04-04-2020, 12:23 PM)lomali Wrote:(04-04-2020, 12:11 PM)mjamilasfihani Wrote:(04-04-2020, 09:45 AM)lomali Wrote: Hello, I'm new at CI4, but I used CI3. I think the problem is you haven't add Modules into app/Config/Autoload.php Also dont forget to check in app/Config/Routes.php
here is the routes.php in the modules/users/config
<?php /** * Define Users Routes */ $routes->group('users', ['namespace' => 'Modules\Users\Controllers'], function($routes) { //$routes->resource('users'); $routes->get('/', 'Users::index'); $routes->add('/show', 'Users:how'); }); and the autoload.php shows like this picture
(04-04-2020, 12:45 PM)lomali Wrote: here is the routes.php in the modules/users/config $routes->add('show/(:num)', 'Users:how/$1');
$routes->add('show/(:num)', 'Users:how/$1');
this is the solution . Thanks a lot! |
Welcome Guest, Not a member yet? Register Sign In |