Welcome Guest, Not a member yet? Register   Sign In
CI4 Modules Routing
#1

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?
Reply
#2

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

}
Reply
#3

(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?
Reply
#4

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

}
Reply
#5

(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
Reply
#6

(This post was last modified: 04-04-2020, 12:57 PM by lomali.)

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

Attached Files Thumbnail(s)
   
Reply
#7

(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');
Reply
#8

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

this is the solution . Thanks a lot!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB