Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving data in Symfony using the model class

Let's say I have a model Ecosystem automatically generated with symfony from my schema.yml. At some point in the code, I would like to retrieve records from the table.

I know there are some ways to do this with Doctrine/Propel classes, but, is there a way of doing it with directly the model? I've been thinking in something like this:

$ecosystem = new Ecosystem();
$records = $ecosystem->find(...);

By the way, which is the preferred method to do this kind of things?

I've been developing with CakePHP and making queries directly with Doctrine doesn't seem natural to me. What if I decide to change to Propel tomorrow?

Thanks!

like image 983
elitalon Avatar asked May 08 '26 08:05

elitalon


1 Answers

Suppose your model is Ecosystem. Doctrine autogenerates two model classes for you:

  1. Ecosystem (defined in Ecosystem.class.php) — objects of this class are actual ecosystem entities
  2. EcoSystemTable (defined in EcosystemTable.class.php) — singleton class to provide management over Ecosystem entities

This why all the entity management functionality is done with *Table classes. How to get them?

Doctrine::getTable('Ecosystem')

or

Doctrine_Core::getTable('Ecosystem')

or

EcosystemTable::getInstance()

or

$obj->getTable(); // where $obj is instance of Doctrine_Record

Further reading:

  • Doctrine_Record API (ver 1.2)
  • Doctrine_Table API (ver 1.2)
  • Practical symfony. Day 6: More with the Model
like image 76
Darmen Amanbayev Avatar answered May 10 '26 23:05

Darmen Amanbayev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!