Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction Phalcon PHP

Thiện
September 07, 2015

Introduction Phalcon PHP

Meetup Phalcon PHP and Zephir

Thiện

September 07, 2015
Tweet

More Decks by Thiện

Other Decks in Education

Transcript

  1. Phalcon PHP: A Quick Introduction About me Thien Tran Duy

    PHP developer since 2012 User 571 on phalconphp.com Loves open source developments Open Company [email protected] September 7, 2015 PHP Saigon (meetup) Phalcon September 7, 2015 1 / 14
  2. Summary There are over 20 different open source PHP frameworks,

    ranging from full-stack frameworks to micro frameworks. And each framework have special feature, which could be speed, documentation, beautiful syntax, or anything else. But Phalcon PHP is the next big thing in PHP frameworks. 1 What is a Phalcon PHP 2 Why using Phalcon PHP 3 In Conclusions PHP Saigon (meetup) Phalcon September 7, 2015 2 / 14
  3. Information What is Phalcon? Phalcon is an open source, full

    stack framework for PHP written as a C-extension, optimized for high performance. While discussing Phalcon its easy to forget that performance is not the only feature. Phalcon is a full stack framework and can do a lot 1 It have basic feature such as Auto-loader, router, MVC, DI, REST PHP Saigon (meetup) Phalcon September 7, 2015 3 / 14
  4. Information What is Phalcon? Phalcon is an open source, full

    stack framework for PHP written as a C-extension, optimized for high performance. While discussing Phalcon its easy to forget that performance is not the only feature. Phalcon is a full stack framework and can do a lot 1 It have basic feature such as Auto-loader, router, MVC, DI, REST 2 It interacts data and storage via ORM, PHQL, ODM, Cache, Memcache, Session, etc PHP Saigon (meetup) Phalcon September 7, 2015 3 / 14
  5. Information What is Phalcon? Phalcon is an open source, full

    stack framework for PHP written as a C-extension, optimized for high performance. While discussing Phalcon its easy to forget that performance is not the only feature. Phalcon is a full stack framework and can do a lot 1 It have basic feature such as Auto-loader, router, MVC, DI, REST 2 It interacts data and storage via ORM, PHQL, ODM, Cache, Memcache, Session, etc 3 It have some components for views and frontend such as Template engines Volt, Forms builder, Flash messages, etc PHP Saigon (meetup) Phalcon September 7, 2015 3 / 14
  6. Information What is Phalcon? Phalcon is an open source, full

    stack framework for PHP written as a C-extension, optimized for high performance. While discussing Phalcon its easy to forget that performance is not the only feature. Phalcon is a full stack framework and can do a lot 1 It have basic feature such as Auto-loader, router, MVC, DI, REST 2 It interacts data and storage via ORM, PHQL, ODM, Cache, Memcache, Session, etc 3 It have some components for views and frontend such as Template engines Volt, Forms builder, Flash messages, etc 4 It also provides library ACL, Cryptography, Events manager, Share, Queueing, Annotations Parse, and so more PHP Saigon (meetup) Phalcon September 7, 2015 3 / 14
  7. MCV: Build single and multi-module applications with ease and pleasure.

    Using the file structure, scheme and patterns you already know. s i n g l e / app/ c o n t r o l l e r s / models / views / p u b l i c / c s s / img/ j s / m u l t i p l e / apps / frontend / c o n t r o l l e r s / models / views / Module . php backend / [ . . . ] views / Module . php p u b l i c / PHP Saigon (meetup) Phalcon September 7, 2015 4 / 14
  8. Dependency Injection: Phalcon is built upon a powerful yet ease

    to understand and use pattern called Dependency Injection. Initialize or define services once - and use them virtually anywhere throughout the application. $di = new Phalcon \ DIFactoryDefault () ; \\ Phalcon \DI () ; //Queue to d e l i v e r e−mails i n r e a l −time $di−>s e t ( ’ queue ’ , f u n c t i o n () use ( $di ) { $ c o n f i g = $di−>get ( ’ config ’ ) ; r e t u r n new Beanstalk ( [ ’ host ’ => $config −>beanstalk −> host ] ) ; } , t r u e ) ; //Use anywhere e l s e i n code $request = $di−>getShared (” queue ”) ; PHP Saigon (meetup) Phalcon September 7, 2015 5 / 14
  9. REST: Writing REST servers and applications has never been easier.

    No boilerplate. Simple services will fit in one file. $app = new Phalcon \Mvc\ Micro () ; // Returning data i n JSON $app−>get ( ’/ get / data . json ’ , f u n c t i o n () { echo json encode ( a r r a y (” some ” , ” important ” , ” data ”) ) ; }) ; // Say h e l l o with $name i n t h e i r name $app−>get ( ’/ h e l l o /{name } ’ , f u n c t i o n ( $name ) { echo ’ wellcome ’ . $name }) ; $app−>handle () ; PHP Saigon (meetup) Phalcon September 7, 2015 6 / 14
  10. Router: Phalcon provides a powerful router that maps route callbacks

    to specific HTTP request methods and URIs. It supports route segment parameters and pattern matching. use Phalcon \Mvc\ Router ; // Create the r o u t e r $ r o u t e r = new Router () ; // Define a route $router −>add ( ”/admin/ u s e r s /my−p r o f i l e ” , a r r a y ( ” c o n t r o l l e r ” => ” u s e r s ” , ” a c t i o n ” => ” p r o f i l e ” ) ) ; $router −>add ( ’/ get / i n f o /{ i d } ’ , a r r a y ( ’ c o n t r o l l e r ’ => ’ products ’ , ’ action ’ => ’ info ’ ) )−>beforeMatch ( a r r a y (new A j a x F i l t e r () , ’ check ’ ) ) ; PHP Saigon (meetup) Phalcon September 7, 2015 7 / 14
  11. Session: Phalcon provides a powerful session. It persists session data

    using industry standard encryption. Phalcon also enables flash messages across requests. use Phalcon \ S e s s i o n \ Adapter \ F i l e s as S e s s i o n ; // S t a r t the s e s s i o n the f i r s t time //when some component r e q u e s t the s e s s i o n s e r v i c e $di−>setShared ( ’ s e s s i o n ’ , f u n c t i o n () { $ s e s s i o n = new S e s s i o n () ; $session −>s t a r t () ; r e t u r n $ s e s s i o n ; }) ; PHP Saigon (meetup) Phalcon September 7, 2015 8 / 14
  12. Crytography: Phalcon provides encryption facilities via the Phalcon Crypt component.

    This class offers simple object-oriented wrappers to the mcrypt PHPs encryption library. use Phalcon \ Crypt ; $di−>s e t ( ’ crypt ’ , f u n c t i o n () { $crypt = new Crypt () ; // Set a g l o b a l e n c r y p t i o n key $crypt −>setKey ( ’%31.1 e $ i 8 6 e $ f !8 jz ’ ) ; r e t u r n $crypt ; } , t r u e ) ; It will encrypted cookies before be sent to the client and decrypted when retrieved. This protection allow unauthorized users to see the cookies contents in the client (browser). Despite this protection, sensitive data should not be stored in cookies. PHP Saigon (meetup) Phalcon September 7, 2015 9 / 14
  13. Volt: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 use Phalcon \Mvc\View ; // R e g i s t e r i n g Volt as template engine $di−>s e t ( ’ view ’ , f u n c t i o n () { $view = new View () ; $view−>setViewsDir ( ’ . . / app/ views / ’) ; $view−>r e g i s t e r E n g i n e s ( a r r a y ( ”. v o l t ” => ’ Phalcon \Mvc\View\ Engine \ Volt ’ ) ) ; r e t u r n $view ; }) ; //Use <h1>Cyborg Robots </h1> <ul> {% f o r robot i n robots %} {% i f robot . type == ” cyborg ” %} <l i >{{ robot . name | e }}</ l i > {% e n d i f %} {% endfor %} </ul> PHP Saigon (meetup) Phalcon September 7, 2015 10 / 14
  14. ORM and PHQL:Phalcon has its own ORM, Phalcon Query Language

    (PHQL), which can be used to make database interaction more expressive and clean. PHQL can be integrated with models to easily define and use relationships between your tables. use Phalcon \Mvc\Model\Query ; // I n s t a n t i a t e the Query $query = new Query (”SELECT ∗ FROM Robots ” , $this −>getDI () ) ; $cars = $query−>execute () ; //ORM Find record with i d = 3 $robot = Robots : : f i n d F i r s t (3) ; $robots = Robots : : query () −>where (” type = : type : ” ) −>andWhere (” year < 2000”) −>bind ( a r r a y (” type ” => ” mechanical ”) ) −>order (”name”) −>execute () ; PHP Saigon (meetup) Phalcon September 7, 2015 11 / 14
  15. With Phalcon, the whole framework is already in RAM, and

    as such, it is not necessary to process the entire set of framework files. This boosts performance by no small means PHP Saigon (meetup) Phalcon September 7, 2015 12 / 14
  16. Resources Phalcon 1 Phalcon forum international at https://forum.phalconphp.com 2 Phalcon

    tips and tricks at http://phalcontip.com 3 Phalcon forum Vietnamese at http://forum.zphalcon.com 4 Phalcon community chat at http://chat.phalcontip.com 5 Get jobs Phalcon at https://phalconjobs.com 6 A curated list of awesome Phalcon at https://github.com/sergeyklay/awesome-phalcon PHP Saigon (meetup) Phalcon September 7, 2015 12 / 14
  17. In conclusion In this topic, I have just reviews feature

    of Phalcon PHP to understand and used it, We would suggest you read the documents here. Are you using Phalcon PHP or planning to use them? I would love to hear your opinion on the subject. . PHP Saigon (meetup) Phalcon September 7, 2015 13 / 14