Bisakah Link Artikel Swarakalibata CI diubah seperti WordpressDibuat
Login Terakhir
1 Tahun lalu,
Telah Dilihat 1875 Kali
| |
Sultan Account |
|
|
Rahmat Sasmita
Mengatakan :
Sultan Account
Assalamualaikum Warahmatullahi Wabarakatuh... misalnya http://localhost/web/berita/detail/usai-bertempur-banyak-tentara-israel-hilang-di-jalur-gaza hilangkan kata /berita/detail/ nya |
|
| PHPMU.COM Support commented on 11 Mei 2018 06:40:32 Sultan Account |
|
|
|
Assalam,.. alhamdulillah bisa setelah saya cobakan,..
pertama buka file "application/config/routes.php"
cari baris : $route['default_controller'] = 'main';
ubah menjadi :
$route = array(
'default_controller' => 'main',
'main' => 'main',
'administrator' => 'Administrator',
'agenda' => 'agenda',
'albums' => 'albums',
'berita' => 'berita',
'download' => 'download',
'halaman' => 'halaman',
'hubungi' => 'hubungi',
'kategori' => 'kategori',
'konsultasi' => 'konsultasi',
'kontrirbutor' => 'kontrirbutor',
'playlist' => 'playlist',
'polling' => 'polling',
'tag' => 'tag',
);
$route['(:any)'] = 'news/$1/$2';
Selanjutnya buat Controller baru dengan nama News.php
dan isikan script berikut :
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class News extends CI_Controller {
private $page = null;
private $params = null;
public function __construct (){
parent::__construct();
$this->page = $this->uri->segment(1);
$this->reroute();
}
public function _remap ($page, $params = array() ){
if(count($params) > 0){
if(strlen($params[0]) > 0){
$this->params = $params;
}
}
if($this->params){
$method = strtolower(trim($this->params[0]));
if(method_exists($this, $method)){
return call_user_func_array (array($this, $method), $this->params);
}else{
$this->index();
}
}else{
$this->index();
}
}
function index($id){
$query = $this->model_utama->view_join_two('berita','users','kategori','username','id_kategori',array('judul_seo' => $this->uri->segment(1)),'id_berita','DESC',0,1);
if ($query->num_rows()<=0){
redirect('main');
}else{
$row = $query->row_array();
$data['title'] = cetak($row['judul']);
$data['description'] = cetak_meta($row['isi_berita'],0,500);
$data['keywords'] = cetak($row['tag']);
$data['rows'] = $row;
$dataa = array('dibaca'=>$row['dibaca']+1);
$where = array('id_berita' => $row['id_berita']);
$this->model_utama->update('berita', $dataa, $where);
$this->load->helper('captcha');
$vals = array(
'img_path' => './captcha/',
'img_url' => base_url().'captcha/',
'font_path' => './asset/Tahoma.ttf',
'font_size' => 17,
'img_width' => '150',
'img_height' => 33,
'border' => 0,
'word_length' => 5,
'expiration' => 7200
);
$cap = create_captcha($vals);
$data['image'] = $cap['image'];
$this->session->set_userdata('mycaptcha', $cap['word']);
$this->template->load(template().'/template',template().'/detailberita',$data);
}
}
private function reroute (){
if($this->page == $this->router->class){
if($this->uri->total_segments() > 1){
$this->load->helper('url');
$uri = substr($this->uri->uri_string, strlen($this->page)+1);
redirect($uri);
}else{
$this->noroute($this->page);
}
}
}
}
?>
Selesai dan simpan, sekarang coba akses berita dengan url :
http://domain.com/usai-bertempur-banyak-tentara-israel-hilang-di-jalur-gaza
keren juga ya sama seperti url di wordpress,.. :D
insyaallah swarakalibata ci versi berikutnya akan kita buat url berita jadi begini juga,.. |
|
| Rahmat Sasmita commented on 18 Mei 2018 16:58:34 Sultan Account |
|
|
|
Assalam,.. Mantaap pk... sudah bisa... untuk merubah semua link pada link terkait di home dan halaman lainnya gimana pk? soalnya masih bisa diakses untuk kedua jenis link nya.. baik yang menggunakan /berita/detail/ atau pun tidak. |
|
| Bukhori Muslim commented on 19 Mei 2018 10:51:28 Sultan Account |
|
|
|
Assalam,.. sepertinya harus diubah semua url pada template coba hapus saja semua "/berita/detail/" pada url berita di template. atau mungkin ada cara redirect pake htaccess, tapi saya kurang paham. ^_^' |
|
| Rahmat Sasmita commented on 20 Mei 2018 07:26:36 Sultan Account |
|
|
|
Assalam,.. Sepertinya memang harus satu per satu di hilangkan... heheh Next version aja... mas |
|
| diwa abdee negara commented on 20 Mei 2018 13:28:12 Sultan Account |
|
|
|
Assalam,.. kok saya gak bisa ya, masih tetap di url ../berita/detail/... |
|