RockCat 2011-03-20 15:27:38 4381次浏览 8条回复 0 0 0
class NewsController extends Controller
{
	public $layout='/layouts/sidebar';
	public $catid = $_GET['catid']; //这句提示我语法错误
}

请问要怎么获取呢?

  • 回复于 2011-03-20 15:32 举报

    这种情况最好写一个getter方法,下面是具体代码:

    class NewsController extends Controller
    {
      public $layout='/layouts/sidebar';
    
      public function getId()
      {
        return $_GET['id'];
      }
    }
    

    在使用的时候,直接用$this->id就可以了。

  • 回复于 2011-03-20 15:34 举报

    那我获取的参数是catid,是不是写个getCatid()方法?

    public function getCatid()
    {
      $this->catid = Yii::app()->request->getParam('catid');
    }
    
  • 回复于 2011-03-20 15:39 举报

    上面的代码没有返回值啊?

  • 回复于 2011-03-20 15:45 举报

    这样写:

    public function getCatid()
    {
      return Yii::app()->request->getParam('catid');
    }
    

    使用的时候可以用$this->catid;

  • 回复于 2011-03-20 16:28 举报

    💫
    还是不行啊!

  • 回复于 2011-03-20 16:31 举报

    是按照我的方法做的吗?

  • 回复于 2011-03-20 22:42 举报

    已经可以了,谢谢巡洋舰!

  • 回复于 2011-03-22 10:15 举报

    我觉得这样会引起xss的问题,建议还是简单的$_get or $_post分离开来写。。。太模糊 容易出问题。

您需要登录后才可以回复。登录 | 立即注册