CodeIgniter урок 24
0
Делаю дз написал запрос на добавление фильмов а он не работает
public function filmadd(){
/*if(!$this->dx_auth->is_admin()){
//show_404();
$this->load->helper('url_helper');
redirect('/', 'location');
}*/
$this->data['title'] = "Добавить фильм";
if($this->input->post('slug') && $this->input->post('$name') && $this->input->post('$descriptions') && $this->input->post('$year') && $this->input->post('rating') && $this->input->post('player_code') && $this->input->post('poster') && $this->input->post('regis')){
$slug = $this->input->post('slug');
$title = $this->input->post('title');
$descriptions = $this->input->post('descriptions');
$year = $this->input->post('year');
$rating = $this->input->post('rating');
$player_code = $this->input->post('player_code');
$poster = $this->input->post('poster');
$regis = $this->input->post('regis');
$date = now();
$cat_id = 1;
if($this->films_model->setFilms($slug, $name, $descriptions, $year, $rating, $player_code, $poster, $regis, $date, $cat_id )){
$this->load->view('templates/header', $this->data);
$this->load->view('news/succes', $this->data);
$this->load->view('templates/footer');
}
}
else {
$this->load->view('templates/header', $this->data);
$this->load->view('movies/create-film', $this->data);
$this->load->view('templates/footer');
}
}
6 ответов
1
public function setFilms($slug, $name, $descriptions, $year, $rating, $player_code, $poster, $regis, $date, $cat_id ){
$data = array(
'slug' => htmlentities($slug),
'name '=> htmlentities($name),
'descriptions' => htmlentities($descriptions),
'year' => htmlentities($year),
'rating' => htmlentities($rating),
'player_code' => htmlentities($player_code),
'poster' => htmlentities($poster),
'regis' => htmlentities($regis),
'add_date' => $date,
'category_id' => $cat_id
);
return $this->db->insert('movie', $data);
}
1
знаки убрал ошибка Message: Call to undefined function now()
1
страница наз. films_model
2
заработало спасибо
2
1) Какую ошибку пишет? Сама модель (файл) как называется? Film_model.php или films_model.php?
$this->films_model
if($this->input->post('slug') && $this->input->post('$name') && $this->input->post('$descriptions') && $this->input->post('$year') && $this->input->post('rating') && $this->input->post('player_code') && $this->input->post('poster') && $this->input->post('regis')){
2) Зачем знак доллар($) в:
$this->input->post('$year')
&& $this->input->post('$descriptions') && $this->input->post('$year')
это же значение массива, не нужен знак $.
2
На функцию now() ругается. В этом видеоуроке вроде нет функции now(), не помню уже.
Попробуй заменить фунцию now() на это:
date("Y-m-d H:i:s")
или используй функцию now(), только подгрузи предварительно хелпер codeigniter:
$this->load->helper('date');