-1
我有這個控制器我可以在同一個類的方法中訪問私有變量嗎?
class PageController extends Controller
{
private $myid;
public funciton index(){
}
public function viewbyid($id){
$this->myid = $id;
return view('someview');
}
public function getRecord(){
$id = $this->myid;
echo $id; //it would be null here,if I am going to access this method.
return view('anotherview');
}
}
是的,這就是'private'手段.... [RTFM(http://www.php.net/manual/en/language.oop5.visibility .php) –
但我試過它返回null – jemz
然後你在哪裏設置它?你在哪裏調用'viewbyid()'? –