Hi Jason,
Sorry, somethings (How do I keep coders from using these models to
edit the tables?) lead me to believe you were asking a (internal?)
security question. And sorry if that tainted the tone of my reply.
On Sep 6, 12:23 am, Jason <[EMAIL PROTECTED]> wrote:
<snip>
> It's not so much a security thing as it is a confusion thing. Cake
> really should have a read only model structure.
Why? It's trivial to do with a behavior anyway (1.2 only) and almost
as easy in 1.1.
<snip>
> I want something to act as a single object
> that I can call upon to get the information I need out of this
> grouping of tables. I want it to be something more specialized than a
> general model.
Irrespective of the behind the scenes stuff, what you want is a (data
manipulation object) model not a (reusable controllererette)
component. To access it everywhere you would put var $uses =
array(NameOfModel); in your app controller
Even if it was setup like this:
class GeoModel extends AppModel {
var $useTable = false;
...
// Define $this->City etc to be an instance of the correct model.
...
function citiesByZip($zipCode) {
// See http://groups.google.com/group/cake-php/web/frequent-discussions
// How to handle tricky HasAndBelongsToMany situations?
...
$this->City->zipCode->recursive = -1;
$zipData = $this->City->ZipCode->findByZipCode($zipCode);
$zipCodeID = $zipData['Zipcode']['id'];
$this->City->recursive = 0;
return $this->City->findAll(Array('CityZip.zip_id' => $zipCodeId));
}
<snip>
> > > Using it this way, which model would I then use? How do I keep coders
> > > from using these models to edit the tables?
You need only define beforeSave and beforeDelete to return false in
either the behavior they are all using, or in the models themselves or
in the abstract class they all inherit from.
<snip>
> I HOPE I have something setup wrong, but it just doesn't seem to play
> well with this setup.
>
> Cake 1.2 (latest build)
>
> 1 controller
> ZipCodeController - scaffolding turned on, $uses ZipCode
You don't need the $uses declaration. but your controller /should/ be
called ZipCodesController
>
> 4 models
> ZipCode (HABTM City)
> City (HABTM ZipCode, BelongsTo State)
> State (HasMany City, BelongsTo Country)
> Country (HasMany State)
>
> That's it. If I navigate to /ZipCode Apache explodes. Any
> suggestions?
Do you have a full db and are using 1.1? If so the reason is the
initial index lists with no limit.
You'd need to know the reason for the exploding. Probably there is a
loop somewhere, and if there is it's either (just guesses)
1) A loop somewhere, possibly due to (incorrect) model definitions
2) You have all your data in place and have not put a limit in the
model definition for the number of associated objects to return, as
such apache is returning a list of zip codes for the index, all
associated Cities, all secondary associated ZipCodes with no limit
etc.
First ensure that your code is following conventions
http://manual.cakephp.org/appendix/conventions
Try commenting all your association definitions in the models and
uncomment them one by one to find the reason. Although frustrating
that sort of problem always has a tangible and fixable reason.
> Once again, I agree that when it comes down to actual security the
> database is the place. But just to reiterate, it's for clarification
> from a code cleanliness standpoint - much like properly using private/
> public/protected namespaces - that is my intention here. Also, the
> intention of having it be compact.
>
> Maybe there is simply no good answer. I only raise the question.
Retrieving data -> Model. Custom functionality -> model functions.
Which model however is up to you and your design.
A component would be the wrong place for your data retrieval logic IMO
(since for one, you would need to then instantiate a model of some
kind or another to get the data).
Anyway, 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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---