我的问题是为什么在更新或在codeigniter中创建后没有显示帖子?例如,如果我在select html标记中创建了一个没有分配类别的帖子,它会在数据库中创建帖子但是没有在应用程序中显示,如果更新帖子而没有在select html标签中选择一个类别,则相同。但如果我指定一个类别,它会显示帖子。
这是我的代码
模型类别
public function pelicula_categoria()
{
$this->db->order_by('categoria_nombre');
$query = $this->db->get('categorias');
return $query->result_array();
}
模特帖子
public function listar_peliculas()
{
$this->db->select();
$this->db->join('categorias', 'categorias.categoria_id = peliculas.categoria_id');
$this->db->from('peliculas');
$this->db->order_by('peliculas.pelicula_id', 'desc');
$query = $this->db->get();
return $query->result_array();
}
控制器添加帖子
public function agregar_pelicula()
{
$data['error'] = null;
$data['titulo_agregar'] = 'Agregar pelicula';
$data['categorias'] = $this->Categorias_Model->pelicula_categoria();
if ($this->input->post())
{
$this->form_validation->set_rules('pelicula_titulo', 'Titulo', ` 'required');
$this->form_validation->set_rules('pelicula_sinopsis', 'Sinopsis', 'required');
$this->form_validation->set_rules('pelicula_caratula', 'Caratula', 'required');
$this->form_validation->set_rules('pelicula_estreno', 'Estreno', 'required');
$this->form_validation->set_rules('pelicula_puntuacion', 'Puntuacion', 'required');
$this->form_validation->set_rules('pelicula_director', 'Director', 'required');
$this->form_validation->set_rules('pelicula_duracion', 'Duracion', 'required');
$this->form_validation->set_rules('pelicula_pais', '', 'required');
$this->form_validation->set_rules('categoria_id', 'Categoria', 'required');
$this->form_validation->set_rules('pelicula_enlace', 'Enlace', 'required');
if ($this->form_validation->run() == FALSE)
{
$data['error'] = "Todos los campos son requeridos";
}
else
{
$this->Peliculas_Model->insert_pelicula();
$this->session->set_flashdata('mensaje', 'Pelicula agregada correctamente');
redirect(base_url() . 'admin');
}
}
$this->load->view('admin/layouts/header', $data);
$this->load->view('admin/modules/create', $data);
$this->load->view('admin/layouts/footer');
}
最后在创建视图和更新视图中显示数据库中的类别
<select class="custom-select" name="categoria_id">
<option selected>Categoria</option>
<?php foreach ($categorias as $categoria): ?>
<option value="<?php echo $categoria['categoria_id']; ?>">
<?php echo $categoria['categoria_nombre']; ?>
</option>
<?php endforeach; ?>
</select>
答案 0 :(得分:0)
您是否登记了print_r();
功能?
//example - Model
public function userlists()
{
$data = '';
$sql = "SELECT * FROM customer";
$query = $this->db->query($sql);
if($query->num_rows()>0)
{
return $query->result_array();
}
}
//Controller
$data['userlist']= $userslists=$this->example_model->userlists();
//check the array values is exists or not, just print the variable
print_r($userslists);