Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

02/08/2020 Devups 4.

5 CRUD
Do your best

AZANKANG ATEMKENG
SPACEKOLA
Devups 4.5 CRUD

Table des matières


I. Component .................................................................................................................................. 4
II. Data-core ..................................................................................................................................... 2
A. Generate component ............................................................................................................... 4
1. Add dependences ................................................................................................................. 4
2. Update admin....................................................................................................................... 5
B. Crud operation ......................................................................................................................... 5
1. Update database schema ..................................................................................................... 6
2. Test crud .............................................................................................................................. 7

AZANKANG ATEMKENG 1
Devups 4.5 CRUD

Introduction
Hi everybody so here is my first tutorial and it talks about Devups, a php framework I wrote and hope
you will like

I. Base structure
Ok now let’s enter the folder src at the root of the project. The elements of this folder are called
component and component itself contain module. we call this two level modularity.

By default, a project devups comes with devups component who contains the module admin we saw
early in the browser.

We have this structure

controller

core

entity

form
component module js
architecture src ressource
requires.php views entity
index.php

moduledependences.php

services.php

Figure 1 base structure

II. Data-core
Before doing something let’s introdious the main concept of devups datacore

Devups framework has this that it can generate code source (crud) of entities base on your uml diagram
model. That can be easyly integrate on the project in process. And to do that devups use a structured
dataset that transcript all the uml class diagram, and that file’s name is datacore.

Data-core are JSON file who define the model of an element. Those elements can be entity (from uml
class diagram), module (group of entities) or component (group of modules) and help devups generate
code source and structure folder for each type of element.

In fact, we have three types of data-core

AZANKANG ATEMKENG 2
Devups 4.5 CRUD

- entityCore define the entity with relation. They are found in Core folder in module (ex:
src/devups/ModuleAdmin/Core/dvups_adminCore.json)
- moduleCore: define the module with its entities. They’re found on every module root (ex:
src/devups/ModuleAdmin/moduleadminCore.json)
- componentCore: define the component with its modules. Found on component root. (ex:
src/devups/devupsCore.json)

at the root of “src” folder let’s create “devupstuto” folder, we will call it devupstuto component, then,
inside the devupstuto component, create devupstutoCore.json and let write the minimum component.

{
"name": "devupstuto",
"template": "adminv2",
"listmodule": [
{
"name": "ModuleStock",
"project": " devupstuto",
"listentity": [
{
"name": "storage",
"attribut": [
{
"name": "id",
"datatype": "integer",
"nullable": "not",
"formtype": "text"
},
{
"name": "name",
"datatype": "string",
"size": "255",
"nullable": "not",
"formtype": "text"
}
],
"relation": []
}
]
}
]
}

Let’s have a deeper look on this json.

We have 3 models: component, module and entity.

- Module has entities


- component has modules.

That’s all we need for the moment.

AZANKANG ATEMKENG 3
Devups 4.5 CRUD

III. Generate component

Components are the element who contains the logic of a project. We then distinguish two type of
component:

- main component who representing the logic of the current project your are building and
- component comes from other project. To either complete or just add some new logic to your
main component.

That’s you devups handle the concept of modularity..

For this minimum component we want to build the entity: storage, contain in the module: ModuleStock
contain in devupstuto component

Now open the cmd and enter the command:


php devups core:g:component devupstuto

Figure 2 core:g:component

Go back to the IDE and all’s done.

Figure 3 devupstuto component

It has the same structure as the module admin in devups component we saw early. You can visit file
generated it looks really sexy :D.

A. Add dependences
before continue, there is something we have to do for the module to be use.

On the root of the src, edit the file requires.php then, just require your module dependence like this:
require “devupstuto/ModuleStock/devupstuto.modulestock.php”;

AZANKANG ATEMKENG 4
Devups 4.5 CRUD

You have to require each new module you create here for it to be use in all the project, a part the
module admin dependence.

B. Update admin
Ok let’s execute some command:
php devups dvups_:update

Figure 4 dvups_:update

This command add the new module and entities in the data base and update the master admin privilege.

Once all’s done, go to the browser, logout then login again and you will see the module appear in the
back-office.

Figure 5 Dashboard update

(Admit that it’s cool hihihi :D).

IV. Crud operation


A. Doctrine orm
Now click on manage. You will have such error: Table storage doesn’t exist.

AZANKANG ATEMKENG 5
Devups 4.5 CRUD

Figure 6: Table storage doesn't exist

Why?

Because all we’ve done with the command, is update the data of devups component (dvups_module,
dvups_entity and dvups_admin) but the database schema has not changed to integrate the new entity:
storage. To update the database schema, we will use doctrine.

1. Update database schema


Doctrine ORM is a powerful tool to handle database schema update. You can have further information
about it on the official web site

note: the purpose of doctrine in devups framework is to update database schema, nothing else.

In the cmd execute:


bin\doctrine orm:schema:update –-dump-sql

This command will show you the query that will be execute.

Figure 7 orm -- dump-sql

Then:

AZANKANG ATEMKENG 6
Devups 4.5 CRUD

bin\doctrine orm:schema:update –-force

This one will execute the query.

Figure 8 orm –force

Back to phpmyadmin you can see

Figure 9 database schema updated

That’s all the power of doctrine ORM.

B. Test crud
Now, just refresh the page and you can now make crud operation on the entity in the new module.

AZANKANG ATEMKENG 7
Devups 4.5 CRUD

Figure 10 empty table

Figure 11: crud create

AZANKANG ATEMKENG 8
Devups 4.5 CRUD

Figure 12 crud read

Figure 13 crud update

Figure 14 crud read update

Figure 15 crud on delete action

Figure 16 crud delete

AZANKANG ATEMKENG 9
Devups 4.5 CRUD

Ok back to the code and let’s see how all this works.

AZANKANG ATEMKENG 10

You might also like