
| Latest version: | 1.7.0 |
| PHP4 | |
| PHP5 | PHP v.5.2.4 or later |
| MVC | |
| Multiple DB | |
| ORM | |
| DB Objects | |
| Templates | |
| Caching | |
| Validation | |
| Ajax | |
| Auth Module | |
| Modules | |
| Cost | FREE |
*application
---config
---controllers
---models
---views
---layouts
*public
*library
[general]
db.adapter = PDO_MYSQL
// The MySQL Host
db.params.host = localhost
//The database username
db.params.username = username
//The database password
db.params.password = password
//The database name
db.params.dbname = database
CREATE TABLE `forms` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(100) NOT NULL,
`data` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
);
<?php
// Define the include path so that we can use the Zend Framework libraries
set_include_path('../library/:../application/models:' . get_include_path());
//Allow the Zend Framework to automatically load classes
include "Zend/Loader.php";
Zend_Loader::registerAutoload();
//Get the database configuration, using the Zend_Config component
$config = new Zend_Config_Ini('../application/config/config.ini', 'general');
//The Zend_Registry component aids us in storing the config data in the application space.
$reg = Zend_Registry::getInstance();
$reg->set('config', $config);
//Configure the database
$db = Zend_Db::factory($config->db);
Zend_Db_Table::setDefaultAdapter($db);
//Configure the controller and the layout
$frontController = Zend_Controller_Front::getInstance();
$frontController->setControllerDirectory('../application/controllers');
Zend_Layout::startMvc(array('layoutPath'=>'../application/layouts'));
//Start it!
$frontController->dispatch();
<?php
class IndexController extends Zend_Controller_Action
{
//define the action that will be performed when index is requested
function indexAction()
{
//Assign the variable $title to be with value "My Form" in the view.
$this->view->title = "My Form";
//Make an instance of the FormsTable model that will handle the database queries
$forms = new FormsTable();
//Get all the data from the database and assign it to the variable $forms
$this->view->forms = $forms->fetchAll();
//Make an instance of the Form model it will assign all the attributes to the form
$form = new Form();
//Assign $form variable with value $form, which will be used in the view
$this->view->form = $form;
//Handle the post of new values
if ($this->_request->isPost()) {
//If the data is successfully assigned and validated
$formData = $this->_request->getPost();
if ($form->isValid($formData)) {
//Assign the data to a new row and save it
$row = $forms->createRow();
$row->data = $form->getValue('data');
$row->title = $form->getValue('title');
$row->save();
//Redirect back to the index page
$this->_redirect('/');
}
}
}
}
<?php
class Form extends Zend_Form
{
public function __construct($options = null)
{
//Load the constructor of the Form object, so that we can actually have a form
parent::__construct($options);
//This one will define the id of the form html tag
$this->setName('form');
//Define the data field of the form and set some example options
$data = new Zend_Form_Element_Text('data');
$data->setLabel('Data')
->setRequired(true)
->addFilter('StripTags')
->addFilter('StringTrim')
->addValidator('NotEmpty');
//Define the title field of the form and set some example options
$title = new Zend_Form_Element_Text('title');
$title->setLabel('Title')
->setRequired(true)
->addFilter('StripTags')
->addFilter('StringTrim')
->addValidator('NotEmpty');
//Define the submit button
$submit = new Zend_Form_Element_Submit('submit');
$submit->setAttrib('id', 'submitbutton');
$submit->setLabel('Add');
//Add the elements to the form
$this->addElements(array($id, $title, $data, $submit));
}
}
<?php
//Create an interface to the table forms
class FormsTable extends Zend_Db_Table
{
//define the table that we will make queries to
protected $_name = 'forms';
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<!-- The title that we have defined in the controller -->
<title><?php echo $this->escape($this->title); ?></title>
</head>
<body>
<div id="content">
<h1><?php echo $this->escape($this->title); ?></h1>
<!-— Get the page content -->
<?php echo $this->layout()->content; ?>
</div>
</body>
<table border="1">
<tr>
<th>Title</th>
<th>Data</th>
</tr>
<?php foreach($this->forms as $form) { ?>
<tr>
<td><?php echo $this->escape($form->title);?></td>
<td><?php echo $this->escape($form->data);?></td>
</tr>
<?php } ?>
</table>
<?php echo $this->form ;?>
try {
$mysql_db = new PDO('mysql:host=ntchosting.com;dbname=phonebook', 'user', 'password');
} catch (PDOException $e){
die($e->getMessage);
}
<?php
require_once 'Zend.php';
Zend::loadClass("Zend_Db");
$params = array ('host' => 'ntchosting.com',
'username' => 'user',
'password' => 'password',
'dbname' => 'phonebook');
$db = Zend_Db::factory('PDO_MYSQL', $params);
?>
{
public function __construct($username, $password)
{
// ...
}
public function authenticate()
{
// ...
}
}
<?php
class NTCExample_Acl extends Zend_Acl
{
public function __construct(Zend_Auth $auth)
{
// Add Resources
// Resource 1: Frontend Module
$this->add(new Zend_Acl_Resource(‘frontend’));
// Resource #2: Administration Module
$this->add(new Zend_Acl_Resource(‘administration’));
// Add Roles
// Role 1: Guest
$this->addRole(new Zend_Acl_Role(‘guest’));
// Role 2: Administrator (inherits from Guest)
$this->addRole(new Zend_Acl_Role(‘admin’));
//Role 3 A user role Johndoe which belongs to an admin parent role
$parents = array('guest','admin');
$this->addRole(new Zend_Acl_Role('johndoe'), $parents );
// Assign Access Rules
// Rule 1 & 2: Guests can access Frontend Module and Johndoe inherits this
$this->allow(‘guest’, ‘default’);
// Rule 3 & 4: Johndoe can access Administration Module and the Guests are denied by default
$this->allow(‘admin’, ‘administration’);
//$myNamespace corresponds to $_SESSION['myNamespace']
$myNamespace = new Zend_Session_Namespace('myNamespace');
//This cookie will expire in 2 hours
$cookie = new Zend_Http_Cookie('foo',
'bar',
'.ntchosting.com',
time() + 7200,
'/path');
$cookie = Zend_Http_Cookie::fromString('foo=bar; domain=.ntchosting.com; ' .
'path=/path; secure');
$cookie = Zend_Http_Cookie::fromString('foo=bar; secure;',
'http://www.example.com/path');