J
J
jack iakovenko2020-11-26 01:43:34
CodeIgniter
jack iakovenko, 2020-11-26 01:43:34

What is wrong with the code in Codeigniter?

can someone help me what's wrong with my code? I have an online movie website
with a database with three separate tables - films, series, animation
so on the main page of the portal it displays information from the database, films and series are also displayed, but the code makes the view page there already with serials error
here are the page codes:
Films_model model code

<?php
class Films_model extends CI_Model {

    public function __construct() {
        $this->load->database();
    }

    public function getFilms($slug = FALSE, $limit, $type = 1) {
        if($slug === FALSE) {
            $query = $this->db
                ->where('category_id', $type)
                ->order_by('add_date')
                ->limit($limit)
                ->get('movie');

            return $query->result_array();    
        }

        $query = $this->db->get_where('movie', array('slug'=>$slug));
        return $query->row_array();
    }

    public function getFilmsByRating($limit) {
        $query = $this->db
            ->order_by('rating', 'desc')
            ->where('category_id', 1)
            ->where('rating>', 0)
            ->limit($limit)
            ->get('movie');

        return $query->result_array();    
    }
}

and this is the code of the Serials_model model
<?php

class Serials_model extends CI_Model {

    public function __construct() {
        $this->load->database();
    }
    
    public function getSerials($slug = FALSE, $limit, $type = 2) {
        if($slug === FALSE) {
            $query = $this->db
                ->where('category_id', $type)
                ->order_by('add_date', 'desc')
                ->limit($limit)
                ->get('serial');

            return $query->result_array();
        }

        $query = $this->db->get_where('serial', array('slug'=>$slug));
        return $query->row_array();
    }

}


this is the Movies controller code
<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Movies extends MY_Controller {

    public function __construct() {
        parent::__construct();
    }

    public function type($slug = NULL) {
        $this->data['movie_data'] = NULL;

        if($slug == "films") {
            $this->data['title'] = "Movies";
            $this->data['movie_data'] = $this->films_model->getFilms(false, 10, 1);
        }

        $this->load->view('templates/header', $this->data);
        $this->load->view('movies/type', $this->data);
        $this->load->view('templates/footer');
    }

    public function view($slug = NULL) {

        $movie_slug = $this->films_model->getFilms($slug, false, false);

        if(empty($movie_slug)) {
            show_404();
        }

        $this->data['title'] = $movie_slug['name'];
        $this->data['year'] = $movie_slug['year'];
        $this->data['rating'] = $movie_slug['rating'];
        $this->data['descriptions_movie'] = $movie_slug['descriptions'];
        $this->data['player_code'] = $movie_slug['player_code'];
        $this->data['director'] = $movie_slug['director'];

        $this->load->view('templates/header', $this->data);
        $this->load->view('movies/view', $this->data);
        $this->load->view('templates/footer');
    }


}


and this is the code for the Serials controller
<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Serials extends MY_Controller {

    public function __construct() {
        parent::__construct();
    }


    public function view($slug = NULL) {

        $serial_slug = $this->serials_model->getSerials($slug, false, false);

        if(empty($serial_slug)) {
            show_404();
        }

        $this->data['title'] = $serial_slug['name'];
        $this->data['year'] = $serial_slug['year'];
        $this->data['rating'] = $serial_slug['rating'];
        $this->data['descriptions_movie'] = $serial_slug['descriptions'];
        $this->data['player_code'] = $serial_slug['player_code'];
        $this->data['director'] = $serial_slug['director'];

        $this->load->view('templates/header', $this->data);
        $this->load->view('serials/view', $this->data);
        $this->load->view('templates/footer');
    }


}


and here is the error that pops up
A PHP Error was encountered
Severity: Notice

Message: Undefined property: Serials::$serials_model

Filename: controllers/Serials.php

Line Number: 14

Backtrace:

File: C:\xampp\htdocs\movieworld\application\controllers\Serials.php
Line: 14
Function: _error_handler

File: C:\xampp\htdocs\movieworld\index.php
Line: 315
Function: require_once

An uncaught Exception was encountered
Type: Error

Message: Call to a member function getSerials() on null

Filename: C:\xampp\htdocs\movieworld\application\controllers\Serials.php

Line Number: 14

Backtrace:

File: C:\xampp\htdocs\movieworld\index.php
Line: 315
Function: require_once


?>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question