Question

This is a very newbie question so bear with me. I'm starting to use Yii as my first PHP framework and so far so good, the project on wich I'm learning is a simple informative webpage, but how am I supposed to handle the subpage concept under Yii? This is what I'm trying to achieve:

  • Home
  • Products
    • Product 1
    • Product 2
  • Contact

I have a controller for Home, Products and Contact, now I know that Yii doesn't work with subcontrollers, then how do I create a Product 1 and 2 subpages? Just a different view for each one? Through Gii? Many thanks.

Was it helpful?

Solution

You could do one of two things

You could have a generic product page that accepts a parameter to distinguish between different products (common approach). For example, www.mysite.com/products?id=1 would show Product1's page whereas www.mysite.com/products?id=2 would show Product2's page (and if there is no id parameter in the query string, then you could just show your Product page)


And you could also have separate methods for each page. So you would have

actionProduct
actionProduct1
actionProduct2

methods in your Product controller and then you could reach your pages as

www.mysite.com/product

www.mysite.com/product1

www.mysite.com/product2
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top