Feeds

Put some MVC in your PHP

Trial by separation

The smart choice: opportunity from uncertainty

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.®

Securing Web Applications Made Simple and Scalable

More from The Register

next story
NO MORE ALL CAPS and other pleasures of Visual Studio 14
Unpicking a packed preview that breaks down ASP.NET
Cheer up, Nokia fans. It can start making mobes again in 18 months
The real winner of the Nokia sale is *drumroll* ... Nokia
DARPA-derived secure microkernel goes open source tomorrow
Hacker-repelling, drone-protecting code will soon be yours to tweak as you see fit
Put down that Oracle database patch: It could cost $23,000 per CPU
On-by-default INMEMORY tech a boon for developers ... as long as they can afford it
Google shows off new Chrome OS look
Athena springs full-grown from Chromium project's head
Apple: We'll unleash OS X Yosemite beta on the MASSES on 24 July
Starting today, regular fanbois will be guinea pigs, it tells Reg
HIDDEN packet sniffer spy tech in MILLIONS of iPhones, iPads – expert
Don't panic though – Apple's backdoor is not wide open to all, guru tells us
prev story

Whitepapers

Designing a Defense for Mobile Applications
Learn about the various considerations for defending mobile applications - from the application architecture itself to the myriad testing technologies.
Implementing global e-invoicing with guaranteed legal certainty
Explaining the role local tax compliance plays in successful supply chain management and e-business and how leading global brands are addressing this.
Top 8 considerations to enable and simplify mobility
In this whitepaper learn how to successfully add mobile capabilities simply and cost effectively.
Seven Steps to Software Security
Seven practical steps you can begin to take today to secure your applications and prevent the damages a successful cyber-attack can cause.
Boost IT visibility and business value
How building a great service catalog relieves pressure points and demonstrates the value of IT service management.