Delete your data

Keyboard Shortcuts

In this CakePHP tutorial, Justin will demonstrate how to delete data in your CakePHP 3 application. You will learn how to delete both a primary record, as well as to cascade a delete, to delete associated data of a related record as needed or desired.

- [Voiceover] Probably the action you'll do the least…is to delete a record.…Deleting is also coincidentally a super easy…action to perform.…CakePHP makes it very easy to delete records…from the database as needed.…The framework even includes the ability to cascade delete…to delete associated records, dependent upon…the primary deleted record.…Let's walk through an example of deleting a record…in a controller to see how this works.…Users has a lot of relationships, now we can explore…what happens when we delete a primary record…and see how the related records…are either deleted or stick around.…

Open up the Users Controller which can be found…at Source, Controller, UsersController.php.…And if we scroll down to the bottom,…on line 97, it's the delete action.…This method takes an ID that it uses…to identify the user record.…On line 99, we limit the http methods…that can access this method, to either post or delete.…This is to insure for instance, someone couldn't…accidentally hit a URL that deletes information.…

Line 100 sets to get the matching user entity for the ID.…

Resume Transcript Auto-Scroll

Author

Released

3/22/2016

CakePHP is a registered trademark of Cake Software Foundation, Inc.. Cake Software Foundation, Inc. is not affiliated with Lynda.com, nor does it endorse, sponsor, or otherwise support Lynda.com services.

CakePHP is a critical framework for PHP developers. It helps them build complex web applications faster and more efficiently. If you want to use CakePHP 3 (the latest version of the framework) in your own development workflow, this is the place to start.

Justin Yost provides an overview of the underlying MVC pattern in CakePHP, and the installation and configuration process for Mac and Windows. He shows how to use the CakePHP shell to build your first basic CakePHP app, and then discusses each application element in depth: controllers, models, views, components, behaviors, helpers, and utilities. At each step, he discusses the relevant new features and enhancements in CakePHP 3, including new components; performance, session management, and ORM improvements; and localization.

In later chapters, the course gets a little more advanced. Watch these tutorials to learn how to send email with CakePHP, extend CakePHP with plugins, and write unit tests to identify and eliminate bugs in your code. Justin also shows how to add security to your CakePHP apps with a basic user authentication system.

Topics include:

Installing and configuring CakePHP

Using the CakePHP shell console

Creating CakePHP controllers

Saving data in a CakePHP model

Finding and deleting data

Working with entity methods

Creating CakePHP views

Using and customizing components to share functionality between controllers