Zend Framework Introduction

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

1 comments

Comments 1 - 1 of 1 previous next Post a comment

Post a comment
Embed Video
Edit your comment Cancel

11 Favorites & 1 Group

Zend Framework Introduction - Presentation Transcript

  1. Zend Framework Jan Willem Eshuis
  2. Who is this stranger?
  3. Photo from Flicr http://flickr.com/photos/97968921@N00/2617607943/ Photo from Flicr http://flickr.com/photos/97968921@N00/2617607943/
  4. What does he do?
  5. Photo from Flickr: http://flickr.com/photos/tttallis/86706014/sizes/o/
  6. Enough about him! What’s that Zend Framework
  7. “Zend Framework is an open source, object- oriented web application framework implemented in PHP 5 and licensed under the New BSD License.”
  8. Characteristic Zend Framework ‣ full PHP 5 open-source framework ‣ verry easy-to-use ‣ it uses the 80:20 rule (80% off the things you need are already there) ‣ no complex configuration
  9. Characteristic Zend Framework ‣ open BSD license (like PHP) ‣ more than 150.000 lines of high quality code ‣ more than 65% covered with unit tests ‣ large community
  10. It uses the MVC structure
  11. Model Photo from Flickr: http://flickr.com/photos/8628179@N06/523589595/
  12. The domain-specific representation of the information on which the application operates.
  13. Viewer Photo from Flickr: http://flickr.com/photos/8628179@N06/523589595/
  14. Renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes.
  15. Controller Photo from Flickr: http://flickr.com/photos/8628179@N06/523589595/
  16. Processes and responds to events, typically user actions, and may invoke changes on the model.
  17. What’s in the Zend Framework?
  18. A lot easy-to-use parts Photo: Jan Willem Eshuis (self)
  19. It’s just a toolbox Photo from Flickr: http://flickr.com/photos/22261399@N03/2144971881/sizes/l/
  20. Tools that are in the toolbox ‣ MVC using Zend_Controller, Zend_View, Zend_Layout and Zend_Form ‣ DatabaseZend_Db_Table, Zend_Db_Select classes like using Zend_Db_Adapter(s) and ‣ AuthenticationZend_Acl with Zend_Auth, Zend_Session and and ACL ‣ I18N with Zend_Locale, Zend_Date, Zend_Measure and Zend_Translate
  21. and even more... ‣ Web Services with Zend_Http_Client, Zend_Rest_Client, Zend_Feed, Zend_Service_... and more ‣ Communiction for creation of documents with Zend_Pdf or emails with Zend_Mail, Zend_Mime ‣ Search with the implementation of Zend_Search_Lucene ‣ Utility’s likeZend_Console_Getopt, Zend_Filter, Zend_Config, Zend_Cache (i love it),
  22. Application layout
  23. Standaard URL layout ‣ /index/index ‣ /help/index ‣ /help/search/query/hello ‣ based on /CONTROLLER/ACTION/PARAMS
  24. Example URL http://os2008.nos.nl/nieuws/artikel/ID/tcm:45-411801/title/welkom-thuis ‣ Controller: nieuws ‣ Action: artikel ‣ Params: ID and title
  25. Directory structure
  26. /application ‣ /controllers directory with your the controllers ‣ /layouts standard layouts for the application ‣ /views/.. controller specific layout ‣ /models your data models ‣ bootstrap.php ‣ Inializer.php
  27. bootstrap.php set_include_path('/Zendlib/Zend1.6' . PATH_SEPARATOR . '.' . PATH_SEPARATOR . '../application/default/models/' . PATH_SEPARATOR . get_include_path()); require_once 'Initializer.php'; require_once \"Zend/Loader.php\"; // Set up autoload Zend_Loader::registerAutoload(); // Prepare the front controller. $frontController = Zend_Controller_Front::getInstance(); // Change to 'production' parameter under production environment $frontController->registerPlugin(new Initializer('development')); // Dispatch the request using the front controller. $frontController->dispatch();
  28. Initializer.php ‣ initialisation creation of DB connection ‣ route settings application layout) (others than the standard create different routes ‣ load/save/create settings for things like views, controller paths, plugins etc..
  29. /public ‣ images static images ‣ styles static style sheets ‣ scripts static javascripts ‣ .htaccess configuration of your apache/php ‣ index.php
  30. .htaccess RewriteEngine on RewriteRule !\\.(js|ico|gif|jpg|png|css)$ index.php index.php require '../application/bootstrap.php';
  31. Demonstration please... Photo from Flickr:http://flickr.com/photos/scrivener/3037005851/sizes/l/
  32. Demo application, “Hello World” ‣ http://example.com/index/index ‣ http://example.com/index/demo ‣ Both in the IndexController ‣ 2 different actions (index and demo)
  33. IndexController.php class IndexController extends Zend_Controller_Action { /** * The default action - show the home page */ public function indexAction() { } public function demoAction() { } } /application/default/controllers/IndexController.php
  34. main.phtml <?php echo '<?xml version=\"1.0\" encoding=\"UTF-8\" ?>'; echo $this->doctype() ?> <html> <head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /> <?php echo $this->headTitle(); echo $this->headScript(); echo $this->headStyle(); ?> </head> <body> <?php echo $this->layout()->content ?> </body> </html> Location: /application/default/layouts/main.phtml
  35. index.phtml Hello, world! Today is <?php echo date(\"d-m-Y\");?>; Location : /application/default/views/index/index.phtml demo.phtml Hello, demo page is here! Location: /application/default/views/index/demo.phtml
  36. That was easy ;-) Photo from Flickr: http://www.flickr.com/photos/25446955@N06/2675295105/
  37. About templates ‣ use of native PHP code in templates, why learn another languages when PHP does the trick ‣ fromstructure1.6 templatingstandard use of thethe way version of there is a (main.phtml uses 2- Controller/Action content/view) ‣ you can use a template engine like Smarty templating
  38. What i love most Photo from Flickr:http://flickr.com/photos/rabbid_hearts/2953293174/sizes/o/
  39. Personal favorites ‣ Zend_Auth, Zend_Acl and Zend_Form ‣ Zend_Cache ‣ Caching DB results ‣ Caching complete pages ‣ Caching in memory with Memcache (very fast) ‣ Building static content! (this is what i like most)
  40. Static content? Why? ‣ it’s the cheapest content has to behave (in a cost aspect: dynamic content you can generated, static content is just there) ‣ you are only script (nogenerate the settings, checks, in control to parameters, content) ‣ very easy scalable! (this is website of the NOS visitors on the Euro 2008 why 60.000 concurrent could do more than 1.1 million requests per minute on only 15 webservers)
  41. Another example “adapters”
  42. How about adapters ‣ Zend Framework makes great use of adapters ‣ For example the Zend_Configown adapters if adapters but you can build your class has 2 you want ‣ Anotheradapters likethe Zend_Db, is comes with a lot of example is Zend_Db_Adapter_Db2, Zend_Db_Adapter_Oracle, Zend_Db_Adapter_Pdo_Mysql and more...
  43. Lot’s of different adapters Photo from Flickr: http://flickr.com/photos/davo39/24860585/
  44. Example “Loading a config file”
  45. What we need and use ‣ configuration file stored in ini or xml format ‣ read the config file with Zend_Config ‣ by using Zend_Config_Ini or Zend_Config_Xml ‣ save config with Zend_Registry
  46. Config file - .ini ; Production settings [production] webhost = demo.jwe.nl database.adapter = pdo_mysql database.params.hostname = mysql.jwe.nl database.params.username = dbuser database.params.password = secret database.params.dbname = dbname ; Test settings, extends production [development:production] database.params.hostname = test.mysql.jwe.nl database.params.username = devuser database.params.password = devsecret Different parts in 1 config file
  47. Config file - .xml <?xml version=\"1.0\"?> <configdata> <production> <webhost>demo.jwe.nl</webhost> <database> <adapter>pdo_mysql</adapter> <params> <host>mysql.jwe.nl</host> <username>dbuser</username> <password value=\"geheim\" /> <!-- short notation --> <dbname>dbname</dbname> </params> </database> </production> <test extends=\"production\"> <database> <params> <host>test.mysql.jwe.nl</host> <username>devuser</username> </params> </database> </test> </configdata>
  48. Where to put the PHP code ‣ please us a Zend_Framework 1.6 implementation ‣ if youZendZend Studio 1.6 Project just create a new use Framework for Eclipse ‣ The example uses witch uses a class requires a bootstrap.php index.php that Initializer ‣ our code is in thefunction class in the initPhpConfig Initializer Examples can be downloaded at http://www.janwillemeshuis.nl/zendframework/
  49. PHP Code // Load the application config from an ini file $oConfig = new Zend_Config_Ini('../data/config.ini', $this->_env); // Store the config in the Registry (a Singleton object) Zend_Registry::set('config',$oConfig); Loading an INI file // Load the application config from a xml file $oConfig = new Zend_Config_Xml('../data/config.xml', $this->_env); // Store the config in the Registry (a Singleton object) Zend_Registry::set('config',$oConfig); Loading an XML file
  50. PHP Code // Show the webhost from the config file echo $oConfig->webhost; // Show the database adapter echo $oConfig->database->adapter; // Show the database username echo $oConfig->database->params->username; Access the config object
  51. Example “Using the database config”
  52. PHP Code /** * Create a Zend_Db object using a factory method, because of the * configuration we have in our config file all settings like the * type of adapter and other settings are done automaticly */ $oDb = Zend_Db::factory( $oConfig->database ); // Load the list of DB Tables into an array $aTables = $oDb->listTables(); // Show the list of tables print_r($aTables); By changing the adapter type in the config file our application will automaticly us another type of database (connection) layer
  53. That was easy ;-) Photo from Flickr: http://www.flickr.com/photos/25446955@N06/2675295105/
  54. The End..... Questions? Please ask them!
  55. Jan Willem Eshuis Phone : +31 (0)6 2001 3300 E-mail : janwillem@jwe.nl Company : www.jwe.nl Weblog : www.janwillemeshuis.nl Linkedin: www.linkedin.com/in/janwillem Twitter : www.twitter.com/jweshuis

+ Jan Willem EshuisJan Willem Eshuis, 11 months ago

custom

3460 views, 11 favs, 2 embeds more stats

Introduction about the Zend Framework

More info about this document

© All Rights Reserved

Go to text version

  • Total Views 3460
    • 3413 on SlideShare
    • 47 from embeds
  • Comments 1
  • Favorites 11
  • Downloads 0
Most viewed embeds
  • 44 views on http://www.janwillemeshuis.nl
  • 3 views on http://www.slideshare.net

more

All embeds
  • 44 views on http://www.janwillemeshuis.nl
  • 3 views on http://www.slideshare.net

less

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

Cancel
File a copyright complaint
Having problems? Go to our helpdesk?

Categories

Groups / Events