Hello

Welcome To BOLD

This Awesome Blogger Template is Brought To You By Bthemez, Let's be friends and spread the love
together in the world. #nohomo :P
Join us on

Membuat Aplikasi “Hello World!” dengan Phalcon Framework PHP

Dalam tutorial ini kita akan coba membuat “Hello World” dengan Phalcon Framework PHP. Sebelum menggunakan phalcon anda harus memasang .dll phalcon di dalam xampp (Meng-install Phalcon Framework PHP di Windows).
Buatlah folder dan beberapa file seperti berikut :
Capture1
Buka file Phalcon_HelloWorld/.htaccess masukan souce code dibawah ini :
<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteRule ^$ public_html/ [L]
 RewriteRule (.*) public_html/$1 [L]
</IfModule>
.htaccess
Semua request ke aplikasi akan di-rewrite ke direktori public_html/ membuatnya sebagai dokumen root. Langkah ini memastikan bahwa folder internal sistem tetap tersembunyi dari pandangan public dan meng-eliminasi acaman keamanan pada celan ini.
Buka file ke dua Phalcon_HelloWorld/public_html/.htaccess
<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^(.*) index.php?_url=/$1 [QSA,L]
</IfModule>
public_html/.htaccess
Kemudian kita akan membuat file bootsrap. File ini sangat penting karna bertindak sebagai dasar aplikasi dapat memerikan anda semua kendali.
Phalcon_HelloWorld/public/index.php
<?php
 
try {
 
    //Register an autoloader
    $loader = new \Phalcon\Loader();
    $loader->registerDirs(array(
        '../app/controllers/',
        '../app/models/'
    ))->register();
 
    //Create a DI
    $di = new Phalcon\DI\FactoryDefault();
 
    //Setup the view component
    $di->set('view', function(){
        $view = new \Phalcon\Mvc\View();
        $view->setViewsDir('../app/views/');
        return $view;
    });
 
    //Setup a base URI so that all generated URIs include the "tutorial" folder
    $di->set('url', function(){
        $url = new \Phalcon\Mvc\Url();
        $url->setBaseUri('/Phalcon_HelloWorld/');
        return $url;
    });
 
    //Handle the request
    $application = new \Phalcon\Mvc\Application($di);
 
    echo $application->handle()->getContent();
 
} catch(\Phalcon\Exception $e) {
     echo "PhalconException: ", $e->getMessage();
}
public_html/index.php
Membuat controller secara default Phalcon akan mencari controller bernama “Index”. Ini adalah titik awal ketika tidak ada controller atau tindakan yang diminta dalam request. Buat file baru bernama IndexController.php didalam folder Phalcon_HelloWorld/app/controllers/IndexController.php
<?php
 
class IndexController extends \Phalcon\Mvc\Controller
{
 
    public function indexAction()
    {
        echo "<h1>Hello World!</h1>";
    }
 
}
app/controller/IndexController.php
Class controller harus memiliki akhiran “Controller” dan action pada controller harus memiliki akhiran “Action”.  Jika sudah selesai mengikuti semua tutorial diatas maka susunan folder akan terlihat seperti ini :
Capture2
Sekarang coba kita lihat di browser, jika sudah benar maka akan terlihat seperti ini http://localhost:8080/Phalcon_HelloWorld/
Untitled1
Selamat Anda sudah selesai mempelajari dasar tentang phalcon framework :D

Share this:

ABOUTME

Hi all. This is deepak from Bthemez. We're providing content for Bold site and we’ve been in internet, social media and affiliate for too long time and its my profession. We are web designer & developer living India! What can I say, we are the best..

JOIN CONVERSATION

    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment