[SOLVED]Problem with routing from a method to another controller - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: [SOLVED]Problem with routing from a method to another controller (/showthread.php?tid=518) |
[SOLVED]Problem with routing from a method to another controller - g3n1u5 - 12-13-2014 Hello guys, as I picked CodeIgniter I decided to make a small project, now I have a problem with routing, I have some pages, made step by step from the tutorial: I have home and addmovie as pages. PHP Code: $route['default_controller'] = 'pages/view'; The url I am giving the form is the base url of the page PHP Code: echo validation_errors(); And now I have another Controller called Movies.php in which there is a function called add which should control the information from the form and eventually add the information to the database. The problem is I dont know how to route the files in a way that when the submit button is pressed it should redirect the form to use the method from Movies.php/add ( controller/method) ! I tried $route['pages/view/addmovie'] = 'movies/add'; but it doesnt work, and I am pretty sure there is a problem with my logic. Best regards g3n1u5! RE: Problem with routing from a method to another controller - InsiteFX - 12-13-2014 The route (:any) needs to be the last route in your routes file, any routes after that will not work because it is a catch all route. Code: redirect('movies/add'); To update etc; You need to also pass the id of the record to the method. RE: Problem with routing from a method to another controller - g3n1u5 - 12-13-2014 It's not working! PHP Code: $route['default_controller'] = 'pages/view'; I tried all. Sorry if I am doing wrong or I did not understand. I am trying just to make the form to reload at the same page, and if there is an error the validation_error() is echoed if not some success message is outputted. The action attr is set to PHP Code: <form action="http://localhost/ci/addmovie" class="col-sm-4" role="form" method="post" accept-charset="utf-8"> I managed to make it working by redirecting to another page ( as shown above - movies/add ) but I'd like to know if I can make it reload the same page. I don't want unnecessary reloads. P.S. addmovie.php from the view PHP Code: <!-- Main page content --> movies.php - controller PHP Code: <?php Pages.php - controller PHP Code: <?php Don't mind some unnecessary attributes and methods, its for learning purposes only Best regards, g3n1u5! RE: Problem with routing from a method to another controller - InsiteFX - 12-13-2014 If you look at your routes file you have 2 routes with (:any) As I stated before the any is a catch all route any route after that will not be seen! Note: Routes will run in the order they are defined. Higher routes will always take precedence over lower ones. Do you have a separate movie controller and page controller? Code: $route['default_controller'] = 'pages'; RE: Problem with routing from a method to another controller - g3n1u5 - 12-13-2014 The last any is necessary for the web app to work. The $route['(:any)/addmovie'] = "movies/add"; is irrelevant, it doesn't work with or without. RE: Problem with routing from a method to another controller - g3n1u5 - 12-13-2014 Fixed it by putting everything in that method and managing it with bunch of ifs! Best regards, g3n1u5 |