custom route for doctrine nestedSet

2019-09-05 05:47发布

问题:

I have been able to to successfully display all the nodes in a nice tree on the frontend, but the problem comes with rendering of the actual pages.

So I have 2 parents, Dog and Cat, and withing them I have multiple child nodes.

I have created a frontend module named animals that has an empty indexSuccess.php file.

In my actions.class.php file i have:

$this->animal = AnimalTable::getAnimalBySlug($request->getParameter('slug'));

In my Animal model

    public static function getAnimalBySlug($slug)
    {
        $q = Doctrine_Query::create()
          ->from('Animal a')
          ->where("a.slug = ?", $slug);

       return $q->fetchOne();
    }

I have a very basic route:

animal:
  url:   /:slug
  param: { module: animals, action: index }

So you see this will work fine for /dog (parent node), but not for /dog/sheep-dog

I'm not sure If i need to update my getAnimalBySlug and the route to take a dynamic route ini terms of a nestedSet.

Thanks

回答1:

Try changing the route to be :

animal:
  url:   /:slug
  param: { module: animals, action: index }
  requirements: { slug: '.*?' }