Welcome Guest, Not a member yet? Register   Sign In
passing name instead of id
#1

(This post was last modified: 10-28-2019, 03:36 AM by manigopal.)

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...r/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...r/Showtime
Reply
#2

What's the error message you get, or the unexpected results?
Reply
#3

(10-24-2019, 05:05 AM)Wouter60 Wrote: What's the error message you get, or the unexpected results?


Page not found error.
Reply
#4

(This post was last modified: 10-24-2019, 06:28 AM by Wouter60.)

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.
Reply
#5

(This post was last modified: 10-25-2019, 10:29 AM by manigopal.)

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
Reply
#6

@Wouter60 i have updated code & error which i get.
Reply
#7

(This post was last modified: 10-26-2019, 12:04 AM by manigopal. Edit Reason: Added Pagination )

After adding Pagination to controller file,

Movies_genre.php

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Movies_genre extends CI_Controller {
    function 
__construct()
    {
        parent::__construct();
        $this->load->model('Model_common');
        $this->load->model('Model_movie_genre');
        //$this->load->model('Model_portfolio');
    }

    public function 
index($genre_type=NULL)
    {
        
/*if( !isset($id) || !is_numeric($id) ) {
            redirect(base_url());
        }*/

        
$tot $this->Model_movie_genre->genre_check($genre_type);
        if(!
$tot) {
            
redirect(base_url());
        }


        
$data['general_settings'] = $this->Model_common->general_settings();
        
$data['page_movies_genre'] = $this->Model_common->page_movies_genre();
        
$data['social_settings'] = $this->Model_common->social_settings();
        
        
$data['movies_by_genre'] = $this->Model_movie_genre->movies_by_genre($genre_type);
        
$data['genre_by_name'] = $this->Model_movie_genre->genre_by_name($genre_type);

        
//$data['portfolio_footer'] = $this->Model_portfolio->get_portfolio_data();

        
$this->load->library('pagination');

        
$config = array();
        
$config['full_tag_open']    '<div class="pagging text-center"><nav><ul class="pagination">';
    
    $config['full_tag_close']   '</ul></nav></div>';
    
    $config['num_tag_open']     '<li class="page-item"><span class="page-link">';
    
    $config['num_tag_close']    '</span></li>';
    
    $config['cur_tag_open']     '<li class="page-item active"><span class="page-link">';
    
    $config['cur_tag_close']    '<span class="sr-only">(current)</span></span></li>';
    
    $config['next_tag_open']    '<li class="page-item"><span class="page-link">';
    
    $config['next_tag_close']  '<span aria-hidden="true"></span></span></li>';
    
    $config['prev_tag_open']    '<li class="page-item"><span class="page-link">';
    
    $config['prev_tag_close']  '</span></li>';
    
    $config['first_tag_open']   '<li class="page-item"><span class="page-link">';
    
    $config['first_tag_close'] = '</span></li>';
    
    $config['last_tag_open']    '<li class="page-item"><span class="page-link">';
    
    $config['last_tag_close']  '</span></li>';

        $config["base_url"] = base_url() . "movies/genre";
        $config["total_rows"] = $this->Model_movie_genre->movies_by_genre($genre_type);
        $config['first_url'] = base_url() . 'movies/genre';
        $config["per_page"] = 18;
        $config["uri_segment"] = 3;
        $config['use_page_numbers'] = TRUE;
        //$config['page_query_string'] = TRUE;

        $this->pagination->initialize($config);

        $offset = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data['movies_fetched'] = $this->Model_movie_genre->movies_by_genre($genre_type$config["per_page"], $offset);
        $data["links"] = $this->pagination->create_links();


        
$this->load->view('view_header',$data);
        
$this->load->view('view_movies_genre',$data);
        
$this->load->view('view_footer',$data);
    }



Model page,

Model_movie_genre.php
PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Model_movie_genre extends CI_Model 
{
    public function 
movies_by_genre($genre_type)
    {
        
$query $this->db->query("SELECT * FROM movies_info WHERE movie_genre=? ORDER BY movie_id DESC", array('movie_genre'=>$genre_type));
        return 
$query->result_array();
    }

    public function 
genre_by_name($genre_type)
    {
        
$query $this->db->query("SELECT * FROM genre_info WHERE genre_type=?", array('genre_type'=>$genre_type));
        return 
$query->first_row('array');
    }

    public function 
genre_check($genre_type) {
        
$sql 'SELECT * FROM genre_info WHERE genre_type=?';
        
$query $this->db->query($sql,array('genre_type'=>$genre_type));
        return 
$query->num_rows();
    }


View page,

view_movies_genre.php
PHP Code:
<!-- /w3l-medile-movies-grids -->
    <
div class="general-agileits-w3l">
        <
div class="w3l-medile-movies-grids">

                <!-- /
movie-browse-agile -->
                
                      <
div class="movie-browse-agile">
                         <!--/
browse-agile-w3ls -->
                        <
div class="browse-agile-w3ls general-w3ls">
                                <
div class="tittle-head">
                                
                                <
h4 class="latest-text">
                                    <?
php //echo $movies_by_genre['movie_id'];?> 
                                    <?php //echo $movies_by_genre->movie_id; ?>
                                    <?php //echo $genre_type; ?>
                                    <?php foreach($movies_by_genre as $row) { 
                                        echo 
$row->movie_id;
                                        }
                                        
?>
                                </h4>
                                    <div class="container">
                                        <div class="agileits-single-top">
                                            <ol class="breadcrumb">
                                            
                                              <li><a href="">Home</a></li>
                                              <li class="active" style="text-transform:Capitalize;">
                                                  <?php //echo $movies_by_genre['movie_genre'];?>
                                                  <?php //echo $genre_type; ?>
                                              </li>
                                            </ol>
                                        </div>
                                    </div>
                                </div>
                                     <div class="container">
                            <div class="browse-inner">
                                
                                <?php 
                            
foreach($movies_by_genre as $row) { 
                            
?>    
                               <div class="col-md-2 w3l-movie-gride-agile"> 
                                         <a href="<?php echo base_url(); ?>movie/<?php echo $row->movie_id?>" class="hvr-shutter-out-horizontal">
                                             <img src="<?php echo base_url(); ?>/public/images/movies/<?php echo $row->movie_image?>" title="<?php echo $row->movie_name?>" alt=" " />
                                         <div class="w3l-action-icon"><i class="fa fa-play-circle" aria-hidden="true"></i></div>
                                    </a>
                                      <div class="mid-1">
                                        <div class="w3l-movie-text">
                                            <h6><a href="<?php echo base_url(); ?>movie/<?php echo $row->movie_id?>">
                                                <?php echo $row->movie_name?></a></h6>                            
                                        </div>
                                        <div class="mid-2">
                                        
                                            <p><?php echo $row->release_year?></p>
                                            <div class="block-stars">
                                                <ul class="w3l-ratings">
                                                         
                                                         <li> 
                                                          <span>IMDB <i class="fa fa-star" aria-hidden="true"></i> 
                                                              <?php echo $row->movie_rating?> 
                                                          </span>
                                                         </li>
                                        
                                                </ul>
                                            </div>
                                            <div class="clearfix"></div>
                                        </div>
                                            
                                    </div>
                                     <div class="ribben two">
                                        <p>NEW</p>
                                    </div>    
                                    </div> 
                                    <?php ?>
                                    
                                    <div class="clearfix"> </div>
                                </div>
                                
                            
                                </div>
                        </div>
                <!--//browse-agile-w3ls -->
                        <!-- <div class="blog-pagenat-wthree">
                            <ul>                                        
                                    
                                    <?php
                                    
// display the links to the pages
                                    //for($page=1;$page<=$number_of_pages;$page++){
                                        //echo '<a href="movies.php?page=' . $page . '">' . $page . '</a> ';
                                    
                                /* <li><a class="frist" href="#">Prev</a></li> */
                                    /*echo '<li><a href="movies-genre.php?genre_type='.$_REQUEST['genre_type'].'&page=' . $page . '">' . $page . '</a></li>';
                                }*/
                                    
?> -->
                                <!--<li><a href="#">2</a></li>
                                <li><a href="#">3</a></li>
                                <li><a href="#">4</a></li>
                                <li><a href="#">5</a></li>
                                <li><a class="last" href="#">Next</a></li> -->
                        <!--    </ul>
                        </div>
                    </div> -->

                    <?php echo $links?>

                    <!-- //movie-browse-agile -->
                
        </div>
    <!-- //w3l-medile-movies-grids -->
    </div>
    <!-- //comedy-w3l-agileits --> 
Reply
#8

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 
Reply
#9

(This post was last modified: 10-26-2019, 01:45 AM by manigopal.)

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
Reply
#10

Quote:Backtrace:

File: C:\xampp\htdocs\ciprojects\showtime\application\controllers\Movies_genre.php
Line: 64
Function: create_links

What is on line 64 of your controller?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB