开发者

Making a model factory with a PHP MVC

I have written a decent MVC framework based on some solid tutorials and borrowing heavily from Cake. It suits our needs because we already have an existing app onto which we are building.

My situation is as follows: I have a model that describes say, a Team. This team has properties, methods, blah blah blah. In my controller I can create one team quite easily by:

$team = new Team('Hornets')

It works great. However, let's say I开发者_开发问答 want to have a method that returns all teams for a given country? Before using MVC I would just make a factory class and do:

$teams = Array();
$teams = TeamFactory::getTeams('Canada')

This would return an array of teams. I guess I can still do this, but my basic question is where would I keep these factory classes in my folder structure?

I have a folder called "lib" in the root where I keep various classes that I use on a regular basis. My only concern being that folder is going to become a big jumbled mess of "Team.Factory.php", "Player.Factory.php", mixed in with all the other stuff. My own instinct is to maybe make a sub-folder inside "lib" called "factory" and then go forth.

Is this "un-MVC"? Amidoingthisrite?


MVC doesn't mind directory structure. I would keep the TeamFactory class in the same directory as the Team class, or maybe make a subdirectory in it and place it there. This is what I mean:

model/Team.php
model/TeamFactory.php

or

model/Team.php
model/factories/TeamFactory.php
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜