gpt4 book ai didi

php - 在 View 内的函数中访问 Codeigniter 数据变量

转载 作者:可可西里 更新时间:2023-10-31 22:15:14 24 4
gpt4 key购买 nike

我的一个 View 中有一个函数,我想通过 CodeIgniter 的数据数组访问 View 可用的变量之一。

例如;在我的 Controller 中我有这个:

$this->load->view('someview', array(
'info' => 'some info'
));

现在,在我看来,我有一个函数,我希望能够从该函数范围内访问变量 $info

这可能吗?

最佳答案

在你的 Controller 中:

    $GLOBALS['var_available_in_function'] = $value;

你的功能:

    function get_var() {
global $var_available_in_function;

return $var_available_in_function;
}

关于php - 在 View 内的函数中访问 Codeigniter 数据变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6983907/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com