Почему не добавляються коментарии к фильмам?
0
короче у меня проблемы не кончаюься так что надеюсь на помощь
подошел к концу помоему и вот вхожу на сайт как админ(кстати пароль админа в phpmyadmin меняю а на сайте с новым паролем не пускает пишет неправильный пароль)перехожу на страницу просмотра любого фильма добавляю комент к фильму а фигушки,страница обновляется и ничего,проверяю в базе данных там тоже пусто
вот код
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();
}
}
у меня три таблицы так вот каждому свою таблицу создал для коментов
Controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Movies extends MY_Controller {
public function __construct() {
parent::__construct();
$this->load->model('Films_model');
}
public function index() {
if(!$this->dx_auth->is_admin()) {
show_404();
}
$this->data['title'] = 'All Movies';
$this->data['movies'] = $this->Films_model->getMovies();
$this->load->view('templates/header', $this->data);
$this->load->view('movies/index', $this->data);
$this->load->view('templates/footer');
}
public function type($slug = NULL) {
$this->load->library('pagination');
$this->data['movie_data'] = NULL;
$offset = (int) $this->uri->segment(4);
$row_count = 10;
$count = 0;
if($slug == "films") {
$count = count($this->films_model->getFilms(false, PHP_INT_MAX));
$p_config['base_url'] = '/movies/type/films/';
$this->data['title'] = "Movies";
$this->data['movie_data'] = $this->films_model->getMoviesOnPage($row_count, $offset, 1);
}
if($this->data['movie_data'] == null) {
show_404();
}
$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('movies/type', $this->data);
$this->load->view('templates/footer');
}
public function create() {
if(!$this->dx_auth->is_admin()) {
show_404();
}
$this->data['title'] = 'Add Movie';
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->Films_model->setMovies($slug, $name, $descriptions, $year, $rating, $poster, $player_code, $director, $add_date, $category_id)) {
$this->data['title'] = 'Movie Added!';
$this->load->view('templates/header', $this->data);
$this->load->view('movies/created');
$this->load->view('templates/footer');
}
}
else{
$this->load->view('templates/header', $this->data);
$this->load->view('movies/create', $this->data);
$this->load->view('templates/footer');
}
}
public function delete($slug = NULL) {
if(!$this->dx_auth->is_admin()) {
show_404();
}
$this->data['movies_delete'] = $this->Films_model->getMovies($slug);
if(empty($this->data['movies_delete'])) {
show_404();
}
$this->data['title'] = "Delete Movie";
$this->data['result'] = "Error Deleting ".$this->data['movies_delete']['name'];
if($this->Films_model->deleteMovies($slug)) {
$this->data['result'] = $this->data['movies_delete']['name']." Succesfully Deleted";
}
$this->load->view('templates/header', $this->data);
$this->load->view('movies/delete', $this->data);
$this->load->view('templates/footer');
}
public function comment() {
if(!$this->dx_auth->is_logged_in()) {
show_404();
}
$this->data['title'] = 'Add Commentary';
if($this->input->post('user_id') && $this->input->post('movie_id') && $this->input->post('comment_text')) {
$user_id = $this->input->post('user_id');
$movie_id = $this->input->post('movie_id');
$comment_text = $this->input->post('comment_text');
if($this->Films_model->setComments($user_id, $movie_id, $comment_text)) {
$this->data['title'] = 'Commentary Added!';
$this->load->view('movies/commentCreated');
}
}
else{
$this->load->view('movies/commentError', $this->data);
}
}
public function edit($slug = NULL) {
if(!$this->dx_auth->is_admin()) {
show_404();
}
$this->data['title'] = 'Edit Movie';
$this->data['movies_item'] = $this->Films_model->getMovies($slug);
if (empty($this->data['movies_item'])) {
show_404();
}
$this->data['id_movies'] = $this->data['movies_item']['id'];
$this->data['slug_movies'] = $this->data['movies_item']['slug'];
$this->data['name_movies'] = $this->data['movies_item']['name'];
$this->data['descriptions_movies'] = $this->data['movies_item']['descriptions'];
$this->data['year_movies'] = $this->data['movies_item']['year'];
$this->data['rating_movies'] = $this->data['movies_item']['rating'];
$this->data['poster_movies'] = $this->data['movies_item']['poster'];
$this->data['player_code_movies'] = $this->data['movies_item']['player_code'];
$this->data['director_movies'] = $this->data['movies_item']['director'];
$this->data['add_date_movies'] = $this->data['movies_item']['add_date'];
$this->data['category_id_movies'] = $this->data['movies_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['movies_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->Films_model->updateMovies($id, $slug, $name, $descriptions, $year, $rating, $poster, $player_code, $director, $add_date, $category_id)) {
$this->data['title'] = 'Succesfully Updated';
$this->load->view('templates/header', $this->data);
$this->load->view('movies/edited');
$this->load->view('templates/footer');
}
}
else{
$this->load->view('templates/header', $this->data);
$this->load->view('movies/edit', $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->load->model('comments_model');
$this->data['moviecomments'] = $this->comments_model->getMovieComments($movie_slug['id'], 100);
$this->data['id'] = $movie_slug['id'];
$this->data['slug'] = $movie_slug['slug'];
$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->data['category'] = $movie_slug['category_id'];
$this->load->view('templates/header', $this->data);
$this->load->view('movies/view', $this->data);
$this->load->view('templates/footer');
}
}
Config/Routes:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
| -------------------------------------------------------------------------
| URI ROUTING
| -------------------------------------------------------------------------
| This file lets you re-map URI requests to specific controller functions.
|
| Typically there is a one-to-one relationship between a URL string
| and its corresponding controller class/method. The segments in a
| URL normally follow this pattern:
|
| example.com/class/method/id/
|
| In some instances, however, you may want to remap this relationship
| so that a different class/function is called than the one
| corresponding to the URL.
|
| Please see the user guide for complete details:
|
| https://codeigniter.com/user_guide/general/routing.html
|
| -------------------------------------------------------------------------
| RESERVED ROUTES
| -------------------------------------------------------------------------
|
| There are three reserved routes:
|
| $route['default_controller'] = 'welcome';
|
| This route indicates which controller class should be loaded if the
| URI contains no data. In the above example, the "welcome" class
| would be loaded.
|
| $route['404_override'] = 'errors/page_missing';
|
| This route will tell the Router which controller/method to use if those
| provided in the URL cannot be matched to a valid route.
|
| $route['translate_uri_dashes'] = FALSE;
|
| This is not exactly a route, but allows you to automatically route
| controller and method names that contain dashes. '-' isn't a valid
| class or method name character, so it requires translation.
| When you set this option to TRUE, it will replace ALL dashes in the
| controller and method URI segments.
|
| Examples: my-controller/index -> my_controller/index
| my-controller/my-method -> my_controller/my_method
*/
$route['default_controller'] = 'main';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['news'] = 'news';
$route['news/create'] = 'news/create';
$route['news/edit'] = 'news/edit';
$route['news/delete'] = 'news/delete';
$route['news/(:any)'] = 'news/view/$1';
$route['posts'] = 'posts';
$route['posts/create'] = 'posts/create';
$route['posts/edit'] = 'posts/edit';
$route['posts/delete'] = 'posts/delete';
$route['posts/(:any)'] = 'posts/view/$1';
$route['movies'] = 'movies';
$route['movies/comment'] = 'movies/comment';
$route['movies/create'] = 'movies/create';
$route['movies/edit'] = 'movies/edit';
$route['movies/delete'] = 'movies/delete';
$route['movies/(:any)'] = 'movies/view/$1';
$route['movies/type/films'] = 'movies/type/films/$1';
$route['serials'] = 'serials';
$route['serials/comment'] = 'serials/comment';
$route['serials/create'] = 'serials/create';
$route['serials/edit'] = 'serials/edit';
$route['serials/delete'] = 'serials/delete';
$route['serials/(:any)'] = 'serials/view/$1';
$route['serials/type/serials'] = 'serials/type/serials/$1';
$route['animations'] = 'animations';
$route['animations/comment'] = 'animations/comment';
$route['animations/create'] = 'animations/create';
$route['animations/edit'] = 'animations/edit';
$route['animations/delete'] = 'animations/delete';
$route['animations/(:any)'] = 'animations/view/$1';
$route['animations/type/animations'] = 'animations/type/animations/$1';
$route['rating'] = 'main/rating';
$route['rating/(:any)'] = 'main/rating/$1';
$route['contact'] = 'main/contact';
$route['search'] = 'search';
$route['search/(:any)'] = 'search/$1';