>백엔드 개발 >PHP 튜토리얼 >codeigniter - php 新手 问题

codeigniter - php 新手 问题

WBOY
WBOY원래의
2016-06-06 20:45:101176검색

model

<code>    class Stock_model extends CI_Model{

        private $hsh;
        function __construct()
        {
            parent::__construct();
            $_ci = & get_instance();


            //$this->hsh = $_ci->load->database('hsh',TRUE);
            $hsh = $_ci->load->database('hsh',TRUE);
        }



        function  get_stock($goods_huo)
        {
            if(isset($goods_huo))
            {
                $hsh->where('item_huo',$goods_huo);
                $query =  $hsh->get('item_info');

                return $query->result_array();
                $query->free_result();

            }
        }
    }
</code>

报错

<code><h4>A PHP Error was encountered</h4>
<p>Severity: Notice</p>
<p>Message:  Undefined variable: hsh</p>
<p>Filename: models/stock_model.php</p>
<p>Line Number: 22</p>
<br>
<b>Fatal error</b>:  Call to a member function where() on a non-object in <b>D:\htdocs\application\models\stock_model.php</b> on line <b>22</b><br>
</code>

刚学,很多问题不懂 ! 这是用的CI

回复内容:

model

<code>    class Stock_model extends CI_Model{

        private $hsh;
        function __construct()
        {
            parent::__construct();
            $_ci = & get_instance();


            //$this->hsh = $_ci->load->database('hsh',TRUE);
            $hsh = $_ci->load->database('hsh',TRUE);
        }



        function  get_stock($goods_huo)
        {
            if(isset($goods_huo))
            {
                $hsh->where('item_huo',$goods_huo);
                $query =  $hsh->get('item_info');

                return $query->result_array();
                $query->free_result();

            }
        }
    }
</code>

报错

<code><h4>A PHP Error was encountered</h4>
<p>Severity: Notice</p>
<p>Message:  Undefined variable: hsh</p>
<p>Filename: models/stock_model.php</p>
<p>Line Number: 22</p>
<br>
<b>Fatal error</b>:  Call to a member function where() on a non-object in <b>D:\htdocs\application\models\stock_model.php</b> on line <b>22</b><br>
</code>

刚学,很多问题不懂 ! 这是用的CI

<code class="lang-php">//$this->hsh = $_ci->load->database('hsh',TRUE);
$hsh = $_ci->load->database('hsh',TRUE);
</code>

Message: Undefined variable: hsh
未定义变量hsh
你把$hsh都改为$this->hsh。
随便建议一下,应该把基础打好了再用框架,过早使用框架只会抑制你的成长。

$hsh 换成 $this->hsh

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.