简体   繁体   English

如何处理Yii下的子页面概念?

[英]How to handle the subpage concept under Yii?

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? 我开始使用Yii作为我的第一个PHP框架,到目前为止这么好,我正在学习的项目是一个简单的信息网页,但我怎么处理Yii下的子页面概念? This is what I'm trying to achieve: 这就是我想要实现的目标:

  • Home
  • Products 制品
    • Product 1 产品1
    • Product 2 产品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? 我有一个家庭,产品和联系人的控制器,现在我知道Yii不能与子控制器一起工作,那么我如何创建产品1和2子页面? Just a different view for each one? 每个人只是一个不同的视角? Through Gii? 通过Gii? Many thanks. 非常感谢。

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) 例如, www.mysite.com/products?id=1 products?id = 1将显示Product1的页面,而www.mysite.com/products?id=2将显示Product2的页面(如果查询字符串中没有id参数,那么您可以只显示您的产品页面)


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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM