SlideShare a Scribd company logo
Phalcon 
Giant Killer
Jacksonfdam 
http://about.me/jacksonfdam 
https://bitbucket.org/jacksonfdam 
https://github.com/jacksonfdam 
http://linkedin.com/in/jacksonfdam 
@jacksonfdam
A thanks to 
For encourage and believe in the 
passage of knowledge. 
(And to release me from work to be here.) ”
Why? 
• Use of frameworks has become mandatory in 
professional development with PHP 
• They offer a philosophy and organized structures to 
easily maintain projects writing less code and making 
work more fun
How PHP works? 
1. PHP have dynamic and weak typing discipline 
2. PHP is interpreted (not compiled) 
3. Every time a script is loaded, should be interpreted 
by PHP 
4. If a bytecode cache (like APC) isn’t used, syntax 
checking is performed every time
How traditional php frameworks works? 
1. Many files with classes and functions are read at every request made. 
Disk reading is expensive in terms of performance 
2. Modern frameworks use lazy loading technique (autoload) for load and 
execute only code needed 
3. Continuous loading/interpreting could be expensive and impact your 
application performance 
4. When you use a framework most of the code remain the same across 
development. Why load and interpret it every time?
How a PHP C extension works? 
1. C extensions are loaded together with PHP one time, on the web server 
dispatch process 
2. Classes and functions provided by the extension are ready to use for 
any application 
3. The code isn’t interpreted because it is compiled to a specific platform 
and processor
What is Phalcon? 
Phalcon is an open source, full stack framework for PHP 5 
written as a C-extension, optimized for high performance. 
You don’t need to learn or use the C language, since the 
functionality is exposed as PHP classes ready for you to 
use. Phalcon also is loosely coupled, allowing you to use 
its objects as glue components based on the needs of your 
application.
How Phalcon works? 
1. Components are loosely coupled. You may use the components you 
want without depending on a full stack 
2. Low-level optimizations provide the lowest overhead for MVC-based 
applications 
3. Interact with databases with maximum performance by using a C-language 
ORM for PHP 
4. Phalcon is directly engaged with PHP, so it can directly access internal 
structures optimizing execution as well
What is Phalcon?
Compare how Phalcon is faster than other 
frameworks 
Traditional Frameworks Phalcon 
Interpretation of hundreds 
or thousands of PHP lines 
on each request 
YES NO 
Load dozens of files in 
each request 
YES NO 
Checking the existence of 
functions, methods, 
classes, constants at each 
request 
YES NO 
Low-level optimizations 
gaining microseconds for 
each request 
NO YES
Framework Benchmark
Framework Benchmark
Framework Benchmark 
<h1>Hello!</h1>
Test Environment 
Operative System: Mac OS X Snow Leopard 10.6.8 
• Web Server: Apache httpd 2.2.21 
• PHP: 5.3.8 + APC 3.1.9 (Without Xdebug) 
• CPU: 3.06 Ghz Intel Core 2 Duo 
• Main Memory: 4GB 1067 MHz DDR3 
• Hard Disk: 500GB SCSI/SAS HDD
Framework Benchmark 
ab -n 1000 -c 5 http://localhost/bench/phalcon
Framework/Requests per Second
Framework Total Requests/Average Time
Number of Interpreted Files per Request
Allocated Memory per Request
Installation 
To use phalcon on Windows you can download a DLL library. Edit your 
php.ini file and then append at the end: 
extension=php_phalcon.dll 
Restart your webserver.
Requirements 
Prerequisite packages are: 
PHP >= 5.3 development resources 
GCC compiler (Linux/Solaris) 
Git (if not already installed in your system - unless you download the 
package from GitHub and upload it on your server via FTP/SFTP)
Requirements 
Prerequisite packages are: 
PHP >= 5.3 development resources 
GCC compiler (Linux/Solaris) 
Git (if not already installed in your system - unless you download the 
package from GitHub and upload it on your server via FTP/SFTP)
Requirements 
Specific packages for common platforms: 
#Ubuntu 
sudo apt-get install php5-dev libpcre3-dev gcc make php5-mysql 
#Suse 
sudo yast -i gcc make autoconf2.13 php5-devel php5-pear php5-mysql 
#CentOS/RedHat/Fedora 
sudo yum install php-devel pcre-devel gcc make 
#Solaris 
pkg install gcc-45 php-53 apache-php53
Compilation 
git clone --depth=1 git://github.com/phalcon/cphalcon.git 
cd cphalcon/build 
sudo ./install
Configure 
Add extension to your php configuration: 
#Suse: Add this line in your php.ini 
extension=phalcon.so 
#Centos/RedHat/Fedora: Add a file called phalcon.ini in /etc/php.d/ with this content: 
extension=phalcon.so 
#Ubuntu/Debian: Add a file called 30-phalcon.ini in /etc/php.d/ with this content: 
extension=phalcon.so 
#Debian with php5-fpm: Add a file called 30-phalcon.ini in /etc/php5/fpm/conf.d/30-phalcon.ini with this content: 
extension=phalcon.so 
Restart the webserver.
Configure 
Phalcon automatically detects your architecture, however, you can force the compilation for a specific architecture: 
cd cphalon/build 
sudo ./install 32bits 
sudo ./install 64bits 
sudo ./install safe
Mac OS X 
On a Mac OS X system you can compile and install the extension from the source code: 
Requirements 
Prerequisite packages are: 
PHP >= 5.3 development resources 
XCode 
#brew 
brew tap homebrew/homebrew-php 
brew install php53-phalcon 
brew install php54-phalcon 
brew install php55-phalcon 
brew install php56-phalcon 
#MacPorts 
sudo port install php53-phalcon 
sudo port install php54-phalcon 
sudo port install php55-phalcon 
sudo port install php56-phalcon
Installation on XAMPP 
XAMPP is an easy to install Apache distribution containing MySQL, PHP 
and Perl. Once you download XAMPP, all you have to do is extract it and 
start using it. Below are detailed instructions on how to install Phalcon on 
XAMPP for Windows. Using the latest XAMPP version is highly 
recommended.
Installation on XAMPP 
XAMPP is always releasing 32 bit versions of Apache and PHP. You will 
need to download the x86 version of Phalcon for Windows from the 
download section. 
After downloading the Phalcon library you will have a zip file like the one 
shown below:
Installation on XAMPP 
Extract the library from the archive to get the Phalcon DLL:
Installation on XAMPP 
Copy the file php_phalcon.dll to the PHP extensions. If you have installed 
XAMPP in the c:xampp folder, the extension needs to be in 
c:xamppphpext
Installation on XAMPP 
Edit the php.ini file, it is located at C:xamppphpphp.ini. It can be edited with 
Notepad or a similar program. We recommend Notepad++ to avoid issues with line 
endings. Append at the end of the file: extension=php_phalcon.dll and save it.
Installation on XAMPP 
Restart the Apache Web Server from the XAMPP Control Center. This will load the 
new PHP configuration.
Installation on XAMPP 
Open your browser to navigate to 
http://localhost. The XAMPP welcome 
page will appear. Click on the link 
phpinfo(). 
phpinfo() will output a significant 
amount of information on screen about 
the current state of PHP. Scroll down 
to check if the phalcon extension has 
been loaded correctly. 
If you can see the phalcon version in 
the phpinfo() output, congrats!, You 
are now flying with Phalcon.
Creating a project 
File structure 
Phalcon does not impose a particular file structure for application 
development. Due to the fact that it is loosely coupled, you can 
implement Phalcon powered applications with a file structure you are 
most comfortable using.
Creating a project 
For the purposes of this tutorial and as a starting point, we suggest the 
following structure: 
tutorial/ 
app/ 
controllers/ 
models/ 
views/ 
public/ 
css/ 
img/ 
js/
Beautiful URLs 
#/tutorial/.htaccess 
<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteRule ^$ public/ [L] 
RewriteRule (.*) public/$1 [L] 
</IfModule> 
#/tutorial/.htaccess 
<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteRule ^$ public/ [L] 
RewriteRule (.*) public/$1 [L] 
</IfModule>
Bootstrap 
<?php 
try { 
//Register an autoloader 
$loader = new PhalconLoader(); 
$loader->registerDirs(array( 
'../app/controllers/', 
'../app/models/' 
))->register(); 
//Create a DI 
$di = new PhalconDIFactoryDefault(); 
//Setup the view component 
$di->set('view', function(){ 
$view = new PhalconMvcView(); 
$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 PhalconMvcUrl(); 
$url->setBaseUri('/tutorial/'); 
return $url; 
}); 
//Handle the request 
$application = new 
PhalconMvcApplication($di); 
echo $application->handle()->getContent(); 
} catch(PhalconException $e) { 
echo "PhalconException: ", $e->getMessage(); 
}
Creating a Controller 
By default Phalcon will look for a controller named “Index”. It is the starting point when no controller or action has been passed in 
the request. The index controller (app/controllers/IndexController.php) looks like: 
<?php 
class IndexController extends PhalconMvcController 
{ 
public function indexAction() 
{ 
echo "<h1>Hello!</h1>"; 
} 
}
Creating a Controller 
Sending output to a view 
Sending output to the screen from the controller is at times necessary but not desirable as most purists in the MVC community will 
attest. Everything must be passed to the view that is responsible for outputting data on screen. Phalcon will look for a view with the 
same name as the last executed action inside a directory named as the last executed controller. In our case 
(app/views/index/index.phtml): 
<?php echo "<h1>Hello!</h1>"; 
Our controller (app/controllers/IndexController.php) now has an empty action definition: 
<?php 
class IndexController extends PhalconMvcController 
{ 
public function indexAction() 
{ 
} 
}
Creating a Model 
Phalcon brings the first ORM for PHP entirely written in C-language. Instead of increasing the complexity of development, it 
simplifies it. 
Before creating our first model, we need to create a database table outside of Phalcon to map it to. A simple table to store 
registered users can be defined like this: 
CREATE TABLE `users` ( 
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, 
`name` varchar(70) NOT NULL, 
`email` varchar(70) NOT NULL, 
PRIMARY KEY (`id`) 
);
Creating a Model 
A model should be located in the app/models directory (app/models/Users.php). The model maps to the “users” table: 
<?php 
class Users extends PhalconMvcModel 
{ 
}
Setting a Database Connection 
In order to be able to use a database connection and subsequently access data through our models, we need to specify it in our 
bootstrap process. A database connection is just another service that our application has that can be used for several 
components:
Setting a Database Connection 
<?php 
try { 
//Register an autoloader 
$loader = new PhalconLoader(); 
$loader->registerDirs(array( 
'../app/controllers/', 
'../app/models/' 
))->register(); 
//Create a DI 
$di = new PhalconDIFactoryDefault(); 
/ 
/Setup the database service 
$di->set('db', function(){ 
return new 
PhalconDbAdapterPdoMysql(array( 
"host" => "localhost", 
"username" => "root", 
"password" => "secret", 
"dbname" => "test_db" 
)); 
}); 
//Setup the view component 
$di->set('view', function(){ 
$view = new PhalconMvcView(); 
$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 PhalconMvcUrl(); 
$url->setBaseUri('/tutorial/'); 
return $url; 
}); 
//Handle the request 
$application = new 
PhalconMvcApplication($di); 
echo $application->handle()->getContent(); 
} catch(Exception $e) { 
echo "PhalconException: ", $e->getMessage(); 
}
Volt: Template Engine 
Volt is an ultra-fast and designer friendly templating language written in C for 
PHP. It provides you a set of helpers to write views in an easy way. Volt is 
highly integrated with other components of Phalcon, just as you can use it as a 
stand-alone component in your applications.
Volt: Template Engine
Volt: Template Engine 
Volt views are compiled to pure PHP code, so basically they save the effort of writing PHP code 
manually: 
{# app/views/products/show.volt #}{% block last_products %}{% for product in products %} 
* Name: {{ product.name|e }} 
{% if product.status == "Active" %} 
Price: {{ product.price + product.taxes/100 }} 
{% endif %}{% endfor %}{% endblock %}
Thank you. 
@jacksonfdam
Ad

More Related Content

What's hot (20)

Console Apps: php artisan forthe:win
Console Apps: php artisan forthe:winConsole Apps: php artisan forthe:win
Console Apps: php artisan forthe:win
Joe Ferguson
 
All the Laravel things: up and running to making $$
All the Laravel things: up and running to making $$All the Laravel things: up and running to making $$
All the Laravel things: up and running to making $$
Joe Ferguson
 
Lamp Zend Security
Lamp Zend SecurityLamp Zend Security
Lamp Zend Security
Ram Srivastava
 
Joomlatools Platform v2.0
Joomlatools Platform v2.0Joomlatools Platform v2.0
Joomlatools Platform v2.0
Joomlatools
 
[Part 1] automation of home appliances using raspberry pi – software installa...
[Part 1] automation of home appliances using raspberry pi – software installa...[Part 1] automation of home appliances using raspberry pi – software installa...
[Part 1] automation of home appliances using raspberry pi – software installa...
Azilen Technologies Pvt. Ltd.
 
10 less-known Laravel Packages: April 2016
10 less-known Laravel Packages: April 201610 less-known Laravel Packages: April 2016
10 less-known Laravel Packages: April 2016
Povilas Korop
 
Reverse Installing CPAN
Reverse Installing CPANReverse Installing CPAN
Reverse Installing CPAN
brian d foy
 
Console Apps: php artisan forthe:win
Console Apps: php artisan forthe:win Console Apps: php artisan forthe:win
Console Apps: php artisan forthe:win
Joe Ferguson
 
php[world] 2015 Laravel 5.1: From Homestead to the Cloud
php[world] 2015 Laravel 5.1: From Homestead to the Cloudphp[world] 2015 Laravel 5.1: From Homestead to the Cloud
php[world] 2015 Laravel 5.1: From Homestead to the Cloud
Joe Ferguson
 
Swoole Love PHP
Swoole Love PHPSwoole Love PHP
Swoole Love PHP
Yi-Feng Tzeng
 
30 Skills to Master to Become a Senior Software Engineer
30 Skills to Master to Become a Senior Software Engineer30 Skills to Master to Become a Senior Software Engineer
30 Skills to Master to Become a Senior Software Engineer
Sean Coates
 
10 Laravel packages everyone should know
10 Laravel packages everyone should know10 Laravel packages everyone should know
10 Laravel packages everyone should know
Povilas Korop
 
So You Just Inherited a $Legacy Application… NomadPHP July 2016
So You Just Inherited a $Legacy Application… NomadPHP July 2016So You Just Inherited a $Legacy Application… NomadPHP July 2016
So You Just Inherited a $Legacy Application… NomadPHP July 2016
Joe Ferguson
 
Cakephp
CakephpCakephp
Cakephp
Khalid Alharbi
 
Pharo JS
Pharo JSPharo JS
Pharo JS
Pharo
 
Composer Helpdesk
Composer HelpdeskComposer Helpdesk
Composer Helpdesk
Sven Rautenberg
 
Lamp
LampLamp
Lamp
anurag1p
 
PHP Dependency Management with Composer
PHP Dependency Management with ComposerPHP Dependency Management with Composer
PHP Dependency Management with Composer
Adam Englander
 
Joomladay Netherlands 2012 - Joomla in the Cloud
Joomladay Netherlands 2012  - Joomla in the CloudJoomladay Netherlands 2012  - Joomla in the Cloud
Joomladay Netherlands 2012 - Joomla in the Cloud
Johan Janssens
 
How composer saved PHP
How composer saved PHPHow composer saved PHP
How composer saved PHP
Ryan Kilfedder
 
Console Apps: php artisan forthe:win
Console Apps: php artisan forthe:winConsole Apps: php artisan forthe:win
Console Apps: php artisan forthe:win
Joe Ferguson
 
All the Laravel things: up and running to making $$
All the Laravel things: up and running to making $$All the Laravel things: up and running to making $$
All the Laravel things: up and running to making $$
Joe Ferguson
 
Joomlatools Platform v2.0
Joomlatools Platform v2.0Joomlatools Platform v2.0
Joomlatools Platform v2.0
Joomlatools
 
[Part 1] automation of home appliances using raspberry pi – software installa...
[Part 1] automation of home appliances using raspberry pi – software installa...[Part 1] automation of home appliances using raspberry pi – software installa...
[Part 1] automation of home appliances using raspberry pi – software installa...
Azilen Technologies Pvt. Ltd.
 
10 less-known Laravel Packages: April 2016
10 less-known Laravel Packages: April 201610 less-known Laravel Packages: April 2016
10 less-known Laravel Packages: April 2016
Povilas Korop
 
Reverse Installing CPAN
Reverse Installing CPANReverse Installing CPAN
Reverse Installing CPAN
brian d foy
 
Console Apps: php artisan forthe:win
Console Apps: php artisan forthe:win Console Apps: php artisan forthe:win
Console Apps: php artisan forthe:win
Joe Ferguson
 
php[world] 2015 Laravel 5.1: From Homestead to the Cloud
php[world] 2015 Laravel 5.1: From Homestead to the Cloudphp[world] 2015 Laravel 5.1: From Homestead to the Cloud
php[world] 2015 Laravel 5.1: From Homestead to the Cloud
Joe Ferguson
 
30 Skills to Master to Become a Senior Software Engineer
30 Skills to Master to Become a Senior Software Engineer30 Skills to Master to Become a Senior Software Engineer
30 Skills to Master to Become a Senior Software Engineer
Sean Coates
 
10 Laravel packages everyone should know
10 Laravel packages everyone should know10 Laravel packages everyone should know
10 Laravel packages everyone should know
Povilas Korop
 
So You Just Inherited a $Legacy Application… NomadPHP July 2016
So You Just Inherited a $Legacy Application… NomadPHP July 2016So You Just Inherited a $Legacy Application… NomadPHP July 2016
So You Just Inherited a $Legacy Application… NomadPHP July 2016
Joe Ferguson
 
Pharo JS
Pharo JSPharo JS
Pharo JS
Pharo
 
PHP Dependency Management with Composer
PHP Dependency Management with ComposerPHP Dependency Management with Composer
PHP Dependency Management with Composer
Adam Englander
 
Joomladay Netherlands 2012 - Joomla in the Cloud
Joomladay Netherlands 2012  - Joomla in the CloudJoomladay Netherlands 2012  - Joomla in the Cloud
Joomladay Netherlands 2012 - Joomla in the Cloud
Johan Janssens
 
How composer saved PHP
How composer saved PHPHow composer saved PHP
How composer saved PHP
Ryan Kilfedder
 

Similar to Phalcon - Giant Killer (20)

PHP Conference - Phalcon hands-on
PHP Conference - Phalcon hands-onPHP Conference - Phalcon hands-on
PHP Conference - Phalcon hands-on
Jackson F. de A. Mafra
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
tutorialsruby
 
Updating_PHP_on_OS_X_Server
Updating_PHP_on_OS_X_ServerUpdating_PHP_on_OS_X_Server
Updating_PHP_on_OS_X_Server
tutorialsruby
 
Updating_PHP_on_OS_X_Server
Updating_PHP_on_OS_X_ServerUpdating_PHP_on_OS_X_Server
Updating_PHP_on_OS_X_Server
tutorialsruby
 
Php ppt
Php pptPhp ppt
Php ppt
Sanmuga Nathan
 
Step-by-Step Introduction to Apache Flink
Step-by-Step Introduction to Apache Flink Step-by-Step Introduction to Apache Flink
Step-by-Step Introduction to Apache Flink
Slim Baltagi
 
Phalcon
PhalconPhalcon
Phalcon
Jyotisankar Pradhan
 
Lumen
LumenLumen
Lumen
Joshua Copeland
 
APACHE
APACHEAPACHE
APACHE
ARJUN
 
Its3 Drupal
Its3 DrupalIts3 Drupal
Its3 Drupal
guest954945a
 
Its3 Drupal
Its3 DrupalIts3 Drupal
Its3 Drupal
guest954945a
 
Running Symfony
Running SymfonyRunning Symfony
Running Symfony
Wildan Maulana
 
Wamp & LAMP - Installation and Configuration
Wamp & LAMP - Installation and ConfigurationWamp & LAMP - Installation and Configuration
Wamp & LAMP - Installation and Configuration
Chetan Soni
 
Php through the eyes of a hoster confoo
Php through the eyes of a hoster confooPhp through the eyes of a hoster confoo
Php through the eyes of a hoster confoo
Combell NV
 
Composer Lightning Talk
Composer Lightning TalkComposer Lightning Talk
Composer Lightning Talk
Eric Johnson
 
25 Intro to Symfony #burningkeyboards
25 Intro to Symfony #burningkeyboards25 Intro to Symfony #burningkeyboards
25 Intro to Symfony #burningkeyboards
Denis Ristic
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
MAGNA COLLEGE OF ENGINEERING
 
Php
PhpPhp
Php
anandha ganesh
 
John's Top PECL Picks
John's Top PECL PicksJohn's Top PECL Picks
John's Top PECL Picks
John Coggeshall
 
Php Applications with Oracle by Kuassi Mensah
Php Applications with Oracle by Kuassi MensahPhp Applications with Oracle by Kuassi Mensah
Php Applications with Oracle by Kuassi Mensah
PHP Barcelona Conference
 
Ad

More from Jackson F. de A. Mafra (20)

PHP Conference 2020 - A eterna luta: compatibilidade retroativa vs. dívida té...
PHP Conference 2020 - A eterna luta: compatibilidade retroativa vs. dívida té...PHP Conference 2020 - A eterna luta: compatibilidade retroativa vs. dívida té...
PHP Conference 2020 - A eterna luta: compatibilidade retroativa vs. dívida té...
Jackson F. de A. Mafra
 
PHP SSO no Zentyal
PHP SSO no ZentyalPHP SSO no Zentyal
PHP SSO no Zentyal
Jackson F. de A. Mafra
 
Phprs meetup - deploys automatizados com gitlab
Phprs   meetup - deploys automatizados com gitlabPhprs   meetup - deploys automatizados com gitlab
Phprs meetup - deploys automatizados com gitlab
Jackson F. de A. Mafra
 
O que você precisa saber sobre chatbots
O que você precisa saber sobre chatbotsO que você precisa saber sobre chatbots
O que você precisa saber sobre chatbots
Jackson F. de A. Mafra
 
WCPOA2019 - WordPress como um backend de seus aplicativos
WCPOA2019  - WordPress como um backend de seus aplicativosWCPOA2019  - WordPress como um backend de seus aplicativos
WCPOA2019 - WordPress como um backend de seus aplicativos
Jackson F. de A. Mafra
 
WordPress como um backend de seus aplicativos
WordPress como um backend de seus aplicativosWordPress como um backend de seus aplicativos
WordPress como um backend de seus aplicativos
Jackson F. de A. Mafra
 
The Ultimate Guide to Development in WordPress
The Ultimate Guide to Development in WordPressThe Ultimate Guide to Development in WordPress
The Ultimate Guide to Development in WordPress
Jackson F. de A. Mafra
 
Precisamos de um barco maior introdução ao dimensionamento de aplicações
Precisamos de um barco maior introdução ao dimensionamento de aplicaçõesPrecisamos de um barco maior introdução ao dimensionamento de aplicações
Precisamos de um barco maior introdução ao dimensionamento de aplicações
Jackson F. de A. Mafra
 
Hangout Tempo Real Eventos - ChatOps (ChatBots e DevOps) - Como bots podem ...
Hangout  Tempo Real Eventos - ChatOps (ChatBots e DevOps)  - Como bots podem ...Hangout  Tempo Real Eventos - ChatOps (ChatBots e DevOps)  - Como bots podem ...
Hangout Tempo Real Eventos - ChatOps (ChatBots e DevOps) - Como bots podem ...
Jackson F. de A. Mafra
 
Hangout Tempo Real Eventos - Android - Os primeiros passos do desenvolviment...
Hangout  Tempo Real Eventos - Android - Os primeiros passos do desenvolviment...Hangout  Tempo Real Eventos - Android - Os primeiros passos do desenvolviment...
Hangout Tempo Real Eventos - Android - Os primeiros passos do desenvolviment...
Jackson F. de A. Mafra
 
Hangout Tempo Real Eventos - Javascript - Os Primeiros Passos
Hangout  Tempo Real Eventos - Javascript - Os Primeiros PassosHangout  Tempo Real Eventos - Javascript - Os Primeiros Passos
Hangout Tempo Real Eventos - Javascript - Os Primeiros Passos
Jackson F. de A. Mafra
 
Hangout Tempo Real Eventos - Nodejs - Os Primeiros Passos
Hangout  Tempo Real Eventos - Nodejs - Os Primeiros PassosHangout  Tempo Real Eventos - Nodejs - Os Primeiros Passos
Hangout Tempo Real Eventos - Nodejs - Os Primeiros Passos
Jackson F. de A. Mafra
 
Desmistificando o DialogFlow
Desmistificando o DialogFlowDesmistificando o DialogFlow
Desmistificando o DialogFlow
Jackson F. de A. Mafra
 
ChatOps (ChatBots + DevOps)
ChatOps (ChatBots + DevOps) ChatOps (ChatBots + DevOps)
ChatOps (ChatBots + DevOps)
Jackson F. de A. Mafra
 
Conexao kinghost - Vendas inteligentes com intelibots
Conexao kinghost - Vendas inteligentes com intelibotsConexao kinghost - Vendas inteligentes com intelibots
Conexao kinghost - Vendas inteligentes com intelibots
Jackson F. de A. Mafra
 
WoMakersCode 2016 - Shit Happens
WoMakersCode 2016 -  Shit HappensWoMakersCode 2016 -  Shit Happens
WoMakersCode 2016 - Shit Happens
Jackson F. de A. Mafra
 
Phalcon 2 High Performance APIs - DevWeekPOA 2015
Phalcon 2 High Performance APIs - DevWeekPOA 2015Phalcon 2 High Performance APIs - DevWeekPOA 2015
Phalcon 2 High Performance APIs - DevWeekPOA 2015
Jackson F. de A. Mafra
 
Dev Heroes
Dev HeroesDev Heroes
Dev Heroes
Jackson F. de A. Mafra
 
Trilha Android - Android Evolved
Trilha Android - Android EvolvedTrilha Android - Android Evolved
Trilha Android - Android Evolved
Jackson F. de A. Mafra
 
TDC 2015 - POA - Trilha PHP - Shit Happens
TDC 2015 - POA - Trilha PHP - Shit HappensTDC 2015 - POA - Trilha PHP - Shit Happens
TDC 2015 - POA - Trilha PHP - Shit Happens
Jackson F. de A. Mafra
 
PHP Conference 2020 - A eterna luta: compatibilidade retroativa vs. dívida té...
PHP Conference 2020 - A eterna luta: compatibilidade retroativa vs. dívida té...PHP Conference 2020 - A eterna luta: compatibilidade retroativa vs. dívida té...
PHP Conference 2020 - A eterna luta: compatibilidade retroativa vs. dívida té...
Jackson F. de A. Mafra
 
Phprs meetup - deploys automatizados com gitlab
Phprs   meetup - deploys automatizados com gitlabPhprs   meetup - deploys automatizados com gitlab
Phprs meetup - deploys automatizados com gitlab
Jackson F. de A. Mafra
 
O que você precisa saber sobre chatbots
O que você precisa saber sobre chatbotsO que você precisa saber sobre chatbots
O que você precisa saber sobre chatbots
Jackson F. de A. Mafra
 
WCPOA2019 - WordPress como um backend de seus aplicativos
WCPOA2019  - WordPress como um backend de seus aplicativosWCPOA2019  - WordPress como um backend de seus aplicativos
WCPOA2019 - WordPress como um backend de seus aplicativos
Jackson F. de A. Mafra
 
WordPress como um backend de seus aplicativos
WordPress como um backend de seus aplicativosWordPress como um backend de seus aplicativos
WordPress como um backend de seus aplicativos
Jackson F. de A. Mafra
 
The Ultimate Guide to Development in WordPress
The Ultimate Guide to Development in WordPressThe Ultimate Guide to Development in WordPress
The Ultimate Guide to Development in WordPress
Jackson F. de A. Mafra
 
Precisamos de um barco maior introdução ao dimensionamento de aplicações
Precisamos de um barco maior introdução ao dimensionamento de aplicaçõesPrecisamos de um barco maior introdução ao dimensionamento de aplicações
Precisamos de um barco maior introdução ao dimensionamento de aplicações
Jackson F. de A. Mafra
 
Hangout Tempo Real Eventos - ChatOps (ChatBots e DevOps) - Como bots podem ...
Hangout  Tempo Real Eventos - ChatOps (ChatBots e DevOps)  - Como bots podem ...Hangout  Tempo Real Eventos - ChatOps (ChatBots e DevOps)  - Como bots podem ...
Hangout Tempo Real Eventos - ChatOps (ChatBots e DevOps) - Como bots podem ...
Jackson F. de A. Mafra
 
Hangout Tempo Real Eventos - Android - Os primeiros passos do desenvolviment...
Hangout  Tempo Real Eventos - Android - Os primeiros passos do desenvolviment...Hangout  Tempo Real Eventos - Android - Os primeiros passos do desenvolviment...
Hangout Tempo Real Eventos - Android - Os primeiros passos do desenvolviment...
Jackson F. de A. Mafra
 
Hangout Tempo Real Eventos - Javascript - Os Primeiros Passos
Hangout  Tempo Real Eventos - Javascript - Os Primeiros PassosHangout  Tempo Real Eventos - Javascript - Os Primeiros Passos
Hangout Tempo Real Eventos - Javascript - Os Primeiros Passos
Jackson F. de A. Mafra
 
Hangout Tempo Real Eventos - Nodejs - Os Primeiros Passos
Hangout  Tempo Real Eventos - Nodejs - Os Primeiros PassosHangout  Tempo Real Eventos - Nodejs - Os Primeiros Passos
Hangout Tempo Real Eventos - Nodejs - Os Primeiros Passos
Jackson F. de A. Mafra
 
Conexao kinghost - Vendas inteligentes com intelibots
Conexao kinghost - Vendas inteligentes com intelibotsConexao kinghost - Vendas inteligentes com intelibots
Conexao kinghost - Vendas inteligentes com intelibots
Jackson F. de A. Mafra
 
Phalcon 2 High Performance APIs - DevWeekPOA 2015
Phalcon 2 High Performance APIs - DevWeekPOA 2015Phalcon 2 High Performance APIs - DevWeekPOA 2015
Phalcon 2 High Performance APIs - DevWeekPOA 2015
Jackson F. de A. Mafra
 
TDC 2015 - POA - Trilha PHP - Shit Happens
TDC 2015 - POA - Trilha PHP - Shit HappensTDC 2015 - POA - Trilha PHP - Shit Happens
TDC 2015 - POA - Trilha PHP - Shit Happens
Jackson F. de A. Mafra
 
Ad

Recently uploaded (20)

Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 

Phalcon - Giant Killer

  • 2. Jacksonfdam http://about.me/jacksonfdam https://bitbucket.org/jacksonfdam https://github.com/jacksonfdam http://linkedin.com/in/jacksonfdam @jacksonfdam
  • 3. A thanks to For encourage and believe in the passage of knowledge. (And to release me from work to be here.) ”
  • 4. Why? • Use of frameworks has become mandatory in professional development with PHP • They offer a philosophy and organized structures to easily maintain projects writing less code and making work more fun
  • 5. How PHP works? 1. PHP have dynamic and weak typing discipline 2. PHP is interpreted (not compiled) 3. Every time a script is loaded, should be interpreted by PHP 4. If a bytecode cache (like APC) isn’t used, syntax checking is performed every time
  • 6. How traditional php frameworks works? 1. Many files with classes and functions are read at every request made. Disk reading is expensive in terms of performance 2. Modern frameworks use lazy loading technique (autoload) for load and execute only code needed 3. Continuous loading/interpreting could be expensive and impact your application performance 4. When you use a framework most of the code remain the same across development. Why load and interpret it every time?
  • 7. How a PHP C extension works? 1. C extensions are loaded together with PHP one time, on the web server dispatch process 2. Classes and functions provided by the extension are ready to use for any application 3. The code isn’t interpreted because it is compiled to a specific platform and processor
  • 8. What is Phalcon? Phalcon is an open source, full stack framework for PHP 5 written as a C-extension, optimized for high performance. You don’t need to learn or use the C language, since the functionality is exposed as PHP classes ready for you to use. Phalcon also is loosely coupled, allowing you to use its objects as glue components based on the needs of your application.
  • 9. How Phalcon works? 1. Components are loosely coupled. You may use the components you want without depending on a full stack 2. Low-level optimizations provide the lowest overhead for MVC-based applications 3. Interact with databases with maximum performance by using a C-language ORM for PHP 4. Phalcon is directly engaged with PHP, so it can directly access internal structures optimizing execution as well
  • 11. Compare how Phalcon is faster than other frameworks Traditional Frameworks Phalcon Interpretation of hundreds or thousands of PHP lines on each request YES NO Load dozens of files in each request YES NO Checking the existence of functions, methods, classes, constants at each request YES NO Low-level optimizations gaining microseconds for each request NO YES
  • 15. Test Environment Operative System: Mac OS X Snow Leopard 10.6.8 • Web Server: Apache httpd 2.2.21 • PHP: 5.3.8 + APC 3.1.9 (Without Xdebug) • CPU: 3.06 Ghz Intel Core 2 Duo • Main Memory: 4GB 1067 MHz DDR3 • Hard Disk: 500GB SCSI/SAS HDD
  • 16. Framework Benchmark ab -n 1000 -c 5 http://localhost/bench/phalcon
  • 19. Number of Interpreted Files per Request
  • 21. Installation To use phalcon on Windows you can download a DLL library. Edit your php.ini file and then append at the end: extension=php_phalcon.dll Restart your webserver.
  • 22. Requirements Prerequisite packages are: PHP >= 5.3 development resources GCC compiler (Linux/Solaris) Git (if not already installed in your system - unless you download the package from GitHub and upload it on your server via FTP/SFTP)
  • 23. Requirements Prerequisite packages are: PHP >= 5.3 development resources GCC compiler (Linux/Solaris) Git (if not already installed in your system - unless you download the package from GitHub and upload it on your server via FTP/SFTP)
  • 24. Requirements Specific packages for common platforms: #Ubuntu sudo apt-get install php5-dev libpcre3-dev gcc make php5-mysql #Suse sudo yast -i gcc make autoconf2.13 php5-devel php5-pear php5-mysql #CentOS/RedHat/Fedora sudo yum install php-devel pcre-devel gcc make #Solaris pkg install gcc-45 php-53 apache-php53
  • 25. Compilation git clone --depth=1 git://github.com/phalcon/cphalcon.git cd cphalcon/build sudo ./install
  • 26. Configure Add extension to your php configuration: #Suse: Add this line in your php.ini extension=phalcon.so #Centos/RedHat/Fedora: Add a file called phalcon.ini in /etc/php.d/ with this content: extension=phalcon.so #Ubuntu/Debian: Add a file called 30-phalcon.ini in /etc/php.d/ with this content: extension=phalcon.so #Debian with php5-fpm: Add a file called 30-phalcon.ini in /etc/php5/fpm/conf.d/30-phalcon.ini with this content: extension=phalcon.so Restart the webserver.
  • 27. Configure Phalcon automatically detects your architecture, however, you can force the compilation for a specific architecture: cd cphalon/build sudo ./install 32bits sudo ./install 64bits sudo ./install safe
  • 28. Mac OS X On a Mac OS X system you can compile and install the extension from the source code: Requirements Prerequisite packages are: PHP >= 5.3 development resources XCode #brew brew tap homebrew/homebrew-php brew install php53-phalcon brew install php54-phalcon brew install php55-phalcon brew install php56-phalcon #MacPorts sudo port install php53-phalcon sudo port install php54-phalcon sudo port install php55-phalcon sudo port install php56-phalcon
  • 29. Installation on XAMPP XAMPP is an easy to install Apache distribution containing MySQL, PHP and Perl. Once you download XAMPP, all you have to do is extract it and start using it. Below are detailed instructions on how to install Phalcon on XAMPP for Windows. Using the latest XAMPP version is highly recommended.
  • 30. Installation on XAMPP XAMPP is always releasing 32 bit versions of Apache and PHP. You will need to download the x86 version of Phalcon for Windows from the download section. After downloading the Phalcon library you will have a zip file like the one shown below:
  • 31. Installation on XAMPP Extract the library from the archive to get the Phalcon DLL:
  • 32. Installation on XAMPP Copy the file php_phalcon.dll to the PHP extensions. If you have installed XAMPP in the c:xampp folder, the extension needs to be in c:xamppphpext
  • 33. Installation on XAMPP Edit the php.ini file, it is located at C:xamppphpphp.ini. It can be edited with Notepad or a similar program. We recommend Notepad++ to avoid issues with line endings. Append at the end of the file: extension=php_phalcon.dll and save it.
  • 34. Installation on XAMPP Restart the Apache Web Server from the XAMPP Control Center. This will load the new PHP configuration.
  • 35. Installation on XAMPP Open your browser to navigate to http://localhost. The XAMPP welcome page will appear. Click on the link phpinfo(). phpinfo() will output a significant amount of information on screen about the current state of PHP. Scroll down to check if the phalcon extension has been loaded correctly. If you can see the phalcon version in the phpinfo() output, congrats!, You are now flying with Phalcon.
  • 36. Creating a project File structure Phalcon does not impose a particular file structure for application development. Due to the fact that it is loosely coupled, you can implement Phalcon powered applications with a file structure you are most comfortable using.
  • 37. Creating a project For the purposes of this tutorial and as a starting point, we suggest the following structure: tutorial/ app/ controllers/ models/ views/ public/ css/ img/ js/
  • 38. Beautiful URLs #/tutorial/.htaccess <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ public/ [L] RewriteRule (.*) public/$1 [L] </IfModule> #/tutorial/.htaccess <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ public/ [L] RewriteRule (.*) public/$1 [L] </IfModule>
  • 39. Bootstrap <?php try { //Register an autoloader $loader = new PhalconLoader(); $loader->registerDirs(array( '../app/controllers/', '../app/models/' ))->register(); //Create a DI $di = new PhalconDIFactoryDefault(); //Setup the view component $di->set('view', function(){ $view = new PhalconMvcView(); $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 PhalconMvcUrl(); $url->setBaseUri('/tutorial/'); return $url; }); //Handle the request $application = new PhalconMvcApplication($di); echo $application->handle()->getContent(); } catch(PhalconException $e) { echo "PhalconException: ", $e->getMessage(); }
  • 40. Creating a Controller By default Phalcon will look for a controller named “Index”. It is the starting point when no controller or action has been passed in the request. The index controller (app/controllers/IndexController.php) looks like: <?php class IndexController extends PhalconMvcController { public function indexAction() { echo "<h1>Hello!</h1>"; } }
  • 41. Creating a Controller Sending output to a view Sending output to the screen from the controller is at times necessary but not desirable as most purists in the MVC community will attest. Everything must be passed to the view that is responsible for outputting data on screen. Phalcon will look for a view with the same name as the last executed action inside a directory named as the last executed controller. In our case (app/views/index/index.phtml): <?php echo "<h1>Hello!</h1>"; Our controller (app/controllers/IndexController.php) now has an empty action definition: <?php class IndexController extends PhalconMvcController { public function indexAction() { } }
  • 42. Creating a Model Phalcon brings the first ORM for PHP entirely written in C-language. Instead of increasing the complexity of development, it simplifies it. Before creating our first model, we need to create a database table outside of Phalcon to map it to. A simple table to store registered users can be defined like this: CREATE TABLE `users` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(70) NOT NULL, `email` varchar(70) NOT NULL, PRIMARY KEY (`id`) );
  • 43. Creating a Model A model should be located in the app/models directory (app/models/Users.php). The model maps to the “users” table: <?php class Users extends PhalconMvcModel { }
  • 44. Setting a Database Connection In order to be able to use a database connection and subsequently access data through our models, we need to specify it in our bootstrap process. A database connection is just another service that our application has that can be used for several components:
  • 45. Setting a Database Connection <?php try { //Register an autoloader $loader = new PhalconLoader(); $loader->registerDirs(array( '../app/controllers/', '../app/models/' ))->register(); //Create a DI $di = new PhalconDIFactoryDefault(); / /Setup the database service $di->set('db', function(){ return new PhalconDbAdapterPdoMysql(array( "host" => "localhost", "username" => "root", "password" => "secret", "dbname" => "test_db" )); }); //Setup the view component $di->set('view', function(){ $view = new PhalconMvcView(); $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 PhalconMvcUrl(); $url->setBaseUri('/tutorial/'); return $url; }); //Handle the request $application = new PhalconMvcApplication($di); echo $application->handle()->getContent(); } catch(Exception $e) { echo "PhalconException: ", $e->getMessage(); }
  • 46. Volt: Template Engine Volt is an ultra-fast and designer friendly templating language written in C for PHP. It provides you a set of helpers to write views in an easy way. Volt is highly integrated with other components of Phalcon, just as you can use it as a stand-alone component in your applications.
  • 48. Volt: Template Engine Volt views are compiled to pure PHP code, so basically they save the effort of writing PHP code manually: {# app/views/products/show.volt #}{% block last_products %}{% for product in products %} * Name: {{ product.name|e }} {% if product.status == "Active" %} Price: {{ product.price + product.taxes/100 }} {% endif %}{% endfor %}{% endblock %}