English 中文(简体)
编码数据没有在指数功能中初步采用
原标题:Codeignieter data is not initialized in index function

我正试图在控制器指数功能中初步数据,以便初步数据可用于控制员随后的职能。 但问题是,在我试图从其他职能中获取数据时,数据并未显示出来。 所有这些只是遵循某种以目标为导向的模式。

这里是我的法典。

class Dashboard extends CI_Controller
{
    private  $account_data;  /*Declaration*/
    private  $profile_data;

    function __construct() {
       // code...
    }

    function index()   /*Here I am initializing data*/
    {
        $this->load->model( db_model );
        $this->account_data = $this->db_model->get_row();
        $this->profile_data = $this->db_model->get_row();
        $this->load->view( user/dashboard );
    }

    function function account_details()
    {
        print_r($this->account_data);  // This displays nothing
    }

    /*other function...*/

}

理想的做法是一劳永逸地获取数据,将其用于其他职能,如果数据再次更新,则要求具备启动数据的功能。

But it is not working out. Please help me. Also suggest if I am following right approach. Thanks for your time.

最佳回答

index method is not initializer, its default page/sub_method, if you call the "*account_details*" in url as index.php/dashboard/account_details the index wont be called.

尝试将法典放在建筑商身上,

class Dashboard extends CI_Controller
{
    private  $account_data;  /*Declaration*/
    private  $profile_data;

    function __construct() { /*Here I am initializing data*/
      parent::CI_Controller(); // Thank you Sven
        $this->load->model( db_model );
        $this->account_data = $this->db_model->get_row();
        $this->profile_data = $this->db_model->get_row();
    }

    function index()   
    {

        $this->load->view( user/dashboard );
    }

    function function account_details()
    {
        print_r($this->account_data);  // This displays nothing
    }

    /*other function...*/

}

<<>Note/strong>:如果你不需要该控制器的所有方法,则在__() 施工时不使用模型或其他计算方法。

model_ initializer(>)”等私人方法将这种代码放在这个范围上,并在您的其他会议名称中称作“代码”<$this->model_ initialize();,如果需要的话。

感谢奥约·塞萨马·塞萨梅。

问题回答

暂无回答




相关问题
Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

JSON with classes?

Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Passing another class amongst instances

I was wondering what is the best practice re. passing (another class) amongst two instances of the same class (lets call this Primary ). So, essentially in the constructor for the first, i can ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签