return require_once
,但是当我不想显示它时,它会显示html代码并显示每一个。
这是load_view
方法:
function load_view($view, $data, $async){
if (is_array($data)){
foreach ($data as $key => $value) {
$$key = $value;
}
}
if ($async) {
return $tmp = require_once('aplication/view/'.$view.'.php');
} else {
echo require_once('aplication/view/'.$view.'.php');
}
}
实现该方法的控制器:
class user extends core_controller {
function __construct() {
$this->data['css'] = array('public/bootstrap/css/bootstrap.min.css',
'public/css/login.css' );
}
function action(){
$this->data['content'] = $this->load_view('loginForm', array(), true);
$this->load_view('templates/template', $this->data);
}
}
意见:
第一:template
<div class="container">
<?php echo $content; ?>
</div>
第二名:loginForm
<div class="row vertical-offset-100">
<div class="col-md-4 col-md-offset-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Please sign in</h3>
</div>
<div class="panel-body">
<form method="post" action="login/enter" accept-charset="UTF-8" role="form">
<fieldset>
<div class="form-group">
<input class="form-control" placeholder="Username" name="username" type="text" required>
</div>
<div class="form-group">
<input class="form-control" placeholder="Password" name="password" type="password" value="" required>
</div>
<a href="#" class="btn btn-info btn-block" role="button">Registrarme</a>
<input class="btn btn-lg btn-success btn-block" type="submit" value="Login">
</fieldset>
</form>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
使用文件获取内容而不是require
if ($async) {
return file_get_contents("yourfile.php");
}
答案 1 :(得分:0)
好的,我在这里得到的是load_view
function load_view($view, $data, $async){
if (is_array($data)){
foreach ($data as $key => $value) {
$$key = $value;
}
}
if ($async) {
ob_start();
include('aplication/view/'.$view.'.php');
$buffer = ob_get_contents();
@ob_end_clean();
return $buffer;
} else {
echo include('aplication/view/'.$view.'.php');
}
}