我试图查看我的模板,但没有显示我的视图,如果我将动作设置为空白,则显示视图

时间:2014-06-03 06:52:29

标签: codeigniter

我试图查看我的模板但没有显示我的视图,如果我将动作设置为空白然后它显示视图如果我设置控制器/功能它隐藏视图,它隐藏视图中的文本框和按钮,存在我正在使用的控制器和功能。什么可能是它的问题,任何身体可以帮助我。

我的控制员:

<?php

class post_job extends CI_Controller {

    function __construct() {
        parent::__construct();
        // Post New Job
        function create_new_job() {
            $this->data['page_heading'] = 'Post New Job';
            $this->data['heading'] = 'Post New Job';
            $this->load->model('post_job');
            $this->form_validation->set_rules('job_title', 'Job Title', 'trim|required|xss_clean');
            $this->form_validation->set_rules('job_desc', 'Job Description', 'trim|required|xss_clean');
            $this->form_validation->set_rules('job_type', 'Job Type', 'trim|required|xss_clean');
            $this->form_validation->set_rules('salary', 'Salary', 'trim|required|xss_clean');
            $this->form_validation->set_rules('location', 'Location', 'trim|required|xss_clean');
            if ($this->form_validation->run() == FALSE) {
                $this->data['content'] = 'post_job';
                $this->load->view('post_job', $this->data);
            } else {
                $this->post_job->create_new_account();
            }
        }
    }
}

?>

我的模特:     

class post_job extends CI_Model {

    public $job_table = 'job_post';

     function create_new_account() {

        $data = array(
            "job_title" => $this->input->post("job_title"),
            "job_description" => $this->input->post("job_desc"),
            "job_type" => $this->input->post("job_type"),
            "salary" => $this->input->post("salary"),
            "location" => $this->input->post("location"),    
        );
        $this->db->insert("job_post", $data);
    }

    function get_userType($user_id) {
        $this->db->select("id, type ")->from("user_type");
        return $this->db->get();
    }

}


?>

我的观看代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Post Job</title>

    <style type="text/css">

    ::selection{ background-color: #E13300; color: white; }
    ::moz-selection{ background-color: #E13300; color: white; }
    ::webkit-selection{ background-color: #E13300; color: white; }

    body {
        background-color: #fff;
        margin: 40px;
        font: 13px/20px normal Helvetica, Arial, sans-serif;
        color: #4F5155;
    }

    a {
        color: #003399;
        background-color: transparent;
        font-weight: normal;
    }

    h1 {
        color: #444;
        background-color: transparent;
        border-bottom: 1px solid #D0D0D0;
        font-size: 19px;
        font-weight: normal;
        margin: 0 0 14px 0;
        padding: 14px 15px 10px 15px;
    }

    code {
        font-family: Consolas, Monaco, Courier New, Courier, monospace;
        font-size: 12px;
        background-color: #f9f9f9;
        border: 1px solid #D0D0D0;
        color: #002166;
        display: block;
        margin: 14px 0 14px 0;
        padding: 12px 10px 12px 10px;
    }

    #body{
        margin: 0 15px 0 15px;
    }

    p.footer{
        text-align: right;
        font-size: 11px;
        border-top: 1px solid #D0D0D0;
        line-height: 32px;
        padding: 0 10px 0 10px;
        margin: 20px 0 0 0;
    }

    #container{
        margin: 10px;
        border: 1px solid #D0D0D0;
        -webkit-box-shadow: 0 0 8px #D0D0D0;
    }
    </style>
</head>
<body>

<div id="container">
    <h1>Post Job</h1>

    <div id="body">


                    <form method="post" action="<?php echo base_url('post_job/create_new_job'); ?>" id="JobForm">


                        <label >Job Category </label>
                            <input id="jobcat" name="job_cat" type="text"  />
                            <br>
                       <label>Job Description </label>
                            <input id="jobdesc" name="job_desc" type="text"  />
                            <br>
                       <label >Job Type </label>
                            <input id="jobtype" name="job_type" type="text"  />
                            <br>
                       <label>Salary </label>
                            <input id="salary" name="salary" type="text"  />
                            <br>
                       <label>Location </label>
                            <input id="location" name="location" type="text"  />
                            <br>

                        <label>Start Date </label>
                            <input id="startdate" name="start_date" type="text"  />
                            <br>                        
                       <label>End Date </label>
                            <input id="enddate" name="end_date" type="text"  />
                            <br>  

                            <input type="button" name="save" value="Post Job" />
                            <br>                      

                </form>
            </div>
        </div>

</div>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

你的控制器,

<?php

class post_job extends CI_Controller {

        // Post New Job
        function create_new_job() 
        {
            $data['page_heading'] = 'Post New Job';
            $data['heading'] = 'Post New Job';
            $this->load->model('post_job');
            $this->form_validation->set_rules('job_title', 'Job Title', 'trim|required|xss_clean');
            $this->form_validation->set_rules('job_desc', 'Job Description', 'trim|required|xss_clean');
            $this->form_validation->set_rules('job_type', 'Job Type', 'trim|required|xss_clean');
            $this->form_validation->set_rules('salary', 'Salary', 'trim|required|xss_clean');
            $this->form_validation->set_rules('location', 'Location', 'trim|required|xss_clean');
            if ($this->form_validation->run() == FALSE) {
                $data['content'] = 'post_job';
                $this->load->view('post_job', $data);
            } else {
                $this->post_job->create_new_account();
            }
        }
}

?>