如何使用Codeigniter 3刷新输出?

时间:2015-11-23 10:11:21

标签: php codeigniter codeigniter-3

我正在撰写Elemwise{real,no_inplace}.grad illegally returned an integer-valued variable. (Input index 0, dtype complex128) 3申请表。我的目标是拥有一个视图,它始终(随着代码的进行)刷新输出内容。我在stackoverflow中读了一些答案,但我不确定,怎么做。

我有一个控制器,它在更新方法中呈现视图。

CodeIgniter

>

这是“MY_Controller”类。

<?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');
    }
}

然后我有一个输出内容的视图。

<?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);
        }
    }
}

?>

这很好用。到目前为止。

现在,我尝试实现的目标如下:

  • 点击“Ausführen”(执行)按钮,将表单提交到与此页面相同的网址
  • 然后我想要一个php脚本来执行,它不断地向页面输出内容。并非所有内容都是一次性的,但会在输出到页面后添加输出。

我希望我能说清楚。

关于如何做的任何建议或教程?

1 个答案:

答案 0 :(得分:1)

您需要在'_self'

上调用->_display方法强制输出

例如,对于JSON输出,您将执行以下操作:

output class

加载视图时也是如此,如果你100%确定你不需要其他任何东西,你可以手动调用_display来获取输出;请务必在此之后致电退出,否则您将以重复的输出结束(一个来自您的手动通话,另一个来自自动通话)。

查看输出类的用户指南:http://www.codeigniter.com/user_guide/libraries/output.html