CodeIgniter Forums
CI4 Modules Routing - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: CI4 Modules Routing (/thread-75990.html)



CI4 Modules Routing - lomali - 04-04-2020

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:Confusedhow

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?


RE: CI4 Modules Routing - lomali - 04-04-2020

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;
}

}


RE: CI4 Modules Routing - mjamilasfihani - 04-04-2020

(04-04-2020, 09:45 AM)lomali Wrote: 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:Confusedhow

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?

Can you show how do you call the model?


RE: CI4 Modules Routing - lomali - 04-04-2020

(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 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:Confusedhow

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?

Can you show how do you call the model?

<?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;
}

}


RE: CI4 Modules Routing - mjamilasfihani - 04-04-2020

(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 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:Confusedhow

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?

Can you show how do you call the model?

<?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;
}

}

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


RE: CI4 Modules Routing - lomali - 04-04-2020

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:Confusedhow');
});


and the autoload.php shows like this picture


RE: CI4 Modules Routing - davis.lasis - 04-04-2020

(04-04-2020, 12:45 PM)lomali Wrote: 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:Confusedhow');
});


and the autoload.php shows like this picture


$routes->add('show/(:num)', 'Users:Confusedhow/$1');


RE: CI4 Modules Routing - lomali - 04-04-2020

$routes->add('show/(:num)', 'Users:[Image: confused.png]how/$1');

this is the solution . Thanks a lot!