Skip to content
Advertisement

Parameter passing through routing problem in Codeigniter 4

I have a little routing problem, that i can’t solve in Codeigniter 4. I try adding a parameter at deleting list item. But get the following error messages.

Error message at post routing: Controller or its method is not found: AppControllersUserfeed::delete

Error message at add or get routing: Controller or its method is not found: AppControllersPages::index

controllers file directory: controller_directory

the relevant part of the Route file (it’s in the Config directory):

$routes->get('/', 'Pages/Home::index');
$routes->get('userfeed', 'Pages/UserFeed::index');
$routes->post('userfeed/add', 'Pages/UserFeed::add');

//$routes->add('userfeed/(:any)', 'Pages/UserFeed::delete');//this works fine
$routes->get('userfeed/(:any)', 'Pages/UserFeed::delete');//this works fine
//$routes->get('userfeed/(:any)', 'Pages/UserFeed::delete/$1');//this is not work, which is the goal
//$routes->post('userfeed/(:any)', 'Pages/UserFeed::delete/$1');//this is not work
//$routes->add('userfeed/(:any)', 'Pages/UserFeed::delete/$1');//this is not work
...

the relevant part of the controller:

namespace AppControllersPages;
use AppControllersMainCtrl;
...
class UserFeed extends MainCtrl{ 
....
public function delete($id=FALSE)
    {
        var_dump('wooot?');
        var_dump($id);
    }
} 

the view part:

....
<a class="badge badge-secondary" href="<?php echo base_url('userfeed/delete/'.$rss['id']);?>" >Töröl</a>
....

But if i make a copy from this controller in the root controller directory, it’s working.

$routes->get('userfeed/delete/(:any)', 'UserFeed2::delete/$1');//it's working fine

If need more information let it with me know. Thanks your help! 🙂

Note: Thank God, found the problem. 🙂
And one guess, one reward. =)

Advertisement

Answer

Try this one

$routes->get('userfeed/delete/(:any)', 'PagesUserFeed::delete/$1');

The difference is the slash used. You must use a backslash () not forward (/)

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement