CakePHP - 文件结构混乱 - 不同的控制器,还是全部一样? [英] CakePHP - file structure confusion - different controllers, or all in same?

查看:139
本文介绍了CakePHP - 文件结构混乱 - 不同的控制器,还是全部一样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要了解我的混淆/问题,让我先简要介绍一下我正在创建的网站:该网站有一个首页和7个类别页面,每个页面都有相同/相似的布局。

To understand my confusion/question, let me first give a quick overview of the site I'm building: The site has a homepage, and 7 category pages, each with the same/similar layout.

在大多数类别主页(例如餐饮),您可以进行搜索(即搜索餐馆),这将带您到结果页。这将有与...剧院搜索结果页...等等相同/类似的布局。

On most category homepages (eg "Dining"), you can do a search (ie a search for restaurants), which will take you to a results page. This will have the same/similar layout as the... "Theaters" search result page...etc etc.

所以 - 虽然有很多部分,没有很多页面布局。

So - although there are a lot of sections, there are not a lot of page layouts.

问题:我不知道是否应该为每个控制器创建单独的控制器,只使用相同的CSS他们?或者如果我可以使用相同的视图文件,但根据url / action..etc不同地填充页面上的每个内容区域?

都将引用不同的&数据库中的多个表 - 例如,餐厅将引用restaurants表,cuisines表,zip_codes表...等。剧院可能会引用电影表,zip_codes表...等等

They'll all reference different & multiple tables in the database - for instance, restaurants will reference the restaurants table, the cuisines table, the zip_codes table...etc. Theaters might reference the "movies" table, the zip_codes table...etc etc etc

但是 - 我也想要一个管理工具,或剧院/编辑...等 - 不是所有的页面都将有管理员的那个特定的网址 - 即户外可能只是企业/编辑或一些通用...我不知道 - 我

But - I also want an admin tool for some - ie "restaurants/edit" or "theaters/edit" ...etc - not ALL the pages will have admin for that specific url - ie "outdoors" might just be "businesses/edit" or something generic... I don't know - I'm confused as you can tell.

任何帮助都非常感谢。我已经阅读了很多关于CakePHP的技术方面的内容,但我找不到任何好的资源为一般的项目结构的不同情况。

Any help is GREATLY appreciated. I've read a lot about the technical things to do w/ CakePHP, but I can't find any good resources for general project structures for varying scenarios.

推荐答案

你可以自己回答。假设您为每个实现单独的控制器,模型和视图,它们有什么不同?如果他们只是在他们使用的表名和标签/字符串不同,那么你可以只使用一个通用控制器。但是,如果它们在其他方面不同(例如,餐馆模型与电影模型具有完全不同的关系结构),则使用单独的控制器。

You can answer this yourself. Suppose you implement separate controllers, models and views for each, how do they differ? If they only differ in the table names and labels/strings that they use, then you can use just one generic controller. But, if they are different in other ways (e.g. the Restaurants model has a totally different relationship structure than a Movie model) then use separate controllers.

为了防止太多重复在控制器和视图文件之间的控制器和视图文件之间使用单独的控制器,尝试推送功能在一个通用的基本控制器(例如AppController,基于AppController创建您自己的基础控制器,你的MoviesController和RestaurantsController等)。将通用视图代码推送到元素中。

To prevent too many repetition between controllers and view files when you do use separate controllers, try to push functionality in a common base controller (e.g. AppController, of create your own base controller based on AppController that your MoviesController and RestaurantsController and so on will derive from). Push generic view code into elements.

关于CSS的一个词:当然你可以(应该)重用它。它与视图分离。只需在视图中使用合理的类名和id,CSS将很容易重用。

A word about CSS: Of course you can (and should) reuse that. It's mostyly separate from the view. Just use sensible class names and id's in your views and the CSS will be easy to reuse.

如果你仍然不确定,我会使用单独的控制器。它可能更多的工作,但它会更清洁,更容易调试。使用上述建议以避免重复。

If you are still unsure, I'd go with separate controllers. It may be more work but it will be cleaner and easier to debug. Use the above suggestions to avoid repetition.

这篇关于CakePHP - 文件结构混乱 - 不同的控制器,还是全部一样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆