It is a very steep learning curve, and I keep forgetting what I learn, so just going to keep a list.
- To make a link to ‘id’ on a .ctp page link to something more useful change the column name thus:
echo $this->Html->link($powerpoint['User']['id'], array('controller' => 'users', 'action' => 'view', $powerpoint['User']['id'])); //becomes echo $this->Html->link($powerpoint['User']['username'], array('controller' => 'users', 'action' => 'view', $powerpoint['User']['id']));(The query is doing a join automatically in the background)
- To make a droplist show a useful thing like the name rather than the key, you need to go in to the XxxxxxController and change the function thus:
$users = $this->Powerpoint->User->find('list'); //becomes $users = $this->Powerpoint->User->find('list',array('fields' => array('User.id', 'User.username')));I guess it then used the two fields as given. If you add a third field it is used as a label in the option. Not sure how to concatenate the columns if you want “Firstname Lastname” in the droplist.
- The Model reflects the database. I knew that but recording it here, as I actually used it.
- If you have a table that is joined through another table (belongsto > belongsto) then you can make it appear thus in the Controller:
$users = $this->Question->Powerpoint->find('list', array( "fields" => array('Powerpoint.user_id', 'Users.username'), "joins" => array( array( "table" => "Users", "type" => "LEFT", "conditions" => array( "Powerpoint.user_id = users.id" ) ) ) ));