Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function index($id = null, $slug = ''){
- // Fetch the article
- //$this->db->where('pubdate <=', date('Y-m-d'));
- $this->data['article'] = $this->mberita->get_by_id($id,$slug);
- // Return 404 if not found
- count($this->data['article']) || show_404(uri_string());
- // Redirect if slug was incorrect
- $requested_slug = $this->uri->segment(3);
- $set_slug = $this->data['article']->slug;
- if ($requested_slug != $set_slug) {
- redirect('article/' . $this->data['article']->id . '/' . url_title($set_slug), 'location', '301');
- // Load view
- $this->data['contents'] = 'article';
- $this->load->view('template/wrapper/mahasiswa/wrapper_article', $this->data);
- }
- <div class="post-buttons">
- <a href="<?php echo 'article/' . intval($dt->id) . '/' . url_title($dt->slug) ; ?>" class="ui black label">
- Read More
- </a>
- </div>
- tkd/index.php/article/77/kejurnas-mahasiswa
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteRule ^(.*)$ index.php?/$1 [L]
- $route['article/(:num)/(:any)'] = "article/show_article/$1/$2"; //where article is controller and show_article is "behind the scene" method that takes over your index(); not a single user will know about it
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class Article extends CI_Controller {
- //I can spot that you are extending your controller NOT by CI_Controller because of usage $this->data[]
- public function __construct() {
- //constructor
- parent::__construct();
- $this->load->model('article_model', 'article'); //load model article_model and create alias "article"
- }
- public function index() {
- //let this be empty or redirect if no ID is sent to the controller
- redirect(); //redirect to default_controller
- }
- public function show_article($id = FALSE, $slug = FALSE) {
- if ($id === FALSE) redirect(); // no id? redirect to default_controller
- if ($slug === FALSE) {
- //slug is not sent to the article
- //you should do nothing if this happens but you may require reload page with correct slug
- //get slug by id
- //redirect(/article/$id/slug_by_id)
- }
- // Fetch the article
- //$this->db->where('pubdate <=', date('Y-m-d'));
- if ($this->data['article'] = $this->article->get($id)) {
- //all good we can show result
- $this->data['contents'] = 'article';
- $this->load->view('template/wrapper/mahasiswa/wrapper_article', $this->data);
- } else {
- //get() method returns FALSE
- redirect(); //id is not valid or there is no such record with id = $id
- }
- }
- }
- /* End of file article.php */
- /* Location: ./application/controllers/article.php */
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class Article extends CI_Model {
- public function __construct() {
- parent::__construct();
- //Do your magic here
- }
- public function get( $id = FALSE ) {
- if ($id === FALSE) return FALSE;
- $q = $this->db->get_where('article', array('id' => $id)); // table = 'article'
- return ($q->num_rows() > 0) ? $q->result() : FALSE;
- }
- }
- /* End of file article_model.php */
- /* Location: ./application/models/article_model.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement