php 将视图加载到变量中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11772651/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 02:02:43  来源:igfitidea点击:

Load view into a variable

phpcodeigniter

提问by Sml004

Is there any way that I can get content of a PHP file in to variable?

有什么方法可以将 PHP 文件的内容放入变量中?

I want to do this

我想做这个

$msg = $this->load->view('some_view');

but when I do this, $msgis NULL.

但是当我这样做时,$msgNULL

Is it possible?

是否可以?

回答by Yan Berk

It is possible:

有可能的:

$msg = $this->load->view('some_view', '', true);

回答by Madan Sapkota

There is a third optional parameter lets you change the behavior of the function so that it returns data as a string rather than sending it to your browser. This can be useful if you want to process the data in some way. If you set the parameter to true (boolean) it will return data. The default behavior is false, which sends it to your browser. Remember to assign it to a variable if you want the data returned:

还有第三个可选参数可让您更改函数的行为,使其以字符串形式返回数据,而不是将其发送到浏览器。如果您想以某种方式处理数据,这会很有用。如果您将参数设置为 true(布尔值),它将返回数据。默认行为是 false,它将它发送到您的浏览器。如果要返回数据,请记住将其分配给变量:

$msg = $this->load->view('some_view', '', true);

Source : http://codeigniter.com/user_guide/general/views.html

来源:http: //codeigniter.com/user_guide/general/views.html