gpt4 book ai didi

variables - 代码点火器 View 记住以前的变量!

转载 作者:行者123 更新时间:2023-12-01 05:43:22 25 4
gpt4 key购买 nike

我在 Controller 中有以下代码:

$data['what'] = 'test';
$this->load->view('test_view', $data);
$this->load->view('test_view');

看法:
<?php
echo $what;
?>

运行此代码时的结果是:
testtest

不应该只是“测试”,因为我第二次没有传递变量 $data 吗?
如何让 CodeIgniter 以这种方式运行?

编辑1:

我想出了一个临时解决这个问题的方法:

在 Loader.php 中替换:
/*
* Flush the buffer... or buff the flusher?
*
* In order to permit views to be nested within
* other views, we need to flush the content back out whenever
* we are beyond the first level of output buffering so that
* it can be seen and included properly by the first included
* template and any subsequent ones. Oy!
*
*/

和:
 /*
* Flush the buffer... or buff the flusher?
*
* In order to permit views to be nested within
* other views, we need to flush the content back out whenever
* we are beyond the first level of output buffering so that
* it can be seen and included properly by the first included
* template and any subsequent ones. Oy!
*
*/

if (is_array($_ci_vars)){
foreach ($_ci_vars as $key12 => $value12) {
unset($this->_ci_cached_vars[$key12]);
}
}

这应该在使用完毕后从缓存中删除变量。

错误报告: http://bitbucket.org/ellislab/codeigniter/issue/189/code-igniter-views-remember-previous

最佳答案

这很有趣,我从来没有像这样使用它,但你是对的,它不应该这样做,也许这是一些缓存选项。在最坏的情况下,您必须这样称呼它:

$this->load->view('test_view', '');

编辑:

我刚刚检查了他们存储库中的 Code Igniter 代码。这样做的原因是他们确实在缓存变量:
    /*
* Extract and cache variables
*
* You can either set variables using the dedicated $this->load_vars()
* function or via the second parameter of this function. We'll merge
* the two types and cache them so that views that are embedded within
* other views can have access to these variables.
*/
if (is_array($_ci_vars))
{
$this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
}
extract($this->_ci_cached_vars)

如果我理解正确,您必须不幸地这样做:
$this->load->view('test_view', array('what' => ''));

关于variables - 代码点火器 View 记住以前的变量!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3919269/

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