Oh, nevermind. I just reread. I guess I was simply trying to set up
the if else inside the database_config class and set the $default
accordingly.

On Feb 8, 1:37 pm, Corie <[EMAIL PROTECTED]> wrote:
> That actually does look like a better solution, as I was also trying
> to figure out how to make it switch for all Models.
>
> I'm a bit new to OOP, how do you set up your /config/database.php
> file? You have to put the conditionals in a function right?
>
> On Feb 8, 11:32 am, grigri <[EMAIL PROTECTED]> wrote:
>
> > Interesting... I do it a completely different way. I have 2 database
> > config files : database.dev.php and database.live.php, each containing
> > a full DATABASE_CONFIG class with my configurations (default, test,
> > and whatever else I need for the app).
>
> > Then, in /config/database.php, I have this:
>
> > if (empty($_SERVER['SERVER_NAME']) ||
> > in_array(strtolower($_SERVER["SERVER_NAME"]), array('grigri',
> > 'localhost'))) {
> >   require "./database.dev.php";}
>
> > else {
> >   require "./database.live.php";
>
> > }
>
> > This way the models don't have to make any changes, it's all
> > automatic.
>
> > How do other people deal with this?
>
> > On Feb 8, 4:23 pm, Corie <[EMAIL PROTECTED]> wrote:
>
> > > I'm running the same cake app on two different servers, development
> > > and production. I want to change the database config that's used
> > > depending on the server. I've got the following set up now.
>
> > > /config/database.php
>
> > > class DATABASE_CONFIG {
> > >         var $development = array(
> > >                 'driver' => 'mysql',
> > >                 'persistent' => false,
> > >                 'host' => 'localhost',
> > >                 'port' => '',
> > >                 'login' => 'admin',
> > >                 'password' => 'password',
> > >                 'database' => 'db',
> > >                 'schema' => '',
> > >                 'prefix' => '',
> > >                 'encoding' => ''
> > >         );
> > >         var $production = array(
> > >                 'driver' => 'mysql',
> > >                 'persistent' => false,
> > >                 'host' => 'localhost',
> > >                 'port' => '',
> > >                 'login' => 'user_admin',
> > >                 'password' => 'password',
> > >                 'database' => 'user_db',
> > >                 'schema' => '',
> > >                 'prefix' => '',
> > >                 'encoding' => ''
> > >         );
>
> > > }
>
> > > /models/table.php
>
> > > class Table extends AppModel
> > > {
> > >         var $name = 'Table';
>
> > >         function beforeFind()
> > >         {
> > >                 if(is_dir('D:\webserver\private_html\site'))
> > >                 {
> > >                         $this->useDbConfig = 'development';
> > >                 }
> > >                 elseif(is_dir(DS.'home'.DS.'user'.DS.'public_html'))
> > >                 {
> > >                         $this->useDbConfig = 'production';
> > >                 }
> > >         }
>
> > > }
>
> > > It just keeps trying to use the 'default' config. I've also tested my
> > > logic by just putting $this->useDbConfig = 'development'; directly
> > > under the beforeFind() function, but it still does nothing. Do I need
> > > to put this somewhere else?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to