BELAJAR CODE IGNITER PART 4

Hello World Codeigniter

Jika serius dengan codeigniter, Anda harus mengerti bagaimana sebuah controller bekerja.

Untuk lebih jelasnya, saya akan sharing kasus sederhana agar Anda dapat memahami bagaimana controller bekerja.

Disini saya mengangkat kasus yaitu bagaimana menampilkan text “Hello World” pada browser menggunakan controller.

Buat sebuat controller dengan nama Hello.php di dalam folder controller:

Kemudian ketikan kode berikut:

1
2
3
4
5
6
7
8
<?php
class Hello extends CI_Controller{
 
  function index(){
      echo "Hello World";
  }
 
}

NB: Setiap penulisan nama file dan nama class selalu di dahului dengan huruf Capital.

Setelah itu save dan buka browser Anda, lalu kunjungi url berikut:

http://localhost/myproject/index.php/hello

Maka akan akan terlihat text “Hello World” pada browser Anda.

Jika Anda perhatikan dengan seksama, pada dasarnya url pada codeigniter terlihat seperti gambar berikut:

URL Codeigniter

Dimana, terdapat protocol, primary domain, index.php, class name, dan function name.

Mungkin terdegar rumit, tapi sebenarnya tidak.

Untuk lebih jelasnya silahkan tambahkan satu function lagi pada Controller Hello.php. disini saya beri nama “show”.

Sehingga controller Hello.php menjadi seperti berikut:

1
2
3
4
5
6
7
8
9
10
11
12
<?php
class Hello extends CI_Controller{
 
  function index(){
      echo "Hello World";
  }
 
  function show(){
      echo "I Make The World Better Place.";
  }
 
}

Jika Anda jalankan dengan mengunjungi URL berikut:

http://localhost/myproject/index.php/hello/show

coba anda cek hasilnya keluarnya apa?

 

 

Bagikan

Comments (22)

  • mypeutemy Cialis Uso Diario Precio trealp https://ascialis.com/# - Cialis sefEntenna Viagra Generique Quand opertesy <a href=https://ascialis.com/#>cialis prescription</a> Infeflat Dapoxetine In Australia 14 Juli 2020 - 01:40:35 WIB
  • Matthewslody <a href="https://canadian-pharmacy-official.com/#"& gt;viagra online</a>
    <a href=https://canadian-pharmacy-official.com/#>viagra prices </a>
    https://canadian-pharmacy-official.com/# - viagra vs cialis
    <a href="https://canadian-pharmacy-official.com/" target="_blank">viagra 100mg</a>
    <a href="https://canadian-pharmacy-official.com/" target="_blank">generic viagra online</a>
    <a href="https://canadian-pharmacy-official.com/" target="_blank">viagra 100mg</a>

    ******blackamerica.info/the-curious-comforts-of-a-you tube-show-about-group-therapy/?unapproved=21653&moder ation-hash=56f85262f465bd4185563cff6aa6c7e4#comment-21653
    *********.miljasuihko.fi/edustamisen-etuoikeus/#comm ent-63064
    *********.caclp.cn/home.php?mod=space&u id=1389958
    *********.uroda.com/artykuly/delikatny-mak ijaz-w-rozach
    *********.kharkov.davr.gov.ua/archives/ 3332#comment-1895705
    25 Agustus 2020 - 18:07:12 WIB
  • Matthewslody <a href="https://canadian-pharmacy-official.com/#"& gt;generic viagra sildenafil</a>
    <a href=https://canadian-pharmacy-official.com/#>sildenafi l 100 </a>
    https://canadian-pharmacy-official.com/# - generic viagra
    <a href="https://canadian-pharmacy-official.com/" target="_blank">canadian pharmacy viagra</a>
    <a href="https://canadian-pharmacy-official.com/" target="_blank">canadian pharmacy viagra</a>
    <a href="https://canadian-pharmacy-official.com/" target="_blank">pills viagra</a>

    *********.jsgcks.com/home.php?mod=space&uid=22910 8
    *********.puerto-penasco.com/bboard/posting.php?mod e=reply&t=1721
    *********.primusnox.de/user/index. php?action=user&id=20&show=gb
    *********.aspie -editorial.com/2019/08/24/aspie-editorial-is-now-on-faceb ook-feel-free-to-join-in-the-discussion/?unapproved=57087 1&moderation-hash=2d2e826f68d09541b28442d3a7155e8c#co mment-570871
    ******nvrzone.com/ru/forum/topic/29161#c omment-186757
    26 Agustus 2020 - 01:52:44 WIB
  • Matthewslody <a href="https://canadian-pharmacy-official.com/#"& gt;generic viagra reviews</a>
    <a href=https://canadian-pharmacy-official.com/#>herbal viagra </a>
    https://canadian-pharmacy-official.com/# - buy generic viagra online
    <a href="https://canadian-pharmacy-official.com/" target="_blank">generic viagra india</a>
    <a href="https://canadian-pharmacy-official.com/" target="_blank">viagra no prescription</a>
    <a href="https://canadian-pharmacy-official.com/" target="_blank">viagra patent</a>

    *********.uroda.com/artykuly/bloto-wulkaniczne-sila-n atury-w-holdzie-twojej-sk-orze/zabiegi-najlepsze-na-jesie n-ostatni-czas-na-przygotowanie-do-sylwestra
    ******ww w.uroda.com/produkty/drogerie-natura-szampon-przeciwlupie zowy
    *********.desert-force.de/3.0/index.php?news-12 r
    ******ahmadrabah.com/site/questions/1001
    ******fo rum.settimanasudoku.it/showthread.php?191716-my-site-mn-i l&p=562821#post562821
    26 Agustus 2020 - 05:52:41 WIB
  • Matthewslody <a href="https://canadian-pharmacy-official.com/#"& gt;viagra pill</a>
    [url=https://canadian-pharmacy-official.com/# ]viagra cost [/url]
    https://canadian-pharmacy-official.com/# - viagra alternative
    <a href="https://canadian-pharmacy-official.com/" target="_blank">viagra prices</a>
    <a href="https://canadian-pharmacy-official.com/" target="_blank">viagra online pharmacy</a>
    <a href="https://canadian-pharmacy-official.com/" target="_blank">viagra 100mg</a>

    ******mayaptrungmactech.com/cac-cau-hoi-thuong-gap/ap -trung-vit-lon?unapproved=15271&moderation-hash=d7f53 5fcc9474ee358d9c4363f893a70#comment-15271
    ******gunsa gogo.org/guestbook/index.php?mode=3&post_id=311979
    n*********.szjarch.cn/Tools/Comment.aspx?mark=product
    n*********.moderntimesbeer.com/blog/our-2015-22oz-releas e-calendar?page=45#comment-674811
    *********.forumviag ra.com/question/medecine-en-ligne-2/
    26 Agustus 2020 - 14:05:39 WIB
  • Matthewslody <a href="https://canadian-pharmacy-official.com/#"& gt;sildenafil 100mg</a>
    <a href=https://canadian-pharmacy-official.com/#>viagra price </a>
    https://canadian-pharmacy-official.com/# - does generic viagra work
    <a href="https://canadian-pharmacy-official.com/" target="_blank">discount viagra</a>
    <a href="https://canadian-pharmacy-official.com/" target="_blank">viagra cost</a>
    <a href="https://canadian-pharmacy-official.com/" target="_blank">viagra sildenafil</a>

    *********.peugeot-207-club.ru/forum/showthread.php?p= 1925141&posted=1#post1925141
    *********.uroda.com/ artykuly/Henna-na-najwyzszym-poziomie
    ******forum.set timanasudoku.it/showthread.php?192103-my-site-lh-wn&p =564962#post564962
    *********.moderntimesbeer.com/blog /bay-area-sneak-preview?page=20#comment-675696
    ****** letonamore.ru/forum
    26 Agustus 2020 - 18:04:07 WIB

Silahkan Tinggalkan Komentar