1
ここに私の問題があります: 私は自分のブログページのページを作成しようとしていますが、何らかの理由で私が表示したい項目の数を入れようとしています。うまくいかない。何故かはわからない?;どんな助けでも助けになる、ありがとう。ここでcodeigniterのページ分類クラスから始める方法
は私のコントローラです:
public function blog()
{
// Pagination for Blog //
$data['blog'] = $this->blog_model->get_blog();
$data['categorias'] = $this->categorias_model->get_categorias();
$data['title'] = 'Blog';
$this->load->library('pagination');
$config['base_url'] = site_url('/blog/');
$config['total_rows'] = 200;
$config['per_page'] = 1;
$config['uri_segment'] = 3;
$config['num_links'] = 2;
$config['use_page_numbers'] = TRUE;
$config['page_query_string'] = TRUE;
$this->pagination->initialize($config);
$this->data['pagination'] = $this->pagination->create_links();
$this->load->view('templates/head',$data);
$this->load->view('templates/navbar',$data);
$this->load->view('news\blog\index.php',$this->data);
$this->load->view('templates/footer',$data);
}
マイモデル:
<?php
class Blog_model extends CI_Model{
// Connect to database //
public function __construct(){
$this->load->database();
}
// Get Posts from database //
public function get_blog($slug=FALSE){
if($slug===FALSE){
// Post order, ASC-DESC Categorias/Tags tabels //
$this->db->order_by('blog.id', 'DESC');
$query=$this->db->get('blog');
return $query->result_array();
}
$query=$this->db->get_where('blog', array('slug'=>$slug));
return $query->row_array();
}
public function crear_post(){
$slug=url_title($this->input->post('titulo'));
$data = array(
'titulo' => $this->input->post('titulo'),
'slug' => $slug,
'imagen' => $this->input->post('imagen'),
'fecha' => $this->input->post('fecha'),
'contenido' => $this->input->post('contenido'),
'categoria_id' => $this->input->post('categoria_id'),
);
return $this->db->insert('blog',$data);
}
public function delete_post($id){
$this->db->where('id', $id);
$this->db->delete('blog');
return true;
}
public function update_post(){
$slug = url_title($this->input->post('titulo'));
$data = array(
'titulo' => $this->input->post('titulo'),
'slug' => $slug,
'imagen' => $this->input->post('imagen'),
'fecha' => $this->input->post('fecha'),
'contenido' => $this->input->post('contenido'),
'categoria_id' => $this->input->post('categoria_id'),
);
$this->db->where('id', $this->input->post('id'));
return $this->db->update('blog', $data);
}
}
そして、ここが私の見解である。ここで
<div class="col-md-8 animated fadeIn">
<?php foreach($blog as $blog) : ?>
<div class="card text-xs-left"><!-- FIRST ARTICLE DEMO -->
<div class="card-header" id="article-header">
<h4><a href="<?php echo site_url('/blog/'.$blog['slug']); ?>"><?php echo ucfirst($blog['titulo']); ?></a></h4>
</div>
<img src="<?php echo $blog['imagen']; ?>" width="750" heihgt="350" class="img-fluid">
<!--<div class="card-body">
<p> <?php echo word_limiter($blog['contenido'],5); ?></p>
</div>-->
<div class="card-footer" id="article-footer">
<div class="row">
<div class="col-lg-12 col-md-9 col-sm-8">
<i class="fa fa-calendar" aria-hidden="true"></i> <?php echo ucfirst($blog['fecha']); ?>
<i class="fa fa-folder" aria-hidden="true"></i> <?php echo $blog['categoria_id']; ?>
<a href="<?php echo site_url('/blog/'.$blog['slug']); ?>" class="pull-right">Read more »</a>
</div>
</div>
</div>
</div>
<?php endforeach ?>
<!-- /Article -->
<?php echo $pagination ?>
</div>