Monday, February 1, 2010

Re: checking whether a table exists

Controllers expect to have a model which in turn expects to have a table
in the DB by default. If you have a controller that doesn't use a model
set $uses to 'null' or an empty array... if you have a model that
doesn't have a datasource then look at $useTable and $schema variables
in http://api.cakephp.org/class/model

On Mon, 2010-02-01 at 19:29 +0100, Lorenzo Bettini wrote:
> The problem I have with my solution, but I guess it's the same of the
> one of the link, is that if I use it inside a controller, I get an error
> before even reaching that code, due to a missing table... is there a way
> to avoid this?
>
> Of course I need this check for an installation page, which I'm
> developing using a controller...
>
> thanks in advance
> Lorenzo
>
> Miles J wrote:
> > You can try this, then see if your table exists within the array.
> >
> > http://www.milesj.me/blog/read/75/Retrieving-Tables-Within-Your-Cake-Database
> >
> > On Feb 1, 8:27 am, Lorenzo Bettini <bett...@dsi.unifi.it> wrote:
> >> Hi
> >>
> >> is this a correct way of checking whether a table exists?
> >>
> >> function check_table_exists($table) {
> >> $dbo = $this->getDataSource();
> >> $result = $dbo->_execute('DESCRIBE '.$table);
> >> return !empty($result);
> >> }
> >>
> >> thanks in advance
> >> Lorenzo
> >>
>
>
>


Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

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: