jcadima
12/11/2015 - 7:11 PM

SEO friendly URLs

SEO friendly URLs

<?php
ref: https://www.youtube.com/watch?v=ZmtZj1pRrkk

// ********** MODEL ********** 
/*=================================================================================
		GET SINGLE ARTICLE
==================================================================================*/
	public function get_article( $id ) {
		$this->db->where('id', $id) ;
		$query = $this->db->get('articles') ;
		return $query->row() ;
	}

/*=================================================================================
		GET SINGLE ARTICLE BY SLUG (SEO FRIENDLY)
==================================================================================*/
	public function get_article_by_slug( $slug ) {
		$this->db->where('slug', $slug) ;
		$query = $this->db->get('articles') ;
		return $query->row() ;
	}
	
	
// **********   VIEW  ********** 
      <ul class="row marketing">
        <?php foreach ( $articles as $article ) : ?>
          <li><h4><?php echo $article->title ?></h4>
              <?php echo word_limiter($article->body, 20 ) ; ?>
              <p><a href="<?php echo base_url(); ?>articles/view_by_slug/<?php echo $article->slug; ?>">Read More</a></p>
          </li>
        <?php endforeach; ?>
      </ul>
	
	
	
// ROUTES.PHP
// [what you want] = "default route"
$route['admin'] = "admin/dashboard" ;
$route['admin/login'] = "admin/authenticate/login" ;
$route['admin/logout'] = 'admin/authenticate/logout' ;


// [what-you-want] = "real path"
$route['blog'] =  'articles'  ; // this will change 'articles' to 'blog'
$route['blog/(:any)'] =  'articles/view_by_slug/$1' ; // changes blog/article-name