passing name instead of id - 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: passing name instead of id (/showthread.php?tid=74682) |
passing name instead of id - manigopal - 10-23-2019 Hi all, I'm doing project for movies based website, i need to pass the genre_type instead of instead of ID. Web URL : showtime (dot) 22web(dot) org - and menu Movies Genre. Objective : to get the movies list based on selected genre with Pagination ., i have done it using core PHP @ showtime (dot) 22web(dot) org/movies-genre.php?genre_type=Action My code, @ https://gitlab.com/manigopal/ci-projects/tree/master/Showtime [regularly updated after every changes] Live Website @ http://cishowtime.22web.org Pagination works fine on #Movies page @ http://cishowtime.22web.org/movies Resource files of #Movies page : Model file => Model_movie.php View file => view_movies.php Controller file => Movies.php Issue on #MoviesGenre page @ http://cishowtime.22web.org/movies/genre/Action Resource files of #MoviesGenre page : Model file => Model_movie_genre.php View file => view_movies_genre.php Controller file => Movies_genre.php MVC files of Movies(which works fine) & MoviesGenre(which has issue) @ https://gitlab.com/manigopal/ci-projects/tree/master/Showtime RE: passing name instead of id - Wouter60 - 10-24-2019 What's the error message you get, or the unexpected results? RE: passing name instead of id - manigopal - 10-24-2019 (10-24-2019, 05:05 AM)Wouter60 Wrote: What's the error message you get, or the unexpected results? Page not found error. RE: passing name instead of id - Wouter60 - 10-24-2019 Your route should be: PHP Code: $route['movies/genre/(:any)'] = 'movies_genre/index/$1'; Wouldn't it be more simple if you just named your controller "Movies.php" with a function genre inside it that takes the $movie_genre as parameter? Then you don't need a route at all. RE: passing name instead of id - manigopal - 10-25-2019 is this correct to pass the value ? @Controller (Movies_genre.php) : following lines only, public function index($genre_type=NULL) $data['movies_by_genre'] = $this->Model_movie_genre->movies_by_genre($genre_type); I have Error received : A PHP Error was encountered Severity: Notice Message: Undefined index: movie_genre Filename: views/view_movies_genre.php Line Number: 13 Backtrace: File: C:\xampp\htdocs\ciprojects\showtime\application\views\view_movies_genre.php Line: 13 Function: _error_handler File: C:\xampp\htdocs\ciprojects\showtime\application\controllers\Movies_genre.php Line: 36 Function: view File: C:\xampp\htdocs\ciprojects\showtime\index.php Line: 315 Function: require_once A PHP Error was encountered Severity: Notice Message: Trying to get property of non-object Filename: views/view_movies_genre.php Line Number: 14 Backtrace: File: C:\xampp\htdocs\ciprojects\showtime\application\views\view_movies_genre.php Line: 14 Function: _error_handler File: C:\xampp\htdocs\ciprojects\showtime\application\controllers\Movies_genre.php Line: 36 Function: view File: C:\xampp\htdocs\ciprojects\showtime\index.php Line: 315 Function: require_once RE: passing name instead of id - manigopal - 10-25-2019 @Wouter60 i have updated code & error which i get. Added Pagination - manigopal - 10-25-2019 After adding Pagination to controller file, Movies_genre.php PHP Code: <?php Model page, Model_movie_genre.php PHP Code: <?php View page, view_movies_genre.php PHP Code: <!-- /w3l-medile-movies-grids --> RE: passing name instead of id - Wouter60 - 10-26-2019 Your model returns $query->result_array(); The result is an array with each record as an associative array. To address an element in this array, you have to use: PHP Code: $row['genre_type'] If your model would return $query->result(); then each record as an object. Elements are then addressed by: PHP Code: $row->genre_type RE: passing name instead of id - manigopal - 10-26-2019 Hi @Wouter60 i have also added #pagination does this is right ? ; $data['movies_fetched'] = $this->Model_movie_genre->movies_by_genre($genre_type, $config["per_page"], $offset); An uncaught Exception was encountered Type: Error Message: Unsupported operand types Filename: C:\xampp\htdocs\ciprojects\showtime\system\libraries\Pagination.php Line Number: 412 Backtrace: File: C:\xampp\htdocs\ciprojects\showtime\application\controllers\Movies_genre.php Line: 64 Function: create_links File: C:\xampp\htdocs\ciprojects\showtime\index.php Line: 315 Function: require_once RE: passing name instead of id - Wouter60 - 10-26-2019 Quote:Backtrace: What is on line 64 of your controller? |