私はコントローラ内にグローバル変数を定義しましたが、index()関数内で値を割り当てています。 index()内でアクセス可能な値ですが、aboutやその他の関数内ではアクセスできません。どうすればいい?codeigniterグローバル変数の値がアクセス可能でない
class Manage_business extends CI_Controller
{
var $id;
public function __construct()
{
parent::__construct();
}
public function index($no)
{
$this->id=$no;
echo $this->id;
}
public function about()
{
echo $this->id;
die();
}
}
を確認してください。http://stackoverflow.com/questions/17013397/code-igniter-best-place-to-declare-global-variableおよびhttp://stackoverflow.com/questions/19237316/how-to-use- global-variable-in-php-codeigniter – Saty
コンストラクタ内に値が割り当てられています。私はindex()内に割り当てました。私はスーパーグローバル変数を望んでいません。 –
about関数を直接使用している場合は、$ this-> idの値をindex関数で設定することはできません。 – Ali