Php 无法分配类公共属性

Php 无法分配类公共属性,php,class,properties,assign,Php,Class,Properties,Assign,在下面的代码段中,公共属性public$page应该被分配为home、login或articles,但当我尝试回显它时,结果为空 <?php class Site extends CI_Controller { public $page; public function index(){ $this->pager(); } // page requester public function pager($page = 'home'){ $this->p

在下面的代码段中,公共属性
public$page
应该被分配为home、login或articles,但当我尝试回显它时,结果为空

<?php

class Site extends CI_Controller {

public $page;

public function index(){
    $this->pager();
}

// page requester

public function pager($page = 'home'){
    $this->page = $page;
    $filename = "../views/{$page}.php";
    $whitelist = array('home', 'login', 'articles');
    if (!file_exists($filename) && in_array($page, $whitelist)) {
        $this->$page();
    }
    else {
        // Whoops we can't find the page you requested..
        show_404();
    }
}

// all controllers

public function home(){
    $data['title'] = $this->page;
    $this->load->view('templates/header', $data);
    $this->load->view('pages/home', $data);
    $this->load->view('templates/footer', $data);
}

public function login(){
    $data['title'] = $this->page;
    $this->load->view('templates/header', $data);
    $this->load->view('pages/login', $data);
    $this->load->view('templates/footer', $data);
}

public function articles(){
    $data['title'] =  $this->page;
    $this->load->view('templates/header', $data);
    $this->load->view('pages/articles', $data);
    $this->load->view('templates/footer', $data);
}

}

?>

$this->page=$page
正在分配公共属性,但仍然为空。在
函数pager()中有一个
$this->$pager()
。那是打字错误吗?还有,它最终会变成一个无限循环吗?@Passerby我的
$this->pager()
函数中没有任何
$this->pager()
调用你的
pager()
函数,如果(!file\u存在(…){}
@passery仔细查看它的
$this->page()
不是
$this pager())