Calling module controller function from page formulary in CodeIgniter 4.1 HMVC

192 views Asked by At

I'm working in an application HMVC CodeIgniter 4.1, all the routes work fine in navigator:

Navigator adress: http://localhost/myapp/public/index.php/installation/shop-data

My module Routes file contains:

$routes->group("installation", ["namespace" => "\Modules\Installation\Controllers"], function ($routes) {

    //Example URL: /installation/shop-data
    $routes->get("shop-data", "InstallationController::shop_data");
    $routes->get("shop-data-post", "InstallationController::shop_data_post");

});

shop_data_post is the function in which I insert the data to the database from the page Form using this:

echo form_open("installation/shop-data-post");

But I obtain this 404 error:

Controller or its method is not found: \App\Controllers\Installation::shop-data-post

How can I get my function correctly from my page formulary?

Thanks

1

There are 1 answers

0
ketter On BEST ANSWER

Ok finally I have solved this..

All that I must did was change my module Installation Routes file so:

This line:

$routes->get("shop-data-post", "InstallationController::shop_data_post");

For this:

$routes->match(["get", "post"], "shop-data-post", "InstallationController::shop_data_post");

The error was on the route request method. It must be POST for process the Form data