3

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!

2 Answers 2

7

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:

Sign up to request clarification or add additional context in comments.

Comments

1

Of cause you can do that, just you *Table class methods, for example: $record = Doctrine::getTable('Ecosystem')->find(1) will return a record with id = 1. You can read more about available finders here: http://www.doctrine-project.org/documentation/manual/1_0/en/dql-doctrine-query-language:magic-finders I think you can safely get away without manually writing DQL queries, unless you care about performance.

2 Comments

I meant making queries even without using Doctrine classes. For instance, in CakePHP you can make queries like this $ecosystem->findById(1)
@elitalon: in your example Ecosystem is also a doctrine class (extends Doctrine_Table).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.