Feeds

Put some MVC in your PHP

Trial by separation

Internet Security Threat Report 2014

Assign the row column values to the Zend_View instance. The variables assigned to the Zend_View object become the properties of the Zend_View object.

$view->id = $_POST['id'];
$view->journal = $rowset[0]["JOURNAL"];
$view->publisher = $rowset[0]["PUBLISHER"];
$view->edition = $rowset[0]["EDITION"];
$view->title = $rowset[0]["TITLE"];
$view->author = $rowset[0]["AUTHOR"];

Create a view script, resultView.php, associated with the Zend_View object. The view script will run in the scope of the Zend_View object. References to $this in the view script are references to the Zend_View object. Create a table header and add values to the table using the Zend_View properties assigned in the action controller. In the selectAction function render the resultView.php script.

echo $view->render('resultView.php');

Invoke the selectView.php view script with the URL http://localhost/views/selectView.php. Specify the catalog ID for the row that is to be retrieved and click select.

Selecting a database table row

Selecting a database table row

The row corresponding to the specified catalog ID will be retrieved and the results displayed.

Update a Row

Next, update a catalog table row using the Zend Framework. Create an associative array, $data, of column names and values for the row to be updated. Create a SQL expression specifying the WHERE clause for the ID of the row to be updated.

$where[] = "ID ="."'".$_POST['id']."'";

Update the database table using the update() method.

$n = $db->update('Catalog', $data, $where); 

Invoke the updateView.php script with URL http://localhost/views/updateView.php. Specify the catalog ID of the row to be updated and the column values to be updated and click on update.

Updating database table

Updating database table

A table row may be deleted using the delete() function.

MVC has a proven track record in simplifying the development and on-going maintenance of applications. Using Zend and the methodology I have outlined, you can now take advantage of MVC to simplify your work with PHP applications.®

Choosing a cloud hosting partner with confidence

More from The Register

next story
Preview redux: Microsoft ships new Windows 10 build with 7,000 changes
Latest bleeding-edge bits borrow Action Center from Windows Phone
Google opens Inbox – email for people too thick to handle email
Print this article out and give it to someone tech-y if you get stuck
Microsoft promises Windows 10 will mean two-factor auth for all
Sneak peek at security features Redmond's baking into new OS
FTDI yanks chip-bricking driver from Windows Update, vows to fight on
Next driver to battle fake chips with 'non-invasive' methods
UNIX greybeards threaten Debian fork over systemd plan
'Veteran Unix Admins' fear desktop emphasis is betraying open source
Entity Framework goes 'code first' as Microsoft pulls visual design tool
Visual Studio database diagramming's out the window
Google+ goes TITSUP. But WHO knew? How long? Anyone ... Hello ...
Wobbly Gmail, Contacts, Calendar on the other hand ...
prev story

Whitepapers

Why cloud backup?
Combining the latest advancements in disk-based backup with secure, integrated, cloud technologies offer organizations fast and assured recovery of their critical enterprise data.
A strategic approach to identity relationship management
ForgeRock commissioned Forrester to evaluate companies’ IAM practices and requirements when it comes to customer-facing scenarios versus employee-facing ones.
Security for virtualized datacentres
Legacy security solutions are inefficient due to the architectural differences between physical and virtual environments.
Reg Reader Research: SaaS based Email and Office Productivity Tools
Read this Reg reader report which provides advice and guidance for SMBs towards the use of SaaS based email and Office productivity tools.
New hybrid storage solutions
Tackling data challenges through emerging hybrid storage solutions that enable optimum database performance whilst managing costs and increasingly large data stores.