phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Zend Framework Database: Deleting Data

Tag: framework, zend, zend framework, database, delete, data   Category: PHP Framework
post: 12 Apr 2008 read: 1,359


Zend Framework Database Step By Step Tutorial - Part 9: Last action from this series is delete data. For this job, create new method in controller.

Open your "UserController.php" within application/controllers. Add new method for delete action (i give name "delAction"):


  public function delAction()
  {
    $params = array('host'		=>'localhost',
	                'username'	=>'root',
					'password'  =>'admin',
					'dbname'	=>'zend'
	               );
	$DB = new Zend_Db_Adapter_Pdo_Mysql($params);
	$request = $this->getRequest();
	
	$sql = "DELETE FROM `user` WHERE id='".$request->getParam('id')."'";
	$DB->query($sql);
	
    $this->view->assign('title','Delete Data');
	$this->view->assign('description','Deleting succes');  		  
    $this->view->assign('list',$request->getBaseURL()."/user/list");  

Next, create a view for this action. Create a file named "del.phtml" within application/views/scripts/user. Enter following code:


<? include "header.phtml"; ?>
  <h1><?=$this->escape($this->title);?></h1>
  <h2><?=$this->escape($this->description);?></h2>
  <a href="<?=$this->escape($this->list);?>">Member List</a>
<? include "footer.phtml"; ?>

Now, try to test from table data. Click link del at one of rows.



Series this article:
Zend Framework Database: Intro
Zend Framework Database: Creating Input Form
Zend Framework Database: Inputing Data to Database
Zend Framework Database: Inserting Expressions to a table
Zend Framework Database: Creating List of Data
Zend Framework Database: Creating Editing Form
Zend Framework Database: Updating Data
Zend Framework Database: Updating Data Use Update Query From Zend Framework
Zend Framework Database: Deleting Data
Zend Framework Database: Delete Query Style
Zend Framework Database: Summarizing Action Controller

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Joomla: Fast Road to Understand Component Programming
Chart: How to Build Cool Animation Real Time Chart
Email: Send Attachement Mail
SMS : Sending SMS with PHP and ActiveXperts (Part 1)

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


624
posting