无法分配类公共属性

时间:2012-10-12 03:55:08

标签: php class properties assign

在下面的代码中,公共属性public $page应该被指定为主页或登录或文章,但是当我尝试回显它时,结果为空。

<?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);
}

}

?>

0 个答案:

没有答案