Question about blog tutorial controller

when comparing the generated controller code and the blog tutorial’s controller code as link from here http://www.yiiframework.com/doc/blog/1.1/en/post.display, I see a difference in that the code generated as of 1.1.10 has an id.

Is it still ideal to follow the blog tutorial’s controller code? if not, what’s the ideal way of building the controller?

are there changes to the loadmodel method?

lastly, is it ideal and will it work if the $id parameter is removed?

did you try and see what will happen if you remove the $id.

I’ll receive

so I thought that


if isset($_GET['id'])

does not work, but strange that the actionAdmin method has


$_GET['Post']

and it works.

so I was wondering why $_GET[‘id’] is not working.

below is my code:




public function actionView($id='')

{

      $post=$this->loadModel();

      $this->render('view', array('model'=>$post));

}


public function loadModel($id='')

{

         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($id,$condition);                        

                }

                if ($this->_model===null)

                    throw new CHttpException(404,'The requested page does not exist.');

        }

	return $this->_model;

}



Errr…Nevermind, I just found that I have an error here:


$this->_model = Post::model()->findByPk($id,$condition); 

which should be changed to


$this->_model = Post::model()->findByPk($_GET['id'],$condition); 

…if only I knew how to debug my code in Netbeans…

Thanks for your time.