Zend - Installation And Sample Project Creation
Upcoming SlideShare
Loading in...5
×
 

Zend - Installation And Sample Project Creation

on

  • 5,445 views

 

Statistics

Views

Total Views
5,445
Views on SlideShare
5,444
Embed Views
1

Actions

Likes
0
Downloads
70
Comments
0

1 Embed 1

http://duckduckgo.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Compare Infobase Ltd

Zend - Installation And Sample Project Creation Zend - Installation And Sample Project Creation Presentation Transcript

  • Zend Framework Introduction by Susheel Kumar Sharma
  • Zend Framework Introduction
    • Open Source Framework
    • 100% Object-Oriented Code
    • Use-At-Will
    •   MVC Pattern
  • MVC
    • Model - data, web services, feeds, etc.
    • View - The display returned to the user.
    • Controller - Manages the request environment, and determines what happens.
  • MVC Cont..
  • MVC Cont…
    • Controller <-> View Controller and View can interact
    • Controller <-> Model Controller can pull data from the model for decisioning, or push data to the model
    • View <- Model View can access the model to retrieve data, but not write to it.
  • Installation Zend Framework Cont..
    • By Installing Zend Server
    • Manual Installation
  • Installation Zend Framework Cont..
    • Manual Installation
    • 1.Check php is available from any directory
    • C:Userscompare>php –I
    • 2.If not, set path for php.exe in System Environment Variable
    • a)Find your php installation directory - This can generally be found in one of the following places:
    • C:php
    • C:xamppphp
    • b)Go to -> My Computer -> (Right Click)Properties
    • -> Advanced -> Environment Variables -> System Variables -> (Select)Path -> Edit -> Variable Value(Paste) -> Ok
  • Installation Zend Framework Cont.. 3.Copy zf.bat, zf.php from ZendFrameworkbin and paste zf.bat, zf.php to C:php or C:xamppphp 4.Set up Zend Framework library to system PHP include_path a) Open php.ini in an editor b) Find include_path c) Add Zend Framework library e.g. include_path = &quot;.;G:xamppphppear;G:dataZendFrameworklibrary“ 5. Run command C:Userscompare>zf show version Zend Framework Version: 1.11.2
  • Create Project 1.Go to directory where you want to create project e.g. C:Userscompare>cd .. C:Users>cd .. C:>G: G:>cd xampphtdocs G:xampphtdocs> 2. Run command G:xampphtdocs> zf create project trainingtestproject Creating project at G:/xampp/htdocs/trainingtestproject Note: This command created a web project, for more information setting up your V HOST, please see docs/README
  • Create Project Cont.. 3. Project directory structure trainingtestproject |-- application |   |-- Bootstrap.php |   |-- configs |   |   `-- application.ini |   |-- controllers |   |   |-- ErrorController.php |   |   `-- IndexController.php |   |-- models |   `-- views |       |-- helpers |       `-- scripts |           |-- error |           |   `-- error.phtml |           `-- index |               `-- index.phtml |-- library |-- public |   |-- .htaccess |   `-- index.php `-- tests     |-- application     |   `-- bootstrap.php     |-- library     |   `-- bootstrap.php     `-- phpunit.xml
  • Create Project Cont.. 4.Copy Zend directory from ZendFrameworklibraryZend and paste to trainingtestprojectlibraryZend(Optional)
  • Main Artifacts
    • Bootstrap
    • Configuration
    • Action Controllers
    • Views
  • The Bootstrap
    • Bootstrap class defines what resources and components to initialize
    • By default, Zend Framework's Front Controller is initialized
    • It uses the application/controllers/ as the default directory in which to look for action controllers
    • The class looks like the following:
    • // application/Bootstrap.php
    • class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
    • {
    • }
  • Configuration
    • Zend Framework is itself configuration less, need to configure application.
    • The default configuration is placed in application/configs/application.ini
    • Contains some basic directives for setting PHP environment 
    • It looks as follows:
  • Configuration Cont.. ; application/configs/application.ini [production] phpSettings.display_startup_errors = 0 phpSettings.display_errors = 0 includePaths.library = APPLICATION_PATH &quot;/../library&quot; bootstrap.path = APPLICATION_PATH &quot;/Bootstrap.php&quot; bootstrap.class = &quot;Bootstrap&quot; appnamespace = &quot;Application&quot; resources.frontController.controllerDirectory = APPLICATION_PATH &quot;/controllers&quot; resources.frontController.params.displayExceptions = 0 [staging : production]   [testing : production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1 [development : production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1
  • Action Controllers
    • action controllers contain application workflow, do mapping requests to the appropriate models and views.
    • action controller should have one or more methods ending in “Action”
    •   methods may then be requested via the web
    • Zend Framework URLs follow the schema /controller/action
    • &quot;controller&quot; maps to the action controller name (minus the &quot;Controller&quot; suffix) and &quot;action&quot; maps to an action method (minus the &quot;Action&quot; suffix)
    • need an IndexController, which is a fallback controller and which also serves the home page of the site
    • ErrorController, which is used to indicate things such as HTTP 404 errors (controller or action not found) and HTTP 500 errors (application errors)
  • Action Controllers Cont..
    • The default IndexController is as follows:
    • // application/controllers/IndexController.php
    • class IndexController extends Zend_Controller_Action
    • {
    •      public function init()
    •      {
    •          /* Initialize action controller here */
    •      }
    •      public function indexAction()
    •      {
    •          // action body
    •      }
    • }
  • Action Controllers Cont..
    • ErrorController is as follows:
    • // application/controllers/ErrorController.php
    • class ErrorController extends Zend_Controller_Action
    • {
    •      public function errorAction()
    •      {
    •          $errors = $this->_getParam('error_handler');
    •          switch ($errors->type) {
    •              case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
    •              case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLE
    • R:
    •             case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
    •                  // 404 error -- controller or action not found
    •                  $this->getResponse()->setHttpResponseCode(404);
    •                  $this->view->message = 'Page not found';
    •                  break;
  •              default:                  // application error                  $this->getResponse()->setHttpResponseCode(500);                  $this->view->message = 'Application error';                  break;          }           $this->view->exception = $errors->exception;          $this->view->request   = $errors->request;      } }
  • Views
    • Written in plain old PHP
    • View scripts are placed in application/views/scripts/
    • They are further categorized using the controller names
    • We have an IndexController and an ErrorController
    • Thus we have corresponding  index/ and error/ 
    • subdirectories within view scripts directory
    • We thus have the view scripts index/index.phtml 
    • and error/error.phtml
    • The following is what we install by default for the index/index.phtml view script:
  • Views Cont.. <!-- application/views/scripts/index/index.phtml --> <style>      a: link ,     a:visited{color: #0398CA;}     span#zf-name{color: #91BE3F;}     div#welcome{color: #FFFFFF;background-image: url(http://framework.zend.com/images/bkg_header.jpg); width:  600px;height: 400px;border: 2px solid #444444; overflow: hidden;text-align: center;}     div#more-information{background-image: url(http://framework.zend.com/images/bkg_body-bottom.gif);         height: 100%;}   </style> <div id=&quot;welcome&quot;>     <h1>Welcome to the <span id=&quot;zf-name&quot;>Zend Framework!</span><h1 />     <h3>This is your project's main page<h3 />
  •     <div id=&quot;more-information&quot;>         <p>             <img src=&quot;http://framework.zend.com/images/PoweredBy_ZF_4LightBG.png&quot; />         </p>          <p>             Helpful Links: <br />             <a href=&quot;http://framework.zend.com/&quot;>Zend Framework Website</a> |             <a href=&quot;http://framework.zend.com/manual/en/&quot;>Zend Framework                 Manual</a>         </p>     </div> </div>
  • Views Cont..
    • The error/error.phtml view script :
    • <!-- application/views/scripts/error/error.phtml -->
    • <!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;;
    •      &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>
    • <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>Zend Framework Default Application</title>
    • </head>
    • <body>
    •   <h1>An error occurred</h1>
    •   <h2><?php  echo  $this->message ?></h2>
    •     <?php if ('development' == $this->env): ?>
    •    <h3>Exception information:</h3>
    •   <p>
    •  
  •     <b>Message:</b> <?php  echo  $this->exception->getMessage() ?>   </p>    <h3>Stack trace:</h3>   <pre><?php  echo  $this->exception->getTraceAsString() ?>   </pre>    <h3>Request Parameters:</h3>   <pre><?php  echo   var _export ($this->request->getParams(), 1) ?>   </pre>    <?php endif ?>   </body> </html>
  • Create a virtual host(Optional)
    • Open httpd.conf file in any editor,
    • Some common locations: /etc/httpd/httpd.conf (Fedora, RHEL, and others), C:Program FilesZendApache2conf (Zend Server on Windows machines)/ G:xamppapacheconf
    •   First, ensure that the NameVirtualHost is defined; set it to a value of &quot;*:80&quot;
    • define a virtual host:
    • <VirtualHost *:80>
    •      ServerName quickstart.local
    •      DocumentRoot /path/to/quickstart/public
    •      SetEnv APPLICATION_ENV &quot;development&quot;
    •     <Directory /path/to/quickstart/public>
    •          DirectoryIndex index.php
    •          AllowOverride All
    •          Order allow,deny
    •          Allow from all
    •     </Directory>
    • </VirtualHost>
  • Create a virtual host(Optional) Cont.. <VirtualHost *:80>      ServerName  trainingtestproject.local      DocumentRoot /path/to/quickstart/public      SetEnv APPLICATION_ENV &quot;development&quot;     <Directory /path/to/quickstart/public>          DirectoryIndex index.php          AllowOverride All          Order allow,deny          Allow from all     </Directory> </VirtualHost>
  • Create a virtual host(Optional) Cont..
    •   DocumentRoot setting specifies the public subdirectory of project; this means that only files under that directory can ever be served directly by the server
    • AllowOverride, Order, and Allow directives; these are to allow to use htacess files within project
    • SetEnv directive is setting an environment variable for virtual host; this variable will be picked up in the index.php and used to set the APPLICATION_ENV constant for our Zend Framework application
    • Add an entry in hosts file located at : On *nix-like systems, this is usually /etc/hosts;
    • On windows : C:WINDOWSsystem32driversetc
    • 127.0.0.1 trainingtestproject.local
  • Reference : http://framework.zend.com/ http://framework.zend.com/manual/en/
  •