![]() |
How to use parameter in redirect function - 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: How to use parameter in redirect function (/showthread.php?tid=78602) |
How to use parameter in redirect function - waleed - 02-12-2021 As in CI4 redirect works like return redirect()->route(). I want to know How I can use a variable in redirect. When I'm using simple route in redirect. It works. Like Route: $routes->get('about-us', 'Main::about_us'); return redirect('about-us') Its work fine. But when I use parameter in redirect it shows an error. i.e (route cannot be found while reverse-routing.) $studentid is some string. return redirect('Student/ViewStudentProfile/'.$studentid'); I have also tried with route but not working. return redirect()->route('Student/ViewStudentProfile/'.$studentid) ; My route is $routes->get('Student/ViewStudentProfile/(:any)' , 'backend/Student_Controller::ViewStudentProfile'); I have spend a lot of time but not found any solution. Any help would be greatly appreciated. RE: How to use parameter in redirect function - InsiteFX - 02-12-2021 PHP Code: $routes->get('Student/ViewStudentProfile/(:any)' , 'backend/Student_Controller::ViewStudentProfile'); RE: How to use parameter in redirect function - neoneeco - 02-13-2021 Hi ! try this : return redirect()->to(base_url('student/viewStudentProfile/'.$studentid)); RE: How to use parameter in redirect function - ikesela - 02-13-2021 make sure to name the route : EXAMPLE: Code: //ROUTE or maybe can try: redirect()->route('route_name',$param) RE: How to use parameter in redirect function - waleed - 02-15-2021 (02-13-2021, 03:37 AM)neoneeco Wrote: Hi ! Yes works fine. Thanks. There is any way to use with only redirect(). |