2017-02-08 10 views
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> 

答えて

0

は再びです:

私のコントローラ:

public function blog() { 
       $data['blog'] = $this->blog_model->get_blog(); 
       $data['categorias'] = $this->categorias_model->get_categorias(); 
       $data['title'] = 'Blog'; 


       $config = array(); 
       $config["base_url"] = base_url() . "blog"; 
       $config["total_rows"] = $this->blog_model->record_count(); 
       $config["per_page"] = 1; 
       $config["uri_segment"] = 3; 
       $config['num_links'] = 1; 
       $config['query_string_segment'] = 'paginas'; 
       $config['page_query_string'] = TRUE; 
       $config['display_pages'] = FALSE; 


       $this->pagination->initialize($config); 

       $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0; 
       $data["pagination"] = $this->pagination->create_links(); 
       $data["results"] = $this->blog_model->get_paginas($config["per_page"], $page); 

       $this->load->view('templates/head',$data); 
       $this->load->view('templates/navbar',$data); 
       $this->load->view("news/blog/index", $data); 
       $this->load->view('templates/footer',$data); 
} 

し、再度、私のモデル:

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'); 
//    $this->db->join('categorias','categorias.id = blog.categoria_id'); 
       // /Post order, ASC-DESC // 
       $query=$this->db->get('blog'); 
       return $query->result_array(); 
       } 

       $query=$this->db->get_where('blog', array('slug'=>$slug)); 
       return $query->row_array(); 
      } 

///Pagination 
    public function record_count() { 
    return $this->db->count_all("blog"); 
} 

public function get_paginas($limit, $start) { 
    $this->db->limit($limit, $start); 
    $query = $this->db->get("blog"); 

    if ($query->num_rows() > 0) { 
     foreach ($query->result() as $row) { 
      $data[] = $row; 
     } 
     return $data; 
    } 
    return false; 
} 



     // Crear post // 
     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'), 
//    'autor' => $this->input->post('autor'), 
       'fecha' => $this->input->post('fecha'), 
       'contenido' => $this->input->post('contenido'), 
       'categoria_id' => $this->input->post('categoria_id'), 

      ); 

      return $this->db->insert('blog',$data); 

      } 

     // Borrar post // 
      public function delete_post($id){ 
      $this->db->where('id', $id); 
      $this->db->delete('blog'); 
      return true; 
     } 
     // Actualizar Post // 
     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'), 
//    'autor' => $this->input->post('autor'), 
       '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); 
     } 

     // Categorias // 

//  public function get_categorias(){ 
//   $this->db->order_by('nombre'); 
//   $query = $this->db->get('categorias'); 
//   return $query->result_array(); 
//  } 



     } 
関連する問題