Wednesday, April 29, 2009

Re: How to catch Controller::loadModel/ClassRegistry::init errors

You could probably get list of tables instead listing models, You
could probably use that piece of code:

$db =& ConnectionManager::getDataSource('default');
$sources = $db->listSources();

Iterate through $sources and do Your stuff. It makes more sense too,
becouse You need to do stuff on Your tables, not on classes that
inherits from Model class.
Probably You will get association tables too, so You'll need to call
class_exist and stuff ;)

On Apr 28, 5:42 pm, Pixelastic <timcc.pe...@gmail.com> wrote:
> Hopefully this will be a one time thing :) I was just wondering if my
> approach for handling errors could have been improved. I guess it's
> simpler to know which model to include/exclude.
>
> Thanks for pointing out the typo.
>
> SpecialModel is a wrapper model (like AppModel) that I have to use
> accross several projects, containing its own logic and callbacks. Each
> of these projects have in addition their own logic and callback (in
> AppModel). I did'nt want to merge the two files as it is easier for
> maintenance that way and I can overwrite methods in a per project
> basis
>
> On 28 avr, 17:30, brian <bally.z...@gmail.com> wrote:
>
> > Is this just a one-time thing? Wouldn't it be simpler just to list the
> > models you need to access?
>
> > You have a typo, also: "SpecialModal". What's SpecialModel for, anyway?
>
> > On Tue, Apr 28, 2009 at 8:23 AM, Pixelastic <timcc.pe...@gmail.com> wrote:
>
> > > Sorry, hit 'Send' too early...
>
> > > The code I'm using is :
>
> > > $appModelList = Configure::listObjects('model');
> > > foreach($appModelList as $modelName) {
> > >        // I have to manually exclude those two model or loadModel
> > > will fail
> > >        if (in_array($modelName, array('SpecialModal', 'AppModel'))) {
> > >                continue;
> > >        }
> > >        //      Loading the model
> > >        $this->loadModel($modelName);
> > >        $model = &$this->{$modelName};
> > >        $modelSchema = $model->schema();
>
> > >        [...]
>
> > > }
>
> > > $this->loadModel fails with SpecialModel and AppModel because they do
> > > not have a table, and all I'm getting is a 'Missing table' page.
> > > My question was: Is there a way to stop my loop if $this->loadModel()
> > > failed instead of manually exclude them ?
>
> > > On 28 avr, 14:19, Pixelastic <timcc.pe...@gmail.com> wrote:
> > >> Well, AppModel and SpecialModel are the only two models that do not
> > >> use a table .I think I may not have been clear enough and you
> > >> misunderstood what I was trying to do.
>
> > >> Here is the context :
>
> > >> I had to apply a regexp to every text field of every item saved in my
> > >> database. So I list every model of my App, instantiate them, find
> > >> their schema, find the text fields for each model. Then I query my db
> > >> for each model, apply the regexp to each text field of each returned
> > >> element and save the element back.
>
> > >> The code I used :
>
> > >> $appModelList = Configure::listObjects('model');
> > >> foreach($appModelList as $modelName) {
> > >>         //if (in_array($modelName, array('SpecialModal', 'AppModel'))) {
> > >>                 continue;
> > >>         }
> > >>         //      Loading the model
> > >>         $this->loadModel($modelName);
> > >>         $model = &$this->{$modelName};
> > >>         $modelSchema = $model->schema();
>
> > >>         [..]
>
> > >> }
>
> > >> On 28 avr, 09:24, Miles J <mileswjohn...@gmail.com> wrote:
>
> > >> > Well if you add that to AppModel, ALL your models will not have a
> > >> > database table. Only put that in the models that DO NOT have a table.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: