Membuat CSS Class aktif di menu dengan Codeigniter

Radio Dalam – Sebelumnya sempat gw share cara bikin Class Aktif di PHP Prosedural (linknya bisa di intip diSINI), nah sekarang gw mau share cara simple untuk bikin Class aktif di Framework Codeigniter.

Sebelumnya siapkan dulu menunya

Sekarang lanjut siapin kode yang udah ada di CI untuk ngambil segmen URL $this->uri->segment(n), N disini ditentukan sesuai bentuk URL yang anda gunakan. Misal URL nya itu webnya.com/news/month/isi_berita, berarti segment(1) itu news, segment(2) itu month, dan segment(3) itu isi_berita. Sudah paham kan sampai situ? ok lanjut…

Kita buat variabel untuk segmen-nya $hal = $this->uri->segment(1) kemudian kita sisipkan ke li untuk pasang CLASS aktif nya <?=($hal==’ini-nama-menu-atau-segmen-nya’)?’active’:”;?>

Semoga bermanfaat 😉

Referensi:
https://forum.codeigniter.com/thread-62075.htmlhttps://stackoverflow.com/questions/19293892/what-is-the-use-of-this-uri-segment3-in-codeigniter-pagination

About the Author

Anshori Wahyu
My name is Mas Wahyu Anshori, 32 years old. I am a student from STIE Ahmad Dahlan Jakarta, work at Punakawan Digital Media since Oct 2017. Before I came to Punakawan, I was doing IT Supportt and web content at Seratus Company, Melodia Group and be part of Kehati as a freelance web developer. I was also a freelance web developer with simple HTML, CSS base, jQuery, and PHP. Learned Website Developer base (with a help of Google) by myself would be my achievement so far. I'am an Indonesian football junkie, as well as addicted to HTML, CSS and jQuery coding.

Be the first to comment on "Membuat CSS Class aktif di menu dengan Codeigniter"

Leave a Reply