Hello. I’m getting an error in my ProjectsController:
Missing argument 1 for ProjectsController::loadModel(), called in /Applications/XAMPP/xamppfiles/htdocs/quicksand/protected/controllers/ProjectsController.php on line 56 and defined
Not sure what the issue is. In the condition: ‘condition’=>‘project=:projectId’, project refers to the foreign key in the “Projectitem model”, as I assume that’s what should be referenced. In the Projectitem model I have the following relation:
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'project' => array(self::BELONGS_TO, 'Projects', 'project'),
);
}
I assume this relation needs to be defined for the condition to work in the CActiveDataProvider.
The end goal is I want to make the Projectitem a sub record of the Project record, with the Projectitem info being displayed in the Project record it relates to. I’m following the example in the book Agile Web Application Development chapter 6 page 129.
are you using standard Gii generator or GiiX? there are differences in those two on loadModel method. standard Gii generates loadModel() function without parameters, while GiiX generates loadModel( $modelName, $primaryKey ) function…
wow… you are right. I have not used default generator since about half year, so the change must be rather new
anyway - blog demo still has the old version which depends on GET param:
public function loadModel()
{
if($this->_model===null)
{
if(isset($_GET['id']))
$this->_model=Comment::model()->findbyPk($_GET['id']);
if($this->_model===null)
throw new CHttpException(404,'The requested page does not exist.');
}
return $this->_model;
}