2012-01-12 74 views

回答

4

您必須將其設置爲類變量並使用它。

喜歡的東西:

<?php 
class Blog extends CI_Controller { 

    $my_variable = null; 

    function _set_myvariable() 
    { 
     $this->my_variable = "this variable has a value"; 
    } 

    function get_variable() 
    { 
      echo $this->my_variable; // outputs NULL 
      $this->_set_myvariable(); 
      echo $this->my_variable; // outputs "this variable has a value" 
    } 
} 
?> 

調用get_variable方法:

  1. 調用_set_myvariable私有函數(注意, 「_」 開始的函數名),將設置類變量。
  2. 然後,它會呼應的是變量的值(這將是「這個變量的值是」)
+0

好涼快。謝謝! – 2012-01-12 22:41:53

相關問題