On Sep 6, 4:02 am, AD7six <[EMAIL PROTECTED]> wrote:
> 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.
>
Aye, I could have been more clear. :)
> > It's not so much a security thing as it is a confusion thing. Cake
> > really should have a read only model structure.
>
The reason for "why" in my mind is bloat. Why go through the process
of loading an entire ORM object when all you want is read-only access?
I think a read only model type with all the fat trimmed would be a
nice addition. Maybe I'm alone there..
> 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) {
> // Seehttp://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));
>
> }
I agree. $usesTable was not something I was aware existed. RTFM, eh?
In that case I can write my own custom SQL and not have to rely on
Cake for these relationships. It's not that Cake CAN'T do this, I just
know that what I want out of these tables is very specific and Cake's
ORM is way too bloated for it with its internal reflection and
relationships. It just isn't efficient. Being able to use a model
without Cake automatically associating it to a table, however, is
pretty much what I want. As I said previously, being able to have a
trimmed down read-only version of this would be more ideal, this will
certainly suffice.
>
> > > > 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.
>
Aye, the behavior works nice for this implementation now that I
understand it a bit more.
> 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)
>
Actually, I mistyped here. The controller was setup correctly and
$uses is there because I was experiementing with differnet models and
didn't feel like creating a new controller just for the scaffolding
while I was trying to track down why Apache was exploding.
> > 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
> conventionshttp://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.
>
It seems to be specific to the PHP and Apache version I had. I am
runnig this for now on a WAMP install (wampserver.com) and I just
upgraded to the newest version. After doing that the scaffolding is
working. :)
>
> 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
I appreciate the advice (all of you).. I'll simply define a Geo model
that doesn't have any automatic associations to tables.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---