1

我已经在网上搜索过这个,但仍然没有任何进展。我只是想向同一个 URL 提交一个表单,但它只是说“加载页面错误”,并且控制台显示“加载资源失败:服务器响应状态为 500(内部服务器错误)”。我已经独立测试了控制器代码,没有错误。

我在网上找到的是设置表单属性“data-ajax=false”,但这只会导致另一个问题:提交表单后页面完全空白。

以下是代码:

查看(省略了页眉和页脚,仅加载了一些包装器和 js 和 css 文件):

<?php if (validation_errors()): ?>
<p><?php echo validation_errors(); ?></p>
<?php endif; ?>
<form id="lecture" action="" method="POST">
    <ul data-role="listview" data-inset="true">
        <li data-role="fieldcontain">
            <label for="title">Title</label>
            <input type="text" name="title" id="title" value="<?php if ($new) echo set_value('title'); else echo $lecture->title; ?>" data-clear-btn="true">
        </li>
        <li data-role="fieldcontain">
            <label for="guests">Guests</label>
            <input type="text" name="guests" id="guests" value="<?php if ($new) echo set_value('guests'); else echo $lecture->guests; ?>" data-clear-btn="true">
        </li>
        <li data-role="fieldcontain">
            <label for="place">Place</label>
            <input type="text" name="place" id="place" value="<?php if ($new) echo set_value('place'); else echo $lecture->place; ?>" data-clear-btn="true">
        </li>
        <li data-role="fieldcontain">
            <label for="date">Date</label>
            <input type="text" name="date" id="date" value="<?php if ($new) echo set_value('date'); else echo $lecture->date; ?>" data-clear-btn="true" data-role="datebox" data-options='{"mode":"datebox", "useNewStyle":true, "useFocus":true}'>
        </li>
        <li data-role="fieldcontain">
            <label for="time">Time</label>
            <input type="text" name="time" id="time" value="<?php if ($new) echo set_value('time'); else echo $lecture->time; ?>" data-clear-btn="true" data-role="datebox" data-options='{"mode":"timebox", "useNewStyle":true, "useFocus":true}'>
        </li>
        <li data-role="fieldcontain">
            <label for="introduction">Introduction</label>
            <textarea cols="40" rows="8" name="introduction" id="introduction"><?php if ($new) echo set_value('introduction'); else echo $lecture->introduction; ?></textarea>
        </li>
        <li data-role="fieldcontain">
            <label for="status">Status</label>
            <select name="status" id="status" data-role="slider">
                <option value="0">Off</option>
                <option value="1">On</option>
            </select>
        </li>
        <li class="ui-body ui-body-b">
            <fieldset class="ui-grid-a">
                    <div class="ui-block-a"><button type="button" data-theme="d" data-rel="back">Cancel</button></div>
                    <div class="ui-block-b"><button type="submit" data-theme="a">Submit</button></div>
            </fieldset>
        </li>
    </ul>
</form>

控制器:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Admin extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->load->model('Lectures_model');
        $this->load->library('form_validation');
    }

    public function index()
    {
        $lectures = $this->Lectures_model->get_all_lectures();
        $data['lectures'] = $lectures;
        $this->load->view('header', array('title' => 'Lectures Management'));
        $this->load->view('admin', $data);
        $this->load->view('footer');
    }

    public function add_lecture()
    {
        $data_header['title'] = 'New Lecture';
        $data_header['extra_css'] = array('jqm-datebox.min.css');
        $data_footer['extra_js'] = array('jqm-datebox.core.min.js', 'jqm-datebox.mode.datebox.min.js', 'jquery.mobile.datebox.i18n.zh-CN.utf8.js');
        $data['new'] = TRUE;
        echo $this->load->view('header', $data_header, TRUE);
        if ($this->form_validation->run('lecture') == FALSE) {
            echo $this->load->view('admin_lecture', $data, TRUE);
        } else {
            $new_lecture = array(
                'title' => $this->input->post('title'),
                'guests' => $this->input->post('guests'),
                'place' => $this->input->post('place'),
                'datetime' => $this->input->post('date') . ' ' . $this->input->post('time'),
                'status' => $this->input->post('status'),
                'introduction' => $this->input->post('introduction')
            );
            $this->Lectures_model->insert_lecture($new_lecture);
            $this->session->set_flashdata('notification', 'Successfully Adding a lecture!');
            echo "Okay";
            // $this->load->view('admin_lecture', array('lecture' => $new_lecture));
        }
        echo $this->load->view('footer', $data_footer, TRUE);
    }

    public function edit_lecture($lecture_id)
    {
        $lecture = $this->Lectures_model->get_lecture($lecture_id);
        $datetime_format = 'Y-m-d H:i:s';
        $datetime = DateTime::createFromFormat($datetime_format, $lecture->datetime);
        $lecture->date = $datetime->format('Y-m-d');
        $lecture->time = $datetime->format('H:i');
        $data_header['title'] = $lecture->title;
        $data_header['extra_css'] = array('jqm-datebox.min.css');
        $data_footer['extra_js'] = array('jqm-datebox.core.min.js', 'jqm-datebox.mode.datebox.min.js', 'jquery.mobile.datebox.i18n.zh-CN.utf8.js', 'status_flip.js');
        $data['lecture'] = $lecture;
        $data['new'] = FALSE;
        // $output = $this->load->view('header', $data_header, TRUE);
        $this->load->view('header', $data_header);
        if ($this->form_validation->run('lecture') == FALSE) {
            // $output .= $this->load->view('admin_lecture', $data, TRUE); 
            $this->load->view('admin_lecture', $data); 
        } else {
            $new_lecture = array(
                'title' => $this->input->post('title'),
                'guests' => $this->input->post('guests'),
                'place' => $this->input->post('place'),
                'datetime' => $this->input->post('date') . ' ' . $this->input->post('time'),
                'status' => $this->input->post('status'),
                'introduction' => $this->input->post('introduction')
            );
            $this->Lectures_model->update_lecture($lecture_id, $new_lecture);
            $this->session->set_flashdata('notification', 'Successfully Editing a lecture!');
            // $this->load->view('admin_lecture', array('lecture' => $new_lecture));
        }
        // $output .= $this->load->view('footer', $data_footer, TRUE);
        $this->load->view('footer', $data_footer);
        // $this->ouput->set_output($output);
    }

}

/* End of file admin.php */
/* Location: ./application/controllers/admin.php */

我试过$this->output->set_output()and echo,但仍然是“加载页面错误”。

我正在使用 CodeIgniter 2.1.4、jQuery 2.0.3 和 jQueryMobile 1.3.2。

4

0 回答 0