文件结构 +控制器之间的共享功能
所以我遇到了文件结构问题,我正在尝试找到不重复事情的最佳方法。我试图让每个额外部分(音乐、电影、节目等)共享功能。功能包括喜欢、推荐、标签和列表。我正在寻找有关如何构建它的建议,以便最大限度地减少代码重复并轻松安全地访问每个部分的功能。详细信息如下。我还使用 Fuel PHP 框架: http://fuelphp.com/
有列表:音乐、电影、节目。 (http://domain.com/music/view/1) 每个列表都支持标签:(http://domain.com/music/tag/view/rock)
到目前为止,这很容易,但是“喜欢”和“推荐”等功能让我感到困惑,因为我可以在每个列表中都有“喜欢”列表的控制器。示例(http://domain.com/music/like/1)或其自己的控制器(http://domain.com/like/music/1)。
此外,每个列表都有“推荐”,其中列出了类似的列表以及每个推荐的评论和“喜欢”。因此,“喜欢”可以用于列表和推荐。
音乐 (Model_Music)[一对一 Model_List]
-- 喜欢
-- 标签(多对多)
-- 推荐(通过 UNION 交叉引用)
-- 列表(在本例中为所有曲目和歌曲名称)[一对多]
节目 (Model_Shows)[一对一 Model_List]
-- 喜欢
-- 标签(多对多)
-- 推荐(通过 UNION 交叉引用)
-- 列表(在本例中为所有剧集)名称和数字)[一对多]
正如您所知,大部分内容都是相同的代码,只是具有不同的 URL 结构以及对要使用的表进行一些更改。我只是不确定如何最好地处理事情,只需要更有经验的观点来处理每个清单的所有这些附加功能。music.php,shows.php,movies.php 任何其他将要添加的功能。
So im stuck with a file structure problem, i'm trying to find the best way not to repeat things. Im trying to get features shared with each extra section (Music, Movies, Shows etc). The Features being Likes, Recommendations, Tags and List. I'm looking for advice on how to structure it so there will be minimal repeating of code and easy secure access to the features for each section. The details are below. Also I am using Fuel PHP framework: http://fuelphp.com/
There are listings: Music, Movies, Shows. (http://domain.com/music/view/1)
Each listing supports Tags: (http://domain.com/music/tag/view/rock)
So far that's easy, but features like 'likes' and 'recommendations' confuse me, as in I could have 'likes' in each listing's controller. Example (http://domain.com/music/like/1) or in its own controller (http://domain.com/like/music/1).
Also each listing has 'recommendations' which list similar listings with reviews and 'Likes' for each recommendation. So 'likes' can be for listings and recommendations.
Music (Model_Music)[one-to-one Model_List]
-- Likes
-- Tags (many-to-many)
-- Recommendations (cross-reference by UNION)
-- List (in this case all tracks and the song name) [one-to-many]
Shows (Model_Shows)[one-to-one Model_List]
-- Likes
-- Tags (many-to-many)
-- Recommendations (cross-reference by UNION)
-- List (in this case all episode names and number)[one-to-many]
As you can tell most of it will be the same code just with different URL structure and some changes on which table to use. I'm just not sure how to handle things best, just need a more experienced view on handling all these additional features to each listing music.php, shows.php, movies.php any any others that will be added.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议创建一个基本控制器来构建所有特定的列表。
因此,您将在控制器目录中创建一个清单文件夹,并创建一个
listings.php
作为清单目录中所有控制器的基础。您只需在所有列表控制器中扩展基本控制器,基本控制器中的任何功能都会被继承。
有关如何在 Fuel 中构建基本控制器的更多详细信息。
I would recommend creating a base controller to build all your specific listings from.
So you would create a listings folder in your controller directory, and also a
listings.php
as a base for all controllers in the listings directory.You just extend the base controller in all your listings controller and any functionality that is in the base controller is inherited.
more details on how to structure base controllers in fuel.