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 </model/messagerie.sql>
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
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 -a -m -b=messagerie
You can now see the data and move between related objects:
You can also perform basic operations on objects:
- Create
- Read (navigate and see)
- Update
- Delete
- Search
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
To see the metadatas of a created model:
Select a model, and activate the Structure tab:
You can also view the partial class diagram:
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 are located in app/models folder, if the configuration of mvcNS.models has not been changed.
Note
If you want to know more about:
- object/relational mapping rules, see the
ORM part</model/models>
- data querying and persistence, see
DAO part</model/dao>
The Settings class:
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