CakePHP - 文件结构混乱 - 不同的控制器,还是全部相同?
为了理解我的困惑/问题,让我首先快速概述一下我正在构建的网站:该网站有一个主页和 7 个类别页面,每个页面都有相同/相似的布局。
在大多数类别主页(例如“餐饮”)上,您可以进行搜索(即搜索餐馆),这将带您进入结果页面。这将具有与...“剧院”搜索结果页面...等相同/相似的布局。
因此 - 尽管有很多部分,但页面布局并不多。
问题:我不确定是否应该为每个控制器创建单独的控制器,并为它们使用相同的 CSS?或者,如果我可以使用相同的视图文件,但根据 url/action..etc 以不同的方式填充页面上的每个内容区域?
它们都会引用不同的 & 内容。数据库中的多个表 - 例如,餐馆将引用餐馆表、菜系表、邮政编码表等。剧院可能会引用“电影”表、邮政编码表...等等
但是 - 我也想要一些管理工具 - 即“餐厅/编辑”或“剧院/编辑”...等等 - 不是所有页面将有该特定网址的管理员 - 即“户外”可能只是“企业/编辑”或通用的东西......我不知道 - 正如你所知,我很困惑。
非常感谢任何帮助。我已经阅读了很多有关使用 CakePHP 执行的技术操作的内容,但是我找不到任何针对不同场景的一般项目结构的良好资源。
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.
Question: I'm not sure if I should create separate controllers for each, and just use the same CSS for them? Or if I can use the same view file, but populate each content area on the page differently based on the url/action..etc?
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以自己回答这个问题。假设您为每个实现单独的控制器、模型和视图,它们有何不同?如果它们仅在表名称和使用的标签/字符串上有所不同,那么您可以只使用一个通用控制器。但是,如果它们在其他方面不同(例如,餐馆模型与电影模型具有完全不同的关系结构),则使用单独的控制器。
当您使用单独的控制器时,为了防止控制器和视图文件之间出现过多的重复,请尝试将功能推送到公共基本控制器(例如 AppController)中,或者基于 AppController 创建您自己的基本控制器,您的 MoviesController 和 RestaurantController 等将派生自该 AppController )。将通用视图代码推送到元素中。
关于 CSS 的一句话:当然你可以(并且应该)重用它。它大部分与视图是分开的。只需在视图中使用合理的类名和 id,CSS 就可以轻松重用。
如果您仍然不确定,我会选择单独的控制器。这可能会需要更多工作,但会更干净、更容易调试。使用上述建议以避免重复。
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.
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.
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.
- 将在布局中的所有站点之间共享的组元素(即站点 css、站点公共 js 库)
-为每个类别(页面)(即餐饮页面、剧院页面、餐厅页面)创建一个视图,并将仅页面内容(即剧院js、剧院包含)放在那里
- 理论上,每个车都应该有一个控制器和模型,所以你必须将它们分开。
无论如何,像“restaurants/edit”或“theaters/edit”这样的url实际上意味着模型“restaurant”,控制器文件中的操作“edit”。
我建议您阅读 cakephp 网站上的博客教程,您应该可以解答您所有的困惑
-group elements that will share among all site in a layout (ie. site css, site common js library)
-make a view for each of your category(page) (ie. dining page, theater page, restaurants page) and put there page only stuff (ie. theater js, theater includes) there
- in theory, every vew should have a controller and model, so you have to make them separate.
anyway url like "restaurants/edit" or "theaters/edit" actually means model "restaurant", operation "edit" in your controller file.
I suggest you read the blog tutorial from cakephp site, you that should answer all your confusion