Проблема с коментариами к фильмам, как исправить?
Срочно нужна помощь
короче сделал все как в видео уроке
у меня в базе данных 3 таблици movie, serial, animation соответственно создал к ним еще 3 таблици moviecomments, serialcomments, animationcomments в которых столбцы созданы так
moviecomments: id, user_id, movie_id, comment_text, banned
serialcomments: id, user_id, serial_id, comment_text, banned
animationcomments: id, user_id, animation_id, comment_text, banned
вот сама модель Comments_model:
<?php
class Comments_model extends CI_Model {
public function __construct() {
$this->load->database();
}
public function getMovieComments($movie_id, $limit) {
$query = $this->db
->where('movie_id', $movie_id,)
->limit($limit)
->get('moviecomments');
return $query->result_array();
}
public function getSerialComments($serial_id, $limit) {
$query = $this->db
->where('serial_id', $serial_id,)
->limit($limit)
->get('serialcomments');
return $query->result_array();
}
public function getAnimationComments($animation_id, $limit) {
$query = $this->db
->where('animation_id', $animation_id,)
->limit($limit)
->get('animationcomments');
return $query->result_array();
}
}
дело в том что если я захожу на сайт как тестовы юзер или админ и пытаюсь оставить комент к фильму все работает отлично а вот если пытаюсь оставить комент к сериалу или к мультику то выдает ошибвку
вот модель Serials_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();
}
public function getSerialsOnPage($row_count, $offset, $type = 2) {
$query = $this->db
->where('category_id', $type)
->order_by('add_date', 'desc')
->get('serial', $row_count, $offset);
return $query->result_array();
}
public function setSerials($slug, $name, $descriptions, $year, $rating, $poster, $player_code, $director, $add_date, $category_id) {
$data = array(
'slug' => $slug,
'name' => $name,
'descriptions' => $descriptions,
'year' => $year,
'rating' => $rating,
'poster' => $poster,
'player_code' => $player_code,
'director' => $director,
'add_date' => $add_date,
'category_id' => $category_id,
);
return $this->db->insert('serial', $data);
}
public function updateSerials($id, $slug, $name, $descriptions, $year, $rating, $poster, $player_code, $director, $add_date, $category_id) {
$data = array(
'id' => $id,
'slug' => $slug,
'name' => $name,
'descriptions' => $descriptions,
'year' => $year,
'rating' => $rating,
'poster' => $poster,
'player_code' => $player_code,
'director' => $director,
'add_date' => $add_date,
'category_id' => $category_id,
);
return $this->db->update('serial', $data, array('id' => $id));
}
public function deleteSerials($slug) {
return $this->db->delete('serial', array('slug' => $slug));
}
public function setComments($user_id, $serial_id, $comment_text) {
$data = array(
'user_id' => $user_id,
'serial_id' => $serial_id,
'comment_text' => $comment_text
);
return $this->db->insert('serialcomments', $data);
}
}
вот контроллер Serials
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Serials extends MY_Controller {
public function __construct() {
parent::__construct();
$this->load->model('serials_model');
}
public function index() {
if(!$this->dx_auth->is_admin()) {
show_404();
}
$this->data['title'] = 'All TV Shows';
$this->data['serials'] = $this->serials_model->getSerials();
$this->load->view('templates/header', $this->data);
$this->load->view('serials/index', $this->data);
$this->load->view('templates/footer');
}
public function view($slug = NULL) {
$serial_slug = $this->serials_model->getSerials($slug, false, false);
if(empty($serial_slug)) {
show_404();
}
$this->load->model('comments_model');
$this->data['serialcomments'] = $this->comments_model->getSerialComments($serial_slug['id'], 100);
$this->data['title'] = $serial_slug['name'];
$this->data['year'] = $serial_slug['year'];
$this->data['rating'] = $serial_slug['rating'];
$this->data['descriptions_serial'] = $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');
}
public function type($slug = NULL) {
$this->load->library('pagination');
$this->data['serial_data'] = null;
$offset = (int) $this->uri->segment(4);
$row_count = 10;
$count = 0;
if($slug = "serials") {
$count = count($this->serials_model->getSerials(false, PHP_INT_MAX));
$p_config['base_url'] = '/serials/type/serials/';
$this->data['title'] = "TV Shows";
$this->data['serial_data'] = $this->serials_model->getSerialsOnPage($row_count, $offset, 2);
}
$p_config['total_rows'] = $count;
$p_config['per_page'] = $row_count;
$p_config['full_tag_open'] = "<ul class='pagination'>";
$p_config['full_tag_close'] ="</ul>";
$p_config['num_tag_open'] = '<li>';
$p_config['num_tag_close'] = '</li>';
$p_config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
$p_config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
$p_config['next_tag_open'] = "<li>";
$p_config['next_tagl_close'] = "</li>";
$p_config['prev_tag_open'] = "<li>";
$p_config['prev_tagl_close'] = "</li>";
$p_config['first_tag_open'] = "<li>";
$p_config['first_tagl_close'] = "</li>";
$p_config['last_tag_open'] = "<li>";
$p_config['last_tagl_close'] = "</li>";
$this->pagination->initialize($p_config);
$this->data['pagination'] = $this->pagination->create_links();
$this->load->view('templates/header', $this->data);
$this->load->view('serials/type', $this->data);
$this->load->view('templates/footer');
}
public function create() {
if(!$this->dx_auth->is_admin()) {
show_404();
}
$this->data['title'] = 'Add TV Show';
if($this->input->post('slug') && $this->input->post('name') && $this->input->post('descriptions') && $this->input->post('year') && $this->input->post('rating') && $this->input->post('poster') && $this->input->post('player_code') && $this->input->post('director') && $this->input->post('add_date') && $this->input->post('category_id')) {
$slug = $this->input->post('slug');
$name = $this->input->post('name');
$descriptions = $this->input->post('descriptions');
$year = $this->input->post('year');
$rating = $this->input->post('rating');
$poster = $this->input->post('poster');
$player_code = $this->input->post('player_code');
$director = $this->input->post('director');
$add_date = $this->input->post('add_date');
$category_id = $this->input->post('category_id');
if($this->serials_model->setSerials($slug, $name, $descriptions, $year, $rating, $poster, $player_code, $director, $add_date, $category_id)) {
$this->data['title'] = 'TV Show Added!';
$this->load->view('templates/header', $this->data);
$this->load->view('serials/created');
$this->load->view('templates/footer');
}
}
else{
$this->load->view('templates/header', $this->data);
$this->load->view('serials/create', $this->data);
$this->load->view('templates/footer');
}
}
public function edit($slug = NULL) {
if(!$this->dx_auth->is_admin()) {
show_404();
}
$this->data['title'] = 'Edit TV Show';
$this->data['serials_item'] = $this->serials_model->getSerials($slug);
if(empty($this->data['serials_item'])) {
show_404();
}
$this->data['id_serials'] = $this->data['serials_item']['id'];
$this->data['slug_serials'] = $this->data['serials_item']['slug'];
$this->data['name_serials'] = $this->data['serials_item']['name'];
$this->data['descriptions_serials'] = $this->data['serials_item']['descriptions'];
$this->data['year_serials'] = $this->data['serials_item']['year'];
$this->data['rating_serials'] = $this->data['serials_item']['rating'];
$this->data['poster_serials'] = $this->data['serials_item']['poster'];
$this->data['player_code_serials'] = $this->data['serials_item']['player_code'];
$this->data['director_serials'] = $this->data['serials_item']['director'];
$this->data['add_date_serials'] = $this->data['serials_item']['add_date'];
$this->data['category_id_serials'] = $this->data['serials_item']['category_id'];
if($this->input->post('slug') && $this->input->post('name') && $this->input->post('descriptions') && $this->input->post('year') && $this->input->post('rating') && $this->input->post('poster') && $this->input->post('player_code') && $this->input->post('director') && $this->input->post('add_date') && $this->input->post('category_id')) {
$id = $this->data['serials_item']['id'];
$slug = $this->input->post('slug');
$name = $this->input->post('name');
$descriptions = $this->input->post('descriptions');
$year = $this->input->post('year');
$rating = $this->input->post('rating');
$poster = $this->input->post('poster');
$player_code = $this->input->post('player_code');
$director = $this->input->post('director');
$add_date = $this->input->post('add_date');
$category_id = $this->input->post('category_id');
if($this->serials_model->updateMovies($id, $slug, $name, $descriptions, $year, $rating, $poster, $player_code, $director, $add_date, $category_id)) {
$this->data['title'] = 'Successfully Updated';
$this->load->view('templates/header', $this->data);
$this->load->view('serials/edited');
$this->load->view('templates/footer');
}
}
else{
$this->load->view('templates/header', $this-data);
$this->load->view('serials/edit', $this->data);
$this->load->view('templates/footer');
}
}
public function delete($slug = NULL) {
if(!$this->dx_auth->is_admin()) {
show_404();
}
$this->data['serials_delete'] = $this->serials_model->getSerials($slug);
if(empty($this->data['serials_delete'])) {
show_404();
}
$this->data['title'] = "Delete TV Show";
$this->data['result'] = "Error Deleting".$this->data['serials_delete']['name'];
if($this->serials_model->deleteSerials($slug)) {
$this->data['result'] = $this->data['serials_delete']['name']."Successfully Deleted";
}
$this->load->view('templates/header', $this->data);
$this->load_view('serials/delete', $this->data);
$this->load->view('templates/footer');
}
public function comment() {
if(!$this->dx_auth->is_admin()) {
show_404();
}
$this->data['title'] = 'Add Commentary';
if($this->input->post('user_id') && $this->input->post('serial_id') && $this->input->post('comment_text')) {
$user_id = $this->input->post('user_id');
$serial_id = $this->input->post('serial_id');
$comment_text = $this->input->post('comment_text');
if($this->serials_model->setComments($user_id, $serial_id, $comment_text)) {
$this->data['title'] = 'Commentary Added!';
$shit->load->view('serials/commentCreated');
}
}
else{
$this->load->view('serials/commentError', $this->data);
}
}
}
а вот файл view:
<h1><?php echo $title; ?>
<?php if($this->dx_auth->is_admin()) { ?>
<a href="/movies/edit/<?php echo $slug; ?>"><button type="button" class="btn btn-default">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></button></a>
<?php } ?>
</h1>
<hr>
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" src="<?php echo $player_code; ?>" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
<div class="well info-block text-center">
Year: <span class="badge"><?php echo $year; ?></span>
Rating: <span class="badge"><?php echo $rating; ?></span>
Director: <span class="badge"><?php echo $director; ?></span>
</div>
<div class="margin-8"></div>
<h2>About <?php echo $title; ?></h2>
<hr>
<div class="well">
<?php echo $descriptions_movie; ?>
</div>
<div class="margin-8"></div>
<h2>User Reviews About: <?php echo $title; ?></h2>
<hr>
<?php foreach($moviecomments as $key => $value): ?>
<div class="panel panel-info">
<div class="panel-heading"><i class="glyphicon glyphicon-user"></i> <span><?php echo getUserNameById($value['user_id'])->username; ?></span> </div>
<div class="panel-body">
<?php echo $value['comment_text']; ?>
</div>
</div>
<?php endforeach ?>
<?php if ($this->dx_auth->is_logged_in()): ?>
<?php $this->session->set_flashdata('redirect', $this->uri->uri_string()); ?>
<div class="panel panel-info">
<div class="panel-heading"><i class="glyphicon glyphicon-user"></i> <span>Nino</span> </div>
<div class="panel-body">
Mille Bobby Brown is excellent, Sam Claflin is extraordinary and Henry Cavil is being
Henry Cavil. The Production is great, the story is heart warming but the mystery is not to
much. I cant wait to see the spin off with Henry Cavil as Sherlock Holmes.
</div>
</div>
<form action="/movies/comment/" method="post">
<input class="hidden" type="input" name="user_id" value="<?php echo $this->dx_auth->get_user_id(); ?>">
<input class="hidden" type="input" name="movie_id" value="<?php echo $id; ?>">
<div class="form-group">
<textarea class="form-control" name="comment_text" placeholder="your comment"></textarea>
</div>
<button class="btn btn-lg btn-warning pull-right">Send</button>
</form>
<?php endif ?>
<?php if (!$this->dx_auth->is_logged_in()): ?>
<br>
<p>To leave a comment, please login or register!</p>
<?php endif ?>
а вот сама ошибка:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: id
Filename: serials/view.php
Line Number: 57
Backtrace:
File: C:\xampp\htdocs\movieworld\application\views\serials\view.php
Line: 57
Function: _error_handler
File: C:\xampp\htdocs\movieworld\application\controllers\Serials.php
Line: 45
Function: view
File: C:\xampp\htdocs\movieworld\index.php
Line: 315
Function: require_once
помогите плиз чтоб наконец залить на хост
спасибо зарание
6 ответов
это я понял но где не так сделал в коде?ведь комент к фильму добавляется а к остальным нет
и если в файле view для сериалов убираю ту самую строку
<input class="hidden" type="input" name="serial_id" value="<?php echo $id; ?>">
и если пытаюсь добавит комент к сериалу выдет
404 Page Not Found
The page you requested was not found.
как все это исправить?
Undefined variable: id починил теперь никак понять не могу почему выдает 404 Page Not Found когда добавляю комент к сериалу?
это починил,недописал в контороллере эту самую строку
теперь не могу понять почему пишет 404 Page Not Found при добавлении комента
к фильмам все работает отлично а к сериалу 404 Page Not Found
короче все починил сам ))
Message: Undefined variable: id
Пытаешься вызвать переменную id, который у тебя нет.
<input class="hidden" type="input" name="movie_id" value="<?php echo $id; ?>">
$id в контроллере задаваться должно, что-то вроде этого:
$this->data['id'] = $serial_slug['id'];