Web Owl
Web Owl

Reputation: 569

CAKEPHP Delete & View In the controller

http://pastebin.com/TPDcNaAp

Cleaner to pastebin. http://webdesign4.georgianc.on.ca/~100141468/comp2084/todo/Employees

I am trying to work with cake to be able to add/delete/edit and view without using scaffold. I cannot seem to get delete and view to work correctly. That is my code in the pastebin, anyone see what I am doing wrong? The file is EmployeesController.php.

Upvotes: 0

Views: 726

Answers (1)

tigrang
tigrang

Reputation: 6767

For your view you haven't create the file:

Error: Confirm you have created the file: /home/100141468/public_html/comp2084/todo/app/View/Employees/view.ctp

Change your view code to look like:

$this->set('employee', $this->Employee->read(null, $id));

Your view will look like whatever you want, use whatever html markup you need to display the data, whether it be a table, divs, a list, etc. In your view you will have the $employee variable available, do a debug($employee); to see its contents.

Ex: <div><b>Name:</b> <?php echo $employee['Employee']['name']; ?></div>

You may also want to check if the record exists first to redirect back to the previous page and let the user know that record does not exists (set a flash message).

For your delete, you are accessing it by GET but not allowing it in your code:

 if ($this->request->is('get')) {
    throw new MethodNotAllowedException();
 }

If you want to delete by accessing the url /employees/delete/{id} remove that block of code.

Upvotes: 1

Related Questions