این تکه کدی که داخل پست کنترلر هستش با توجه به اسمش انگار داره یه مدل رو فراخانی میکنه
[/rtl]
public function actionView()
{
$post=$this->loadModel();
$comment=$this->newComment($post);
$this->render('view',array(
'model'=>$post,
'comment'=>$comment,
));
}
[rtl]
ولی تو همین فایل به این صورت تعریف شده:
[/rtl]
public function loadModel()
{
if($this->_model===null)
{
if(isset($_GET['id']))
{
if(Yii::app()->user->isGuest)
$condition='status='.Post::STATUS_PUBLISHED.' OR status='.Post::STATUS_ARCHIVED;
else
$condition='';
$this->_model=Post::model()->findByPk($_GET['id'], $condition);
}
if($this->_model===null)
throw new CHttpException(404,'The requested page does not exist.');
}
return $this->_model;
}
darmorede $post=$this->loadModel(); bayad begam ke hameye model ha in function ro daran va bar asase niyazeshoon azash estefade mikonan , va shooma ham baraye inke betoonid dar view commenthaye in post ro bebinid niyaz darid ke aval objecte poste morede nazar ro load konid va az roye oon commentharoo peyda konid .
ke albae dakhele khoode loadModel() chand ta shart ro ham check mikone ke masalan aya user sabt shoode ast ya kheyr va bar asase un mataleb ro neshoon mide .