Unfortunately I’m not at that stage yet, I’m planning out how it’s going to work and this seems to be a stumbling block. I’ll try to describe in more detail how it should work:
Say I have 2 models, one called "Category" and one called "Article".
The "Category" model has these attributes:
Category.parentId // Either null or the id of another category
and the following relations:
Category.children // has many -> Category
Category.parent // belongs to -> Category
Category.articles // has many -> Article
So the Category can either be a root node (it has no parent) or it can be a child of one of the other categories. (I’m aware a nested set is more efficient than this system, but I’m using this example for simplicity’s sake).
The "Article" model has these attributes:
As well as the relation:
Article.category // belongs to category
So the problem is, how do you efficiently link to a nested category or article?
Something like this sucks:
$this->createUrl("/article/show",array("category1" => $article->category->parent->parent->stub,"category2" => $article->category->parent->stub, "category3" => $article->category->stub,"stub" => $article->stub));
If instead we had a function on the Category model that returned that category’s path, like this:
class Category extends CActiveRecord
public function getUrlPath()
$path = $this->parent->getUrlPath()."/".$this->stub;
$path = $this->stub;
This would be much nicer:
$this->createUrl("/article/show",array("categoryPath" => $article->category->getUrlPath(),"stub" => $article->stub));
In my controller I should be able to find the appropriate article and category by accessing $_GET[‘categoryPath’] and $_GET[‘stub’].
The problem is that URL manager doesn’t seem to handle this kind of behavior, instead it splits the category path into seperate $_GET variables. I believe this is happening because of the slashes in the URLs, if getUrlPath() returned category stubs seperated by “.” instead of “/” this would work, but URLs like this aren’t really what I was after:
is not quite as good as