Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Crud the basic

besstiolle edited this page Apr 28, 2015 · 5 revisions

Create

To initiate a new Entity you simply need to call it

$bar = new Bar();

the object $bar will automatically let you set its own values defined in the file ./modules/Foo/lib/class.entity.bar.php (learn more)

example :

$bar->set('myField', 'myValue');

/!\ If you try to set a value to a non-existent field, an Exception will be thrown

To save the Bar Object into the database you simply need to call the save() function.

$bar->save();

Note : You can also use this code :

OrmCore::insert(new Bar(),$bar);

###Read

Here you will find some advice to retrieve your persisted data

OrmCore::findAll(new Bar());

Will return all the Bar entity persisted in the database into a single array.

OrmCore::findById(new Bar(),23);
OrmCore::findByIds(new Bar(), array(23,24,25));

Will return the Bar(s) with the id(s) in parameter. It may return null or a empty array if there is no Bar with the id(s) in your database

Update

Basically the function is exactly the same than creation

$bar = OrmCore::findById(new Bar(),23);
if($bar != null) {
  $bar->set('myField', 'myNewValue');
  $bar->save();
}

Note : You can also use this code :

OrmCore::update(new Bar(),$bar);

Delete

You can delete a Entity Bar with its id(s)

OrmCore::deleteByIds(new Bar(),array(23,24,25));

And Also

You can count the number of Entity Bar in your database

OrmCore::countAll(new Bar());

And now you can take a look inside the advanced Crud functions