2017-11-17 15 views
-1

私はそのコードを持っています。なぜ彼らがスラッグを使うのか分からない。誰かがexplaneできますか? スラグの平均は何ですか?私はそれが変数のようだと思う、私はそれが偶然かもしれない名前です。スラグの重要性は何ですか? yazi_model.phpモデル - >CodeigniterでSlugを使用する理由

<?php 
    class Yazi_model extends CI_Model{ 
     public function __construct(){ 
      $this->load->database(); 
     } 

     public function getir_yazilar($slug = FALSE){ //why slug should be false? why we use slug for it? 
      if($slug === FALSE){ //is this 'if' is necessary? I can just write last code and it will work. 
       $query = $this->db->get('yazilar'); 
       return $query->result_array(); 
      } 
      $query = $this->db->get_where('yazilar',array('slug' => $slug));//why slug? 
      return $query->row_array(); 
    } 
} 

Yazilar.php controller->

<?php 
    class Yazilar extends CI_Controller{ 
     public function index(){ //why not use slug 
      $veri['baslik'] = 'Son yazılar'; 
      $veri['yazilar'] = $this->yazi_model->getir_yazilar(); 
      $this->load->view('tema/header'); 
      $this->load->view('yazilar/index',$veri); 
      $this->load->view('tema/footer'); 
     } 

     public function detay($slug = NULL){ //why slug 
      $veri['yazi'] = $this->yazi_model->getir_yazilar($slug); //why slug 
      if(empty($veri['yazi'])){ 
       show_404(); 
      } 

      $veri['baslik'] = $veri['yazi']['baslik']; 
      $this->load->view('tema/header'); 
      $this->load->view('yazilar/detay',$veri); 
      $this->load->view('tema/footer'); 
     } 
    } 
+0

[CodeIgniterのに使用ナメクジ]の可能な重複(https://stackoverflow.com/questions/3305786/using-s lugs-in-codeigniter) –

+0

有用なクラス:https://github.com/ericbarnes/CodeIgniter-Slug-Library – Alex

答えて

1

ナメクジは、SEOフレンドリーなURLを取得するために使用することができます。例えば

: から:

www.site.com/index.php/blog/view/8 

へ:スラグと呼ばれる列の私のデータベーステーブルのナメクジは、このように、スラグとのポストを見つけ

www.site.com/index.php/blog/view/blog-name 

店:

public function view($slug) 
{ 
    $query = $this->db->get_where('posts', array('slug' => $slug), 1); 

    // Fetch the post row, display the post view, etc... 
} 
関連する問題