1

我对 CodeIgniter 很陌生。几个小时以来,我一直面临着一个非常恼人的问题。这是代码

    <?php
    class Hello extends CI_Controller
    {
     var $firstname;
 var $lastname;

    function _construct()
{
  parent::_construct();
  $this->firstname='Ashutosh';
  $this->lastname='Bajpay';

}

function you()
{ 
  $data['firstname'] = $this->firstname;
  $data['lastname'] = $this->lastname;
  $this->load->view('ashu',$data);
}
   }
   ?>

并且视图文件 ashu.php 是-

     Hello, <?php echo $firstname;?> <?php echo $lastname;?>! This is your second     CodeIgniter program.

输出是-

您好!这是您的第二个 CodeIgniter 程序。

但是当我写作的时候——

    function you()
{ 
  $data['firstname'] = 'Ashutosh';
  $data['lastname'] = 'Bajpay';
  $this->load->view('ashu',$data);
}

然后输出是想要的-

您好,Ashutosh Bajpay!这是您的第二个 CodeIgniter 程序。

4

1 回答 1

1

change

     var $firstname;
     var $lastname;

to

    private  $firstname;
    private  $lastname;
于 2013-01-09T12:24:17.843 回答