Thursday, October 28, 2010

Re: 2 database, 1 models and controllers, many views

Sure, no problem.

Just use 2 db configs and set the $default db config on runtime:

file app/config/database.php

class DATABASE_CONFIG {

var $default = null;

var $dev = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => secret1'',
'database' => 'db1',
'prefix' => '',
'encoding' => 'utf8',
);

var $prod = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => 'secret2',
'database' => 'db2',
'prefix' => '',
'encoding' => 'utf8',
);
/**
* @link http://edwardawebb.com/web-development/cakephp/automatically-choose-database-connections-cakephp
*/
function __construct() {
//check to see if server name is set
if(isset($_SERVER['SERVER_NAME'])) {
switch($_SERVER['SERVER_NAME']) {
case 'example1.pl':
case 'www.example1.pl':
$this->default = $this->prod;
break;
default:
$this->default = $this->dev;
break;
}
}
else {
// we are likely baking, use our local db
$this->default = $this->dev;
}
}
}

The code above was taken from @link in comment. The dev is my laptop
with XAMPP, the prod is my production sever, both have MySQL server on
localhost.
I use it to automatically change db configs without editing config
file.

On Oct 28, 3:16 pm, Dmitry Shevchenko <dmitr...@gmail.com> wrote:
> I wanted to create 2 separated web site which will use same models and
> controllers.
>
> main aim - run 2 sites which will use almost the same logic but it
> will be build with different design.
> I wanted to use same models and controllers, because I want to support
> only one version.
>
> so database structure, models, controllers will be the same
> differents - views (design) and domains.
>
> On Oct 28, 2:54 pm, Zaky Katalan-Ezra <procsh...@gmail.com> wrote:
>
>
>
> > What is your goal?
>
> > On Thu, Oct 28, 2010 at 12:31 PM, Dmitry Shevchenko <dmitr...@gmail.com>wrote:
>
> > > Hi.
> > > Is it possibly for cake to have 2 different database, which is use
> > > same models and controllers and different views.
>
> > > I need this to create a almost copy of website, so system logic will
> > > be the same, I will only have separated DB and views.
>
> > > Seems this could be done by switching config on config.php and maybe
> > > dispatcher.php... but I'm not sure.
>
> > > Is someone do something similar ?
>
> > > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp 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<cake-php%2Bunsubscribe@googlegroups.c om>For more options, visit this group at
> > >http://groups.google.com/group/cake-php?hl=en
>
> > --
> > Regards,
> > Zaky Katalan-Ezra
> > QA Administratorwww.IGeneriX.com
> > Sites.IGeneriX.com
> > 054-7762312

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: