/vendor
directory in your project, and will install there the Cherrycake engine and all its dependencies.composer.json
file:If you want to use a namespace other thanCherrycakeApp
for your App, modify the snippet above to match it.
/public
. Create this subdirectory now.DocumentRoot
directive to /path_to_your_app/public
in your virtual host configuration file and create the file /public/.htaccess
in your project with the following contents:/install/database
directory./public/index.php
file will receive all the requests to your app and will be in charge of starting up the Cherrycake engine. Create it now and let's go step by step:CherrycakeApp
namespace. In any case, we declare the namespace first:autoload.php
file, like this:$e
variable as a convention:Note that the entire Cherrycake engine lives inside theCherrycake
namespace, while your application lives in its own different namespace you declared above. Every time you'll refer to a Cherrycake class, module or constant you'll need to prefix it with the appropriate\Cherrycake\
namespace like we did here, or add ause
statement at the top of your code. You'll see examples of that in the guide section and the provided examples.
__NAMESPACE__
appName
The name of the application. You can skip this and one will be generated automatically.isDevel
When set to true, the application works in development mode, meaning you'll get extended error reports and other tricks to help you develop your app. When not specified, this parameter defaults to false
.baseCoreModules
Is an array of the module names that should be loaded upon initialization of the engine. If not specified, only the Actions module will be loaded.Check the Engine::init documentation for more configuration parameters when initializing the engine.
baseCoreModules
, it will be loaded immediately and, as part of the loading process, it will be initialized by calling the Actions::init method. What this method does in the Actions module, among other things, is to go through all available modules in both the Cherrycake engine and your app, check if they have a method called mapActions
and run it.It's as if the Actions module asked all other modules: "If you have any actions you would like to map to respond to requests, please let me know now!"
Note that there's actually no need to specify abaseCoreModules
setup key when initializing the engine. If you skip this parameter, the Actions module will be loaded by default, which is the most common scenario when developing regular apps.
end
methods of all the loaded modules, so they can perform any cleaning tasks like disconnecting from external sources:index.php
file ends looking like this:Note that because we're ok with the default configuration parameters for the Engine::init call, we've simplified it and only theisDevel
configuration key remains.
/
route of your web application and respond by showing a simple HTML "Hello world" message.HelloWorld
that will map an action into the Actions module./src/HelloWorld/HelloWorld.class.php
and edit it so it declares an empty module structure, like this:Remember to use the same namespace you choose for your application in the/public/index.php
file.
Also, don't forget that modules have their own directory inside/src
, that directory name must match the module name, even with uppercase and lowercase characters.
HelloWorld
module so it will respond to requests, declare the static method mapActions
, and call the Actions::mapAction method, like this:/
path (that's why pathComponents
has been set to false), and will call the show
method on the HelloWorld
module (the same module we're working on). Take a look at the Actions guide to learn about how to map more advanced actions.show
method we told the Action to run. Let's add it now:This seems to be a somewhat overkill way of doing what could've been done with a simpleecho "Hello world"
line, isn't it?