View
12.650
Download
9
Category
Tags:
Preview:
DESCRIPTION
What is Zend Framework? Getting and Installing Zend Framework MVC overview Quick Start to developing applications using Zend Framework's
Citation preview
Zend Framework
• What is Zend Framework?
• Getting and Installing Zend Framework
• MVC overview
• Quick Start to developing applications using Zend Framework's
• PHP 5 library for web development productivity
• Free, Open source
• Class library – fully OOP
• Documentation – in many languages
• Quality & testing – fully unit tested
What is Zend Framework?
What's in Zend Framework?
• PHP 5.1.4
• Web server
• Standard installation
• Commonly no additional extensions needed
Requirments
The
directory
tree
quickstart|-- application| |-- Bootstrap.php| |-- configs| | `-- application.ini| |-- controllers| | |-- ErrorController.php| | `-- IndexController.php| |-- models| `-- views| |-- helpers| `-- scripts| |-- error| | `-- error.phtml| `-- index| `-- index.phtml|-- library|-- public| `-- index.php`-- tests |-- application | `-- bootstrap.php |-- library | `-- bootstrap.php `-- phpunit.xml
14 directories, 10 files
quickstart|-- application| |-- Bootstrap.php| |-- configs| | `-- application.ini| |-- controllers| | |-- ErrorController.php| | `-- IndexController.php| |-- models| `-- views| |-- helpers| `-- scripts| |-- error| | `-- error.phtml| `-- index| `-- index.phtml|-- library|-- public| `-- index.php`-- tests |-- application | `-- bootstrap.php |-- library | `-- bootstrap.php `-- phpunit.xml
14 directories, 10 files
Sample INI config
[production]app.name = "Foo!"db.adapter = "Pdo_Mysql"db.params.username = "foo"db.params.password = "bar"db.params.dbname = "foodb"db.params.host = "127.0.0.1"
[testing : production]db.adapter = "Pdo_Sqlite"db.params.dbname = APPLICATION_PATH "/data/test.db"
[production]app.name = "Foo!"db.adapter = "Pdo_Mysql"db.params.username = "foo"db.params.password = "bar"db.params.dbname = "foodb"db.params.host = "127.0.0.1"
[testing : production]db.adapter = "Pdo_Sqlite"db.params.dbname = APPLICATION_PATH "/data/test.db"
Getting and Installing
Zend Framework
Always found at:http://framework.zend.com
/download/latest
• Use CLI:% tar xzf ZendFramework-1.9.2-minimal.tar.gz% unzip ZendFramework-1.9.2-minimal.zip
• Or use a GUI file manager
Unzip/Untar
Add to your
include_path
<?phpset_include_path(implode(PATH_SEPARATOR, array( '.', '/home/matthew/zf/library', get_include_path(),)));
<?phpset_include_path(implode(PATH_SEPARATOR, array( '.', '/home/matthew/zf/library', get_include_path(),)));
Step 1:Create the project
Using the Model in the ControllerUsing the Model in the ControllerLocate the zf utility
In bin/zf.sh of bin/zf.bat of your ZF install (choose based on your OS)
Place bin/ in your path, or create an alias on your path:
alias zf=/path/to/bin/zf.sh
Create the project
# Unix:% zf.sh create project quickstart
# DOS/Windows:C:> zf.bat create project quickstart
# Unix:% zf.sh create project quickstart
# DOS/Windows:C:> zf.bat create project quickstart
Create a vhost
<VirtualHost *:80> ServerAdmin you@atyour.tld DocumentRoot /abs/path/to/quickstart/public ServerName quickstart
<Directory /abs/path/to/quickstart/public> DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory></VirtualHost>
<VirtualHost *:80> ServerAdmin you@atyour.tld DocumentRoot /abs/path/to/quickstart/public ServerName quickstart
<Directory /abs/path/to/quickstart/public> DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory></VirtualHost>
Fire up your browser!
Configuration[production]phpSettings.display_startup_errors = 0phpSettings.display_errors = 0includePaths.library = APPLICATION_PATH "/../library"bootstrap.path = APPLICATION_PATH "/Bootstrap.php"bootstrap.class = "Bootstrap"resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
[staging : production]
[testing : production]phpSettings.display_startup_errors = 1phpSettings.display_errors = 1
[development : production]phpSettings.display_startup_errors = 1phpSettings.display_errors = 1
[production]phpSettings.display_startup_errors = 0phpSettings.display_errors = 0includePaths.library = APPLICATION_PATH "/../library"bootstrap.path = APPLICATION_PATH "/Bootstrap.php"bootstrap.class = "Bootstrap"resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
[staging : production]
[testing : production]phpSettings.display_startup_errors = 1phpSettings.display_errors = 1
[development : production]phpSettings.display_startup_errors = 1phpSettings.display_errors = 1
.htaccess file
SetEnv APPLICATION_ENV development
RewriteEngine OnRewriteCond %{REQUEST_FILENAME} -s [OR]RewriteCond %{REQUEST_FILENAME} -l [OR]RewriteCond %{REQUEST_FILENAME} -dRewriteRule ^.*$ - [NC,L]RewriteRule ^.*$ index.php [NC,L]
SetEnv APPLICATION_ENV development
RewriteEngine OnRewriteCond %{REQUEST_FILENAME} -s [OR]RewriteCond %{REQUEST_FILENAME} -l [OR]RewriteCond %{REQUEST_FILENAME} -dRewriteRule ^.*$ - [NC,L]RewriteRule ^.*$ index.php [NC,L]
Step 2:Create a controller
All controllers extend Zend_Controller_Action
Naming conventions
Controllers end with 'Controller': IndexController, GuestbookController
Action methods end with 'Action':signAction(), displayAction(), listAction()
Controllers should be in the application/controllers/ directory, and named after the class, with a “.php” suffix:
application/controllers/IndexController.phpapplication/controllers/GuestbookController.php
Create a controller
IndexController.php
Step 3:Create the model
Using the Model in the ControllerUsing the Model in the ControllerUsing the Model in the Controller
• Controller needs to retrieve Model
• To start, let's fetch listings
Using the Model in the ControllerUsing the Model in the ControllerAdding the Model to the Controller
Using the Model in the ControllerUsing the Model in the ControllerTable Module – Access Methods
Step 4:Create views
Create a view scriptCreate a view
• View scripts go in application/views/scripts/
• View script resolution looks for a view script in a subdirectory named after the controller
– Controller name used is same as it appears on the url:• “GuestbookController” appears on the URL as
“guestbook”
• View script name is the action name as it appears on the url:
• “signAction()” appears on the URL as “sign”
index/index.phtml view script
Step 5:Create a form
Create a Form
Zend_Form:
• Flexible form generations
• Element validation and filtering
• Rendering
View helper to render element
Decorators for labels and HTML wrappers
• Optional Zend_Config configuraion
Create a form – Identify elements
Guestbook form:
• Email address
• Comment
• Captcha to reduce spam entries
• Submit button
Create a form – Guestbook form
Using the Form in the Controller
• Controller needs to fetch form object
• On landing page, display the form
• On POST requests, attempt to validate the form
• On successful submission, redirect
Adding the form to the controllerAdding the form to the controller
Step 6:Create a layout
Layouts
• We want our application views to appear in this:
Thank you.
Recommended