Join Jon Peck for an in-depth discussion in this video CakePHP directory structure and configuration, part of Learning CakePHP (2013).
Now that Cake's been extracted, I'm going to use the Netbean's IDE to explore and configure Cake. I'm going to create a new project from existing sources, and for the sources folder, I'm going to browse to the sandbox directory on my desktop. And I explicitly put Netbean's metadata into a separate directory and click Finish. Over here on the left, I can see the directory structure of the project, and index.php was opened by default.
Scrolling to the bottom, let's see what it's doing. It defines a couple constants and determines where CakePHP is installed, then finally requires appwebrootindex.php. That's the actual front controller. This file's just here for convenience. I don't need to make any changes to index.php, so let's close it out and get to addressing those action items from the first run. There are a couple mark down files in the root directory. The read me provides some links to CakePHP resources and documentation.
Contributing describes how to get involved in the CakePHP project. The two build files are for describing cake to the pair package manager. HT access is an Apache webserver configuration file that, when we look at it, just directs requests to the app webroot directory. Nothing very fancy, just clean. I'll close it out. There are four directories in the CakePHP root. App is where all our custom application will go, including models, views, and controllers.
Also the public webroot directory is contained here, for example. I'll explore appin greater detail in a moment. Lib contains the core CakePHP libraries. Unless you're contributing to the Cake Project, don't make any edits in here because it makes it hard to maintain. Plugins are packaged combinations of models, views and controllers that perform specific functions. This directory is empty by default. An example of a plugin is debug_kit, which is helpful for development.
I'll demonstrate how to install it later. A directory of contributed plugins can be found at plugins.cakephp.org. Finally, the vendors directory is a placeholder for third party PHP libraries like GeSHi, the generic syntax highlighter. Out of the box this directory's empty. Same as plugins. Let's navigate into app. There's a number of directories here, but only two that matter right now. Config is where cake's configuration files reside. I'll make the changes that cake was requesting in a moment.
I'm going to search for the word, security.salt. This is a random string used for secure hashing. It doesn't really matter what it is, as long as it can't be guessed. The best practice is to change it to a unique random string or to use a password generator. I'm going to change it to too many secrets. You should choose something a little bit more secure. Underneath, there's a cipher seed that's used for encrypting and decrypting strings. In this case, it needs to be just numbers.
But again it doesn't really matter what it's set to as long as it can't be guessed. So I'm just going to set it to 31337. That's all I need for base security, so I'll save and close the core file. Back in the browser, when I refresh, the security errors have been sorted, but the database configuration is still not present. I could just copy the default template and make the necessary configuration changes, but instead, I'm going to set up and use another great feature, the CakePHP console.
Speed up your development with CakePHP, the popular open-source PHP framework. In this course, author Jon Peck builds a magazine cataloging system while explaining how to work with the Model-View-Controller (MVC) development pattern.
The course demonstrates how to install and configure CakePHP, describing the layout and components. Then, leveraging the Bake console, Jon shows how to generate and customize code, and explores form validation, database persistence, and even image uploads. By developing a complete, functional application, you'll have the foundation you need to build your own applications with CakePHP.
- What is CakePHP?
- Installing and configuring CakePHP
- Generating a model with Bake
- Linking models together
- Generating a controller
- Saving a model from the controller
- Displaying a model with a view
- Debugging a failed save
- Using helpers to generate HTML
- Uploading files and displaying images