thinkphp D方法怎么給構造函數傳參
4 回答

慕標琳琳
TA貢獻1830條經驗 獲得超9個贊
如PHP code控制器類:
class NewAction extends Action{
public function index()
{
$this->display();}
private function show($cls)//我想在模板中傳入參數
{
$news=M("news");
$list=$news->where('class=$cls')->order("time desc")->select();
$this->assign("list",$list);
$this->display();
/* header("Content-type:text/html;Charset=utf-8");
echo $cls;*/
}
}

ibeautiful
TA貢獻1993條經驗 獲得超6個贊
直接 $this -> function(); 就可以了... 完全把Action當做一個Class看待即可,靈活使用,參數也是可以加的,不過聲明的時候盡量加上默認參數,免得通過模塊調用的時候,報出無參數的提醒錯誤。
- 4 回答
- 0 關注
- 817 瀏覽
添加回答
舉報
0/150
提交
取消