pemrograman web adam hendra brata

Upload: yogarizwan

Post on 02-Mar-2018

238 views

Category:

Documents


3 download

TRANSCRIPT

  • 7/26/2019 Pemrograman Web Adam Hendra Brata

    1/18

    Modular PHP

    Adam Hendra Brata

    Pemrograman Web

  • 7/26/2019 Pemrograman Web Adam Hendra Brata

    2/18

    Modular PHP Pengenalan Web Modular

    Include dan Require

    Pokok Bahasan

  • 7/26/2019 Pemrograman Web Adam Hendra Brata

    3/18

    Modular Web

  • 7/26/2019 Pemrograman Web Adam Hendra Brata

    4/18

    Pernahkah kita sadar dalam menulis kode

    program dalam pemrograman web,terkadang kita menuliskan beberapa kodeprogram yang pada dasarnya sama ataumemiliki fungsi yang mirip, namun kita tulisberkali kali untuk pembuatan fungsional

    web tersebut

    Modular Web

  • 7/26/2019 Pemrograman Web Adam Hendra Brata

    5/18

    Rewriting Code : Connect to Database

    Bagaimanapunbentuknya, dia akan

    tetap sama saja

  • 7/26/2019 Pemrograman Web Adam Hendra Brata

    6/18

    Ingat dengan permainan Lego ?

    Modular Web

  • 7/26/2019 Pemrograman Web Adam Hendra Brata

    7/18

    Modular Web

  • 7/26/2019 Pemrograman Web Adam Hendra Brata

    8/18

    Konsep modular pada pemrograman web pada

    dasarnya adalah memisah komponen / kodeprogram ke dalam beberapa file / modul yangberbeda

    Kemudian modul / file terpisah ini masing -masing bias jadi akan memiliki tanggung

    jawab yang berbeda

    Modular Web

  • 7/26/2019 Pemrograman Web Adam Hendra Brata

    9/18

    Dalam PHP konsep ini bisa diwujudkan dengan

    menggunakan : include

    include_once

    require

    require_once

    Modular Web

  • 7/26/2019 Pemrograman Web Adam Hendra Brata

    10/18

    Include Syntax : include 'filename' ;

    Contoh :

    Modular Web : Include

    footer.php

    < body>

    < h1>Welcome to my home page!

    < p>Some text.

    Some more text.

    < h2> Hello

    < /body>

    < /html>

    index.php

  • 7/26/2019 Pemrograman Web Adam Hendra Brata

    11/18

    Include Syntax : include_once 'filename' ;

    Contoh :

    Modular Web : Include_Once

    footer.php

    < body>

    < h1>Welcome to my home page!

    < p>Some text.

    Some more text.

    < h2> Hello

    < /body>

    < /html>

    index.php

  • 7/26/2019 Pemrograman Web Adam Hendra Brata

    12/18

    Coba jalankan kode dibawah ini dengan

    include dan include_once, amati yang terjadi

    Modular Web : Include Vs Include_Once

    footer.php

    < body>

    < h1>Welcome to my home page!

    < p>Some text.

    Some more text.

    < /body>< /html>

    index.php

    The include_once function is exactly the

    same as the include function except it will

    limit the file to be used once.

  • 7/26/2019 Pemrograman Web Adam Hendra Brata

    13/18

    Include Syntax : require 'filename' ;

    Contoh :

    Modular Web : Require

    footer.php

    < body>

    < h1>Welcome to my home page!

    < p>Some text.

    Some more text.

    < h2> Hello

    < /body>

    < /html>

    index.php

  • 7/26/2019 Pemrograman Web Adam Hendra Brata

    14/18

    Letakkan file footer di folder / alamat yang

    berbeda dengan index .php dan jalankan fileindex.php

    Modular Web : Include Vs Require

    footer.php

    < body>

    < h1>Welcome to my home page!

    < p>Some text.

    Some more text.

    //ganti dengan

    < h2> Hello include

    < /body>

    < /html>

    index.php

    The require function acts just like the

    include function except if the file can not

    be found it will throw a PHP error.

  • 7/26/2019 Pemrograman Web Adam Hendra Brata

    15/18

    Modular Web : Include Vs Require

    And the conclusion is..

  • 7/26/2019 Pemrograman Web Adam Hendra Brata

    16/18

    Include Syntax : require_once 'filename' ;

    Contoh :

    Modular Web : Require_Once

    footer.php

    < body>

    < h1>Welcome to my home page!

    < p>Some text.

    Some more text.

    < h2> Hello

    < /body>

    < /html>

    index.php

  • 7/26/2019 Pemrograman Web Adam Hendra Brata

    17/18

    Modular Web : Require Vs Require_Once

    require_once adalah fungsi yangmenggabungkan sifat require daninclude_once

    require_once dapat memastikan file yangdibutuhkan ada sebelum ditambahkan ke dalam filedan sebagai tambahan fungsi require_once jugaakan memastikan file yang akan ditambahkan

    tersebut hanya bisa digunakan sekali saja dalam fileyang ingin ditambahkan

  • 7/26/2019 Pemrograman Web Adam Hendra Brata

    18/18

    Terimakasih dan

    SemogaBermanfaat ^