Your first symfony app

In this chapter we will see how to get started with the development of a symfony app using Code-bay. The technical requirements for this tutorial is to have git and a docker client installed on your machine. The very first step consists in setting up a new Symfony project using the provided sf5.2 bootstrap project.

Starting from a bootstrap

To do so, you can either download the code of sf5.2-bootstrap bootstrap project or fork and clone it on your device. In this guide we are going to use the second solution as illustrated below :

Enter the desired name of your new project, in this example we are creating a cb-sample/festival-api project

We can now clone the repository and build the docker image that will run our Symfony app by execution the commands below :

git clone git@gitlab.com:cb-sample/festival-api.git
cd festival-api
docker exec -it sf5-2_php bash
cd sf5-2/
composer update

Notice that the composer command fails when trying to clear the symfony cache. This is due to the fact that we configured the auto-wiring for source folder src/Api although this folder does not exist. In order to fix this problem we are going to create a new Api in Code-bay and to generate the associated code.

Creating a simple api

Begin with login to Code-bay using your personal account and create a new 'Sample' project as show below

Your new project has been created, click on the cog item in the list to access the project detail page and create a new Api called Festival :

Click on the cog item of the api as you did for the project and go to the Code tokenssection to get the api generation code url. To do so, enter a name in the new token name field, click on create button and copy the generated URL in your clip board using the copy item :

Finish by entering this URL in your plugin configuration for the project your forked. You can find more details about installing and running Code-bay plugin on the dedicated page. Generate the code in your IDE and run

composer update

command again in the docker, it finishes now without error. Visit the page http://localhost:8888, you will land on the default Symfony 5.2 page. At this stage, we have a running symfony app with a /home path defined, but this route does not do anything yet. Let's add a simple piece of code to the draft generated by Code-bay to make the route return a sample json object. Within your IDE, open the newly created file src/Api/Action/Home/HomeIndex/Stages/HomeIndexBusinessStage.php and add the following code to the body of the processStage method :

$context->setResponseCode200View([
  'hello' => 'world'
]);

Go to /home, you can see the browser displays a json object with a key 'hello' having a value 'world'. In the next chapter, we will go deeper in the api configuration to illustrate the main Code-bay features.


© Code-bay 2021, All rights reserved

When you visit or interact with our sites, services or tools, we use cookies for storing information to help provide you with a better, faster and safer experience. None of these cookies are used for marketing purposes.