I am using Symfony 1.2.9 (with Propel ORM) to create a website. I have started using the admin generator to implement the admin functionality. I am having all manner of problems getting the admin manager to display an object (blog)开发者_开发百科 that has one 1:N relation (blogposts) and one N:M relationship (blogroll).
This is proving to be far more difficult than I had ever imagined (and I daresay, than it needs to be). I have already spent two days on this problem and have not made much progress. I am trying to generate admin functionality for a blog.
I have posted an abridged version of my schema here. Hopefully it will help clarify the problem I am having (maybe I am not explaining the problem clearly enough - but hopefully, the schema should clarify the problem I am facing, and what I'm trying to do).
A blog has 0 to 1 blog rolls, 0 to N blog posts attached to it. Each blog post has 0 to M comments attached to it. Currently, I can view a list of blogs. But I want to add 2 interactions (or links) that can make me:
- view the blogroll (which is a list of blogs attached to the blog)
- view the list of blogposts attached to a blog.
When a blogpost list is shown, I want link to show a link (same functionality as before), that allows me to show the list of comments for the selected blogpost.
I am sure I am not the first (or only) person that has tried to do this before. Am I going about it the wrong way, is there a better (i.e. more intuitie for the user) way of displaying and performing CRUD on objects with such relationships?. Can anyone out there help?
Why don't you do it as you have proposed by yourself in your other question.
(This is again for Doctrine but for Propel it should be similar).
Create an object action in your generator.yml
:
list:
object_actions:
bloglist: {label: Bloglist}
Then in your actions.class.php
you have to add a function:
public function executeListBloglist(sfWebRequest $request) {
$blog = $this->getRoute()->getObject();
// retrieve the blogposts via a PEER method (I don't have any clue about Propel ;))
$this->blogposts = however.you.get.the.blogposts();
}
Then create a template bloglistSuccess.php
where you show the posts.
Or, you can redirect or forward to the admin module for the blogposts if you have such a module. There you have probably to override the list action to accept the ID parameter of the blog and extend the query to filter posts by this blog id.
There is nothing wrong in doing a redirect or forward, it is not a hack ;)
Edit after comment:
I would also suggest that you forward the request.
No you don't have to change the routing you can just append the parameter like you suggested.
For overriding I reconsidered that it would be better if you override the buildQuery
method (again). (I can't remember how this method was called with Propel, I hope you get what I mean).
So it would look like this:
class blogpostAdminActions extends autoBlogpostAdminActions
{
//...
protected function buildQuery()
{
$query = parent::buildQuery();
$request = $this->getRequest(); // <- I am not sure about this method call but there is one that gives you the webRequest.
if ($request->hasParamter('blog_id'))
{
$query->andWhere('blog_id = ?', $request->getParameter('blog_id'));
}
return $query;
}
}
Of course you have to change this to Propel criteria, but I assume you can do that ;)
Hope this helps you.
精彩评论