之前用的 CI,在 __construct 里 $this->变量名,就可以直接调用,Yii 有没有类似的?
__construct
$this->变量名
不是你这样写的,要先声明属性
class ArticleController extends Controller { public $request; public function init(){ $this->request = Yii::$app->request; } public function actionIndex() { $this->request->get(); } }
谢谢~~~
直接赋给成员变量不就行了。
怪就怪你php基础还不行,怎么就到框架了呢。年轻人,基础很重要哦!
慢滚不送~~
这就有点低素质了啊
@刘师傅 你素质高,我发问题不去论坛发帖,不是为了跟你扯淡的。
private $_wx;
/** * {@inheritdoc} */ public function beforeAction($action) { if (parent::beforeAction($action)) { $this->_wx = yii::$app->params['weixin']; return true; } return false; } public function actionTest(){ print_r($this->_wx); }
private $_wx; /**
{@inheritdoc} */ public function beforeAction($action) { if (parent::beforeAction($action)) {
$this->_wx = yii::$app->params['weixin']; return true;
}
return false; }
public function actionTest(){
print_r($this->_wx);