Put some MVC in your PHP
Trial by separation
Assign the row column values to the
Zend_View instance. The variables assigned to the
Zend_View object become the properties of the
$view->id = $_POST['id']; $view->journal = $rowset["JOURNAL"]; $view->publisher = $rowset["PUBLISHER"]; $view->edition = $rowset["EDITION"]; $view->title = $rowset["TITLE"]; $view->author = $rowset["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
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
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
$n = $db->update('Catalog', $data, $where);
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
A table row may be deleted using the
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.®
Sponsored: Transform Your IT Infrastructure