Generate models from Database with webtools¶
Note
In this part, your project is already created.
If you do not have a mysql database on hand, you can download this one: messagerie.sql
Configuration¶
Check the database configuration with webtools at http://127.0.0.1:8090/Admin/
:
Go to models part:
Note
The configuration file is located in app/config/config.php
Change the configuration of the database to use the messagerie database:
- Click on the Edit config file button
- Select the database part
- Enter messagerie in the dbName field
- Click on Test button to check the connection
- Validate with the Save configuration button
Generation¶
To generate all models, click on (Re-)create all models button.
Generate the models cache by clicking on Re-init all models cache button:
That’s all!
The models are generated and operational.
You can now see datas.
Note
It is possible to generate models automatically when creating a project with the -m
option for models and -b
to specify the database:
Ubiquity new quick-start -q=semantic -a -m -b=messagerie
Checking¶
Class diagram¶
Still in the models part, click on the models generation step:
Then click on Classes diagram button:
You can see the class diagram, using the yUML API
Models meta-datas¶
To see the metadatas of a created model:
Select a model, and activate the Structure tab:
You can also view the partial class diagram:
Models validation¶
The third tab gives information about object validation:
Note
The validation rules were generated automatically with the classes.
They are defined through @validator
annotations on each member of a class and are stored in cache.
The Validate instances button is used to check the validity of the instances:
Note
It is normal that by default all instances in the database do not check all validation rules.
Generated classes¶
Generated classes are located in app/models folder, if the configuration of mvcNS.models has not been changed.
Note
If you want to know more about:
The Settings class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | namespace models;
class Settings{
/**
* @id
* @column("name"=>"id","nullable"=>false,"dbType"=>"int(11)")
* @validator("id","constraints"=>array("autoinc"=>true))
**/
private $id;
/**
* @column("name"=>"name","nullable"=>true,"dbType"=>"varchar(45)")
* @validator("length","constraints"=>array("max"=>45))
**/
private $name;
/**
* @oneToMany("mappedBy"=>"settings","className"=>"models\\Organizationsettings")
**/
private $organizationsettingss;
}
|
Important
Any modification on the classes (code or annotations) requires the reset of the cache to be taken into account.
Ubiquity init-cache -t=models