Example #1
0
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
 public function executeIndex(sfWebRequest $request)
 {
     //get current slug
     $slug = $request->getParameter('crumb');
     $this->product = null;
     $product = null;
     $category = null;
     $this->catid = null;
     //We need to identify what path is being accessed through the URL via the slugs
     if ($slug != "") {
         $slugs = explode("/", $slug);
         $count = count($slugs);
         if ($count == 0) {
             //if no slugs, set root level category (all)
             $category = Category::getRootCategory();
         } elseif ($count == 1) {
             //if 1 slug only, set category
             $category = Category::getCategoryFromSlug($slugs[0]);
         } else {
             //if multiple slugs
             if ($slugs[$count - 2] == "product") {
                 //if third to last slug is "product", we are viewing a product...
                 $product = Product::getProductFromSlug($slugs[$count - 1]);
                 //...so get that product...
                 if ($count > 2) {
                     $category = Category::getCategoryFromSlug($slugs[$count - 3]);
                     //...and its associated category...
                 } else {
                     $category = null;
                     //...or not, if product is being viewed directly
                 }
             } else {
                 //When viewing a product, the route will always prepend /product in order to identify.
                 //If that is not found, we are just viewing a category.
                 $category = Category::getCategoryFromSlug($slugs[$count - 1]);
             }
         }
     }
     if ($product != null) {
         $this->product = $product;
     }
     if ($category != null) {
         $this->catid = $category->getId();
     }
 }