Help with a CakePHP Project

Discussion in 'PHP' started by capebretoner, Feb 2, 2008.

  1. #1
    I am looking for some help setting up a cakephp web application that I am building. It will have 2 completely seperate databases as one is only data that is not to be modified, only for reference. This reference database can change in the future.

    The other database will hold the application info. For example, I want to be able to search the name in on DB and then grab the results. The reference DB contains a number of associated tables which I have set up the models for.

    If you know something about Cake please let me know as I would like to pick your brain.

    Thanks,
     
    capebretoner, Feb 2, 2008 IP
  2. darren884

    darren884 Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi just use different tables, not different databases. You will regret it. Look at the CakePHP bakery model page. You will learn a lot how to do queries.
     
    darren884, Feb 3, 2008 IP
  3. capebretoner

    capebretoner Well-Known Member

    Messages:
    536
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    128
    #3
    I think that I will move them to the same database as you mention. However I still have the problem that the DB that I am using does not have an "id" header. I am trying to do most of the work upfront so that when the DB that I am using gets updated then all I have to do is upload it and go so I would rather not have to change that stuff. Do you know how to make this work in CAKE? Or is it an exercise in futility?
     
    capebretoner, Feb 3, 2008 IP
  4. qeorge

    qeorge Peon

    Messages:
    206
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I think I can help you, I spend all my time with CakePHP :)

    Basically, you're going to want to specify multiple database configurations. The first step is to open up /app/config/database.php

    You should have something like this:
    
        var $default = array(
            'driver' => 'mysql',
            'persistent' => false,
            'host' => 'localhost',
            'login' => 'db_login',
            'password' => 'password',
            'database' => 'db_mydatabase', 
            'prefix' => '' 
        );
    
    Code (markup):
    What you will want to do is specify 2 possible configurations, and then tell your models which one to use.

    So for example you could put this code in database.php:

    
        var $users = array(
            'driver' => 'mysql',
            'persistent' => false,
            'host' => 'localhost',
            'login' => 'db_login',
            'password' => 'password',
            'database' => 'db_users', 
            'prefix' => '' 
        );
    
        var $appInfo = array(
            'driver' => 'mysql',
            'persistent' => false,
            'host' => 'localhost',
            'login' => 'db_login',
            'password' => 'password',
            'database' => 'db_appinfo', 
            'prefix' => '' 
        );
    
    Code (markup):
    Then in your models, you set which config to use. So for example to make your User model load its data from db_users, you simply add a variable to your model, making it look something like this:

    
    class User extends AppModel 
    {
        var $name = 'User';
        var $useDbConfig = 'users';    
    }
    
    Code (markup):
    Then for another model, say Profile, you would tell it to load its data from db_appinfo like this:


    
    class Profile extends AppModel 
    {
        var $name = 'Profile';
        var $useDbConfig = 'appinfo';    
    }
    
    Code (markup):
    You should be off to the races now. PM me if you have trouble getting it working.

    Also, per this page, make sure you set persistent to false in your alternate DB Configs.

    Got to love Cake, best framework around. Cheers!
     
    qeorge, Feb 4, 2008 IP
  5. capebretoner

    capebretoner Well-Known Member

    Messages:
    536
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    128
    #5
    Excellent, thanks

    I am just getting into CAKE for my pet project. I have a long way to go yet. Do you have any good tutorials on how to build a directory? That is the starting point for my app :)

    Thanks
     
    capebretoner, Feb 11, 2008 IP