Jump to content
Larry Ullman's Book Forums
KeepLearning

The Loadmodel Controller Method: Which Table Will Be Searched?

Recommended Posts

Version 0.5

 

Loading a Single Model

 

The following two examples work together. The second calls the first. I believe the purpose is to retrieve a record from a table. And I believe each occurrence of $id represents the primary key value of the particular record we want.

 

My question is, how do these functions know which table to search in? 

 

page 136:

 

public function loadModel($id) {
$model = Page::model()->findByPk($id);
if ($model===null) {
throw new CHttpException(404, 'The requested page
does not exist.');
}
 
Page 139:
public function actionView($id){
$this->render('view',array(
'model'=>$this->loadModel($id),
));
}

Share this post


Link to post
Share on other sites

They know what database table to search in because of the model type. The Page model is linked to the page table. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...