Your SlideShare is downloading. ×
Introduction to Zend Framework
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Introduction to Zend Framework

16,662

Published on

An introduction to writing a simple Zend Framework MVC application

An introduction to writing a simple Zend Framework MVC application

Published in: Technology
4 Comments
14 Likes
Statistics
Notes
  • nice. Visit this url
    http://codemustangs.wordpress.com/2012/08/15/example-to-start-working-with-zend-framework/
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • i have really learnt a lot from this..this is my first into to mvc framework. thanks.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • The reason why I don't use the auto load feature in my slides is to indicate the components that are being used. Of course you can enable auto loading and tweak other features as well, but that's a matter of personal taste.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Very cool! I've only messed with the Zend_Pdf classes in the framework so far. But, the layout & MVC stuff you show here looks pretty cool. I'll have to give it a try.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
16,662
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
696
Comments
4
Likes
14
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Zend Framework Introduction by Michelangelo van Dam
  • 2. Who is Michelangelo van Dam ?
    • Freelance PHP consultant with over 7 years of enterprise level PHP development experience.
    • Started using Zend Framework in 2007 and contributes to this framework for Zend_Ldap.
    • web: http://www.in2it.be
    • blog: http://dragonbe.blogspot.com
    • e-mail: dragonbe [at] google mail
    • twitter: http://twitter.com/DragonBe
  • 3. What is Zend Framework ?
    • a component based framework
      • use the whole framework
      • pick what you need, drop the rest
    • implementing the MVC-paradigm
    • simplicity and object oriented best practices
    • corporate friendly license (new BSD license)
    • a very tested agile code base
    • modify code by extending components
  • 4. Zend Framework map
  • 5. Tools to build ZF applications
    • IDE's
      • Zend Studio 6.0 (“neon”) (www.zend.com)
        • fully supported by Zend
        • integration of Zend Framework in IDE
      • Komodo IDE (www.activestate.com)
    • Text editors
      • vi(m)
      • textpad
      • notepad
  • 6. A bit of theory... MVC
    • model
      • the model holds the business logic
    • view
      • creates the presentation layer
    • controller
      • defines actions to be executed
  • 7. MVC in action
  • 8. Setting up the virtualhost (Apache) <VirtualHost *:80> ServerName www.example.com ServerAlias example.com DocumentRoot /path/to/example.com/htdocs <Directory /path/to/example.com/htdocs> Options Indexes FollowSymlinks AllowOverride All Order allow,deny Allow from all DirectoryIndex index.php </Directory> SetEnv ENVPHP localhost ErrorLog /path/to/logs/example.com-error_log CustomLog /path/to/logs/example.com-access_log common </VirtualHost>
  • 9. Directory structure app/ default/ <- the &quot;default&quot; application controllers/ <- here you define your controllers ErrorController.php IndexController.php models/ <- this is where your business logic is put views/ <- everything for presentations is put here helpers/ scripts/ index/ index.phtml error/ index.phtml library/ Zend/ <- this is the Zend Framework library htdocs/ <- this is where your bootstrap file is located images/ scripts/ styles/ .htaccess index.php
  • 10. modify apache settings .htaccess RewriteEngine on RewriteRule !.(js|ico|gif|jpg|png|css)$ index.php
  • 11. bootstrap file index.php /** * Setup controller */ $controller = Zend_Controller_Front::getInstance(); $controller ->setControllerDirectory( '../application/default/controllers' ); $controller ->throwExceptions( false ); // should be turned on in development time // run! $controller ->dispatch(); require_once 'Zend/Controller/Front.php' ; <?php /** * My new Zend Framework project * * @author Michelangelo van Dam (michelangelo@in2it.be) * @version $Id$ */ set_include_path( '.' . PATH_SEPARATOR . '../library' . PATH_SEPARATOR . '../application/default/models/' . PATH_SEPARATOR . get_include_path() );
  • 12. view script index/index.phtml <?php /** * Default home page view * * @author Micehlangelo van Dam (michelangelo@in2it.be) * @version $Id$ */ echo '<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?>' ; ?> <! DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot; > < html xmlns = &quot;http://www.w3.org/1999/xhtml&quot; > < head > < meta http-equiv = &quot;Content-Type&quot; content = &quot;text/html; charset=UTF-8&quot; /> < title > New Zend Framework Project </ title > </ head > < body > Hello, world! </ body > </ html >
  • 13. controller IndexController.php <?php /** * IndexController - The default controller class * * @author Michelangelo van Dam (michelangelo@in2it.be) * @version $Id$ */ require_once 'Zend/Controller/Action.php' ; class IndexController extends Zend_Controller_Action { /** * The default action - show the home page */ public function indexAction() { // TODO Auto-generated IndexController::indexAction() action } }
  • 14. that's it !
  • 15. implementing Zend_Layout app/ default/ controllers/ models/ views/ helpers/ layouts/ layout.phtml <- here you define the site layout scripts/ index/ error/ library/ Zend/ htdocs/ images/ scripts/ styles/ .htaccess index.php
  • 16. modifying bootstrap index.php /** * Setup controller */ $controller = Zend_Controller_Front::getInstance(); $controller ->setControllerDirectory( '../application/default/controllers' ); $controller ->throwExceptions( false ); // should be turned on in development time // We enable Zend_Layout Zend_Layout::startMvc(array( 'layoutPath' => '../app/views/layouts' )); // run! $controller ->dispatch(); require_once 'Zend/Controller/Front.php' ; <?php /** * My new Zend Framework project * * @author Michelangelo van Dam (michelangelo@in2it.be) * @version $Id$ */ set_include_path( '.' . PATH_SEPARATOR . '../library' . PATH_SEPARATOR . '../application/default/models/' . PATH_SEPARATOR . get_include_path() );
  • 17. site layout with layout.phtml <?php echo '<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?>' ; ?> <?php echo $this ->doctype( 'XHTML1_TRANSITIONAL' ); ?> < html xmlns = &quot;http://www.w3.org/1999/xhtml&quot; > < head > <?php echo $this ->headMeta()->appendHttpEquiv( 'Content-Type' , 'text/html; Charset=UTF-8' ); ?> <?php echo $this ->headTitle(); ?> </ head > < body > <?php echo $this ->layout()->content; ?> </ body > </ html >
  • 18. modifying index/index.phtml Hello, world!
  • 19. modifying IndexController.php <?php /** * IndexController - The default controller class * * @author Michelangelo van Dam (michelangelo@in2it.be) * @version $Id$ */ require_once 'Zend/Controller/Action.php' ; class IndexController extends Zend_Controller_Action { /** * The default action - show the home page */ public function indexAction() { $this ->headTitle( 'New Zend Framework Application' ); } }
  • 20. Result is the same, but better
  • 21. More information
    • Zend Framework website http://framework.zend.com
    • Zend Developer Zone http://devzone.zend.com
    • ZFTutorials forum http://www.zftutorials.com
    • Blogs
      • Matthew Weier O'Phinney: http://weierophinney.net/matthew
      • Cal Evans: http://blog.calevans.com
      • Andries Seutens: http://andries.systray.be/blog
      • Rob Allen: http://akrabat.com
  • 22. Further reading
    • Guide to Programming with Zend Framework
    • written by: Cal Evans
    • published by: php|arch ( http://phparch.com )
    • Zend Framework in Action
    • written by: Rob Allen, Nick Lo, Steven Brown
    • published by: Manning Publications ( http://manning.com )
  • 23. Additional notes
    • This presentation can be found on SlideShare
    • http://www.slideshare.net/DragonBe/introduction-to-zend-framework/
    • On IRC ( irc.freenode.net ) you can go to #zftalk to chat about Zend Framework
    • Team up with the Belgian PHP Community on http://phpbelgium.be
  • 24. Thank you... Any Questions ???

×