On Mar 1, 10:31 am, "Martin" <[EMAIL PROTECTED]> wrote:
> Hi everyone,
> I ran into a bit of a problem this morning that I cant get my head
> around.
>
> For several bad reasons there are a few tables I am working with that
> have duplicates with the same structure but different data. It is a
> legacy database I can't start messing with too much.
>
> I wanted to avoid duplicating the View-files and Controller. My idea
> was to Inherit the Controller and just sort of "rename" the Model so
> that all the references still work.
>
> The problem is that I can make the references in the controller work
> quite well... But all array_indexes the model returns still have the
> original Model name. There are probably more pitfalls I have not even
> come close to.
>
> So, is there a good way for a ModelTwo to represent itself as ModelOne
> to the controller and Views?

In your controller there is a variable modelClass which is the name of
the primary model. If you:

1) Make use of this variable in your controller
   e.g. : $this->{$this->modelClass}->findAll(....
2) Pass this var to the view
3) Use the passed variable in your views
   e.g. foreach ($data as $blob) { echo $blog[$modelClass]['name']...

You should find that helps in avoiding rewriting the same code. If
modelClass isn't the correct string for your model - just edit it in
the beforeFilter. I'm not aware of any concequences in doing this
unless you are using scaffolding.

An extension to this idea is to write generic functions in your app
contrller using modelClass, and only define your methods in the
specific controllers if they differ from the generic logic. It is
possible to change the view folder that is used for a controller
(viewPath variable), which if the views are all the same you could
also consider doing.

An alternative if these controllers and views are carbon copies is to
use routes to ensure requests all point to the same controller with a
named var which you can pick up in the beforeFilter method, and set
the var modelClass as appropriate. In this way you have n sets of
routes for your various 'controllers' and 1 controller and set of
views. This would be (perhaps) the cleanest MVC solution.

Well, HTH,

AD


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to