In my model i have:
* @method Doctrine_Collection getComments() Returns the current record's "Comments" collection
Default if i generated admin then this isn't showing in list. If is in generator.yml :
config:
actions: ~
fields: ~
list:
display: [id, title, comments]
filter: ~
form: ~
edit: ~
new: ~
Then this show me
<pre> Doctrine_Collection data : Array( ) </pre>
instead of list of comments.
I know - i can get files from cache and showing this, but maybe this is possible only with generator.yml ? For example if i have relation one to many then this showing me this name.
I dont want use cache for this! thanks!
you can use a function for your problem.
For example, in my generator.yml
list:
display: [id, description, public, nbQuestions]
nbQuestions is a function in Object.class.php
public function getNbQuestions() {
return $this->getQuestion()->count();
}
The admin generator will automatically call the "getYouField" Method in the object class. So you can describe a function which return a long string for you doctrine collection.
There is an other way than only displaying a count.
You can add a partial in your generator.yml:
list:
display: [id, description, public, _comments]
Then in your partial (_comments.php
), you can call the relation and display what ever you want (add style, other infos, etc ..):
<?php
// note that you will need to change the $object
echo $object->getComments()->count();
?>
In an other way, it could be usefull to have all comments listed in the edit view. In your generator.yml:
form:
# don't forget to add others fields
display: [_comments]
And then in your partial:
<ul>
<?php foreach($form->getObject()->getComments() as $comment): ?>
<li><?php echo $comment->getBody() ?></li>
<?php endforeach; ?>
</ul>
And if you want to combine both in the same partial (don't forget to rename $object
):
<?php if(isset($form)): ?>
<ul>
<?php foreach($form->getObject()->getComments() as $comment): ?>
<li><?php echo $comment->getBody() ?></li>
<?php endforeach; ?>
</ul>
<?php elseif(isset($object)): ?>
<?php
// note that you will need to change the $object
echo $object->getComments()->count();
?>
<?php endif; ?>