CakePHP 3 includes a bake shell. In this video, Justin will use the bake shell to demonstrate building up a basic CRUD or Create, Read, Update, and Delete application with minimal effort and work on your part. You will learn how to use bake shell to quickly generate the core CakePHP application for this course.
- [Voiceover] One of the core plugins provided with CakePHP is the Bake plugin. Bake does what you might expect. It quickly creates the foundation of a CakePHP project. It builds our model, view and controller layer, assuming it has a database schema to read and interpret from. In this case, our training.sqlite3 database includes both some basic tables, and even some sample data for us to build our application with. So let's get started with using Bake to build up the skeleton of our project.
To start Bake, we need to be in the root of our project directory again, using our Terminal application. And we want to run the command bin/cake bake. Remember that if you're on Windows, the forward slash will instead be a back slash. We should see a list of available Bake commands. The first one is the one we want to run, all. All will bake the entire MVC stack for a database table. So let's run bin/cake bake all and see what happens.
We are presented with a list of possible model names based on the database design. The database is designed around the concept of users, storing bookmarks, that have a collection of tabs for each bookmark. It's a pretty simple bookmarking site. So let's start by baking the users skeleton. To do this, we need to enter bin/cake bake all users. And we're done. We should now have some output informing us that CakePHP Bake baked a bunch of files and code for our project.
You'll see here at the end that it tells us that it baked the edit view template file, and it created that file for us. That's what Bake is doing. It's creating the base of our project for us. Let's see what happened with our project. First I'm gonna clear out the terminal, and we're going to start our server using the command bin/cake server. And now our server is started. We can navigate to our browser and visit localhost:8765.
And again we see the CakePHP home page. However, if we go to the URL localhost:8765/users, we see something totally new. We see a rough index page, listing our users, their email, their password, their first name and last name, and a created and modified date/time. We can even click on edit, and edit a user. When we edit a user, notice the modified date/time gets updated as well.
This is very impressive isn't it. And CakePHP Bake did all this work for us, without us having to do anything at this point. Let's finish up the rest of the bake process through the other tables. We wanna go back to our terminal application. We need to stop the server. Recall the command to do this is CTRL-C. I'm going to clear the terminal again and let's bake the rest of our project. First we're going to bake the tags table. The command to do this is bin/cake bake all tags.
And finally, we wanna do this command one more time, for bookmarks. If you didn't know, you could hit the up arrow in your terminal, and get the last command you run, and just edit it. So I'll get the last command I run, and edit it to be bake all bookmarks. At this point, the whole project is baked. Feel free to restart the server, and explore what CakePHP Bake has built out for us.
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.
- 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
- Creating behaviors
- Formatting data with helpers
- Developing faster with CakePHP utilities: hash, collections, and logging
- Sending CakePHP email
- Creating a custom plugin
- Testing CakePHP applications
- Authorizing users of CakePHP applications