Re: Silent errors when model's table is not found??

2009-08-09 Thread Abhi

Thanks for all replies. Here is what finally worked (if it might be
useful for you):

I overwrote the cakeError in app_model.php

// if this trigger - SILENT_MODEL_ERRORS is on, 'missing db table'
error wont produce and stop your stuff
function cakeError($error, $params)
{
if(defined('SILENT_MODEL_ERRORS') && SILENT_MODEL_ERRORS==true)
throw new Exception($error.' error in '.$this->name.' 
model');
else
return parent::cakeError($error, $params);
}

And caught exception on ClassRegistry::init() using try-catch
statements.


On Aug 9, 5:03 am, JamesF  wrote:
> why not just add some check while loading your models to see if they
> exist
>
> if(ClassRegistry::init($modelName)){
>
> }
>
> as an example (im sure there are better methods, check the api)
>
> On Aug 8, 3:09 pm, Abhimanyu Grover  wrote:
>
> > Right now, If a table for a specific model is not found, CakePHP
> > execution stops with big "Missing database table" error - however
> > sometimes you may run into scenario where you need not following code
> > to run.. We ran into a similar scenario in a project which has like 30
> > models, out of which some are not always required on different client
> > setups. The problem occurred when we made a shell script which
> > performs some stuff on every model of system. So, whenever it tries to
> > load a model, say:
>
> > foreach($models as $modelName) {
> > $model = ClassRegistry::init($modelName);
>
> > }
>
> > So when a model whose db table doesn't exists, is being loaded - it
> > exits saying "Missing database table" and doesnt go beyond. I went
> > a step ahead a tried overwriting Object::_stop() but that'll just
> > produce more warnings, and it just didnt worked.
>
> > Anyone faced this issue before? or Any ideas on getting ahead of the
> > problem?
>
> > Thanks guys.
> > Abhimanyu
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Silent errors when model's table is not found??

2009-08-08 Thread JamesF

why not just add some check while loading your models to see if they
exist

if(ClassRegistry::init($modelName)){

}
as an example (im sure there are better methods, check the api)


On Aug 8, 3:09 pm, Abhimanyu Grover  wrote:
> Right now, If a table for a specific model is not found, CakePHP
> execution stops with big "Missing database table" error - however
> sometimes you may run into scenario where you need not following code
> to run.. We ran into a similar scenario in a project which has like 30
> models, out of which some are not always required on different client
> setups. The problem occurred when we made a shell script which
> performs some stuff on every model of system. So, whenever it tries to
> load a model, say:
>
> foreach($models as $modelName) {
> $model = ClassRegistry::init($modelName);
>
> }
>
> So when a model whose db table doesn't exists, is being loaded - it
> exits saying "Missing database table" and doesnt go beyond. I went
> a step ahead a tried overwriting Object::_stop() but that'll just
> produce more warnings, and it just didnt worked.
>
> Anyone faced this issue before? or Any ideas on getting ahead of the
> problem?
>
> Thanks guys.
> Abhimanyu
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Silent errors when model's table is not found??

2009-08-08 Thread brian

Maybe you should re-think how your application works. If not all
tables are required, there should be some way to set that
application-specific. Maybe put something in bootstrap?

On Sat, Aug 8, 2009 at 3:09 PM, Abhimanyu Grover wrote:
>
> Right now, If a table for a specific model is not found, CakePHP
> execution stops with big "Missing database table" error - however
> sometimes you may run into scenario where you need not following code
> to run.. We ran into a similar scenario in a project which has like 30
> models, out of which some are not always required on different client
> setups. The problem occurred when we made a shell script which
> performs some stuff on every model of system. So, whenever it tries to
> load a model, say:
>
> foreach($models as $modelName) {
> $model = ClassRegistry::init($modelName);
> }
>
> So when a model whose db table doesn't exists, is being loaded - it
> exits saying "Missing database table" and doesnt go beyond. I went
> a step ahead a tried overwriting Object::_stop() but that'll just
> produce more warnings, and it just didnt worked.
>
> Anyone faced this issue before? or Any ideas on getting ahead of the
> problem?
>
> Thanks guys.
> Abhimanyu
> >
>

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Silent errors when model's table is not found??

2009-08-08 Thread Josh

I don't know if cake has a way to list all the tables.  Assuming it
doesn't you might try something like this:

//make array with tables
$sql = "SHOW TABLES";
$result = mysql_query($sql);
while ($row = mysql_fetch_row($result)) {
$tables[] = $row[0];
}

//put tables in the cake format for models
foreach ($tables as &$table) {
$table = Inflector::classify($table);
}

//intersect with your models array
$activeModels = array_intersect($tables, $models);
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Silent errors when model's table is not found??

2009-08-08 Thread Abhimanyu Grover

Right now, If a table for a specific model is not found, CakePHP
execution stops with big "Missing database table" error - however
sometimes you may run into scenario where you need not following code
to run.. We ran into a similar scenario in a project which has like 30
models, out of which some are not always required on different client
setups. The problem occurred when we made a shell script which
performs some stuff on every model of system. So, whenever it tries to
load a model, say:

foreach($models as $modelName) {
$model = ClassRegistry::init($modelName);
}

So when a model whose db table doesn't exists, is being loaded - it
exits saying "Missing database table" and doesnt go beyond. I went
a step ahead a tried overwriting Object::_stop() but that'll just
produce more warnings, and it just didnt worked.

Anyone faced this issue before? or Any ideas on getting ahead of the
problem?

Thanks guys.
Abhimanyu
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---