【发布时间】:2015-11-23 10:11:21
【问题描述】:
我正在写一个CodeIgniter 3 应用程序。我的目标是有一个视图,它不断地(随着代码的进行)随着输出内容刷新。我在 stackoverflow 中阅读了一些答案,但我不确定该怎么做。
我有一个控制器,它在更新方法中呈现视图。
<?php
defined('BASEPATH') OR exit('No direct script access allowed!');
class Dataupdate extends MY_Controller {
function __construct() {
parent::__construct();
}
public function index() {
$this->render('dataupdate_list_view');
}
public function update() {
$this->render('dataupdate_update_view');
}
}
?>
这是“MY_Controller”类。
<?php
defined('BASEPATH') OR exit('No direct script access allowed!');
class MY_Controller extends CI_Controller {
protected $data = array();
function __construct() {
parent::__construct();
$this->data['page_title'] = 'Team Portal';
$this->data['before_head'] = '';
$this->data['before_body'] = '';
}
/**
* Render method is used to render a view using a template.
* The given template delivers the HTML header and footer.
* The view contains the actual page content.
*
* @param string $the_view The view to be rendered
* @param string $template The template to render the view
*/
protected function render($the_view = NULL, $template = 'master') {
if ($template == 'json' || $this->input->is_ajax_request()) {
header('Content-Type: application/json');
echo json_encode($this->data);
} else {
// Get current user from database
$this->load->model('user_model');
$user = $this->user_model->get_record_by_name($_SERVER['REMOTE_USER']);
// Data to pass to view
$this->data['the_view_content'] = (is_null($the_view)) ? '' : $this->load->view($the_view, $this->data, TRUE);
$this->data['user'] = $user;
// Load view with data
$this->load->view('templates/' . $template . '_view', $this->data);
}
}
}
?>
然后我有一个视图,它输出内容。
<div>
<!-- PAGE TITLE -->
<div class="page-title">
<h3>Daten Update</h3>
<div class="title_right">
</div>
</div>
<div class="clearfix"></div>
<!-- ALERTS -->
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2>Fehler<small>Kleiner Text</small></h2>
<div class="clearfix"></div>
</div>
<div class="x_content bs-example-popovers">
<div class="alert alert-danger alert-dismissible fade in" role="alert">
<strong>Strong text.</strong>What to do now?
</div>
</div>
</div>
</div>
</div>
<!-- CONTENT -->
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2>Neues Daten Update ausführen</h2>
<div class="clearfix"></div>
</div>
<div class="x_content">
<?php echo form_open('dataupdate/update'); ?>
<input type="text" name="test" />
<button>Ausführen</button>
<?php echo form_close(); ?>
</div>
</div>
</div>
</div>
</div>
这很好用。到目前为止。
现在,我尝试实现以下目标:
- 我点击“Ausführen”(执行)按钮,将表单提交到与此页面相同的 url
- 然后我想执行一个 php 脚本,它不断地向页面输出内容。不是一次所有内容,而是在输出到页面后添加输出。
我希望我说清楚了。
关于如何做到这一点的任何建议或教程?
【问题讨论】:
-
尝试添加一些你到现在为止写的代码,因为我的英语很差,不清楚你的需要
-
我投票结束这个问题作为题外话,因为建议看看Codeigniter Tutorial for Beginners
-
@Abdulla 感谢您提供教程链接。我很快浏览了这些视频,但我找不到我的问题的答案。也许我错过了,或者我一开始没有说清楚。
标签: php codeigniter codeigniter-3