Note that there are some explanatory texts on larger screens.

plurals
  1. POcakephp column mapping
    primarykey
    data
    text
    <p>I have just started working with CakePHP, so I am a complete newbie with working in this framework and have taken on a legacy system with a pretty awful database structure. I went in and added primary keys to the tables that didn't have them. However, I can't find information on where to map columns in the model, and could use some links so I can get oriented in this area. I'm starting with their user table, which has been named "system". I created a model called User:</p> <pre><code>class User extends AppModel { var $name = 'User'; var $useTable = 'system'; } </code></pre> <p>I want to map the columns to property names that are more in line with conventions without changing the existing database, since they are currently using that table. The table structure is:</p> <pre><code>Table: system Field Name DataType Nullable Default ------------------------------------------------------------------ user_id tinyint(4) No None AUTO_INCREMENT s_rec_type tinyint(4) Yes NULL s_user_id varchar(20) Yes NULL s_init char(2) Yes NULL s_password varchar(12) Yes NULL admin_access tinyint(4) No 0 fname varchar(50) No lname varchar(50) No email_address varchar(50) Yes NULL created datetime Yes NULL modified datetime Yes NULL // I added email_address, created, and modified. </code></pre> <p>I want to map the columns in the model as follows:</p> <pre><code>user_id -&gt; Id s_rec_type -&gt; UserType s_user_id -&gt; UserName s_init -&gt; Initials s_password -&gt; Password admin_access -&gt; AdminAccess fname -&gt; FirstName lname -&gt; LastName email_address -&gt; EmailAddress created -&gt; Created modified -&gt; Modified </code></pre> <p>so that I can use the methods like $this->User->findAllById($id) or $this->User->findByInitials('sb') or access the id by $this->User->id instead of something like $this->User->user_id and be more consistent with naming conventions with code that is easier to understand. </p> <p>This table will be used also to determine what menu options users have access to and which pages the user can access. I'll deal with that later. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload