Как исправить ошибку a php error was encountered?

1

Не знаю как исправить ошибку с неопределенным индексом

урок 17-18 при реализации страницы просмотра фильма , вылезает ошибка , связанная с этой строкой кода 

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

 и вылезает такая ошибка:

A PHP Error was encountered
Severity: Notice

Message: Undefined index: name

Filename: controllers/Movies.php

Line Number: 17

Backtrace:

File: C:\xampp\htdocs\kinomonster\application\controllers\Movies.php
Line: 17
Function: _error_handler

File: C:\xampp\htdocs\kinomonster\index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Notice

Message: Undefined index: year

Filename: controllers/Movies.php

Line Number: 18

Backtrace:

File: C:\xampp\htdocs\kinomonster\application\controllers\Movies.php
Line: 18
Function: _error_handler

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

и так с каждой переменной 

Подскажите, как исправить

CodeIgniter

5 ответов

1

Покажите код controllers/Movies.php

1

В var_dump будем массив из getFilms, по которому можно определить есть ли в $movie_slug ключ с name.

1
<?php 

defined('BASEPATH') OR exit('no dirrect script access allowed');

class Movies extends My_Controller {
	public function __construct() {
		parent::__construct();
	}
	
	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['descrptions_movie'] = $movie_slug['descriptions'];
		$this->data['player_code'] = $movie_slug['player_code'];


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

можно пример вывода?

1

Поставьте сразу после 

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

такой код и вывод сюда прикрепите:

echo "<pre>";
var_dump($movie_slug);
echo "</pre>";
die(); //если с die() неработает, уберите die();

Sign up or Log in to write an answer