CodeIgniter Forums
Potential Bug Report: Presenter::show(id) Overwrites Custom Functions - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Potential Bug Report: Presenter::show(id) Overwrites Custom Functions (/showthread.php?tid=91063)



Potential Bug Report: Presenter::show(id) Overwrites Custom Functions - MZahov - 06-12-2024

When using CodeIgniter 4, the Presenter show(id) method appears to overwrite custom functions that I have added. This results in a 404 error when trying to access these functions, with the message:

Code:
{
    "status": 404,
    "error": 404,
    "messages": {
        "error": "Nothing found for customFunction1."
    }
}

However, if I configure the routes in Routes.php to exclude the show method using ['except' => 'show'], the custom functions work correctly.

PHP Code:
$routes->presenter('example', ['except' => 'show''filter'=> 'jwt''namespace' => '\App\Controllers\Api']);

$routes->group('example', ['filter'=>'jwt''namespace'=>'\App\Controllers\Api'], static function($routes) {
    $routes->get('customFunction1''Example::customFunction1');
    $routes->get('customFunction2''Example::customFunction2');

}); 

How to exclude only example/(;segment). So additional functions will not be overwritten. Any suggestions?

Code:
+--------+-------------------------+--------------------+--------------------------------------------------------------------+----------------+---------------+
| Method | Route                  | Name              | Handler                                                            | Before Filters | After Filters |
+--------+-------------------------+--------------------+--------------------------------------------------------------------+----------------+---------------+
| GET    | example/(.*)           | »                 | \App\Controllers\Api\Example::show/$1                              | jwt            | jwt           |



https://codeigniter.com/user_guide/incoming/restful.html#presenter-controller-comparison


RE: Potential Bug Report: Presenter::show(id) Overwrites Custom Functions - kenjis - 06-12-2024

Define the routes for the custom functions before calling the `$routes->presenter('example', ...)`.


RE: Potential Bug Report: Presenter::show(id) Overwrites Custom Functions - MZahov - 06-12-2024

(06-12-2024, 02:47 AM)kenjis Wrote: Define the routes for the custom functions before calling the `$routes->presenter('example', ...)`.
Thanks. Feeling stupid that I didn't move it Smile