All pastes #929336 Raw Edit

Unnamed

public php v1 · immutable
·published 2008-03-05 18:15 UTC
rendered paste body
<?phpclass TasksController extends AppController{	var $name = 'Tasks';	var $helpers = array('Html', 'Javascript', 'Ajax'); 		function index()	{		// init view		$this->set('data', $this->Task->findAll());			}		function add()	{		// Add a task to the database. 		if (!empty($this->params['data']))		{			if ($this->Task->save($this->params['data']))			{				$this->set('data', $this->Task->findAll());				$this->render('todo', 'ajax'); 			}			else 			{				// Seems that our Model has failed to save the data. Let's do something, but not anything yet.							}		}	}		function done($id = null)	{		// move task from todo to done.		$this->Task->id = $id;		$this->params['data']['Task']['done'] = 1;		if ($this->Task->save($this->params['data']))		{			// Success			$this->set('data', $this->Task->findAll()); 			$this->render('done', 'ajax'); 		}	}		function undo($id)	{		// undo task done		$this->Task->id = $id;		$this->params['data']['Task']['done'] = 0; // reset task done column in db.		if ($this->Task->save($this->params['data']))		{			// Data saved. 			$this->set('data', $this->Task->findAll()); 			$this->render('todo', 'ajax'); 		}	}		function delete($id)	{		// delete task from db		$this->Task->del($id); 		$this->set('data', $this->Task->findAll());		$this->render('done', 'ajax'); 	}		}?>