0
我想用CodeIgniter建立一個小博客,出於某種原因,我把表單數據庫條目0而不是字符串。我試圖手動通過控制器,它的工作原理。表單中有什麼問題?CodeIgniter把0而不是字符串值到數據庫
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
類site_model延伸CI_Model {
var $title = '';
var $content = '';
var $date = '';
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function get_records()
{
$query = $this->db->get('posts');
return $query->result();
}
function add_records($data) {
$this->db->insert('posts', $data);
return;
}
function updata_records($data) {
$this->db->where('postID', $id);
$this->db->updata('posts', $data);
}
function delede_roe() {
$this->db->where('postID', $this->uri->segment(3));
$this->db->delete('posts');
}
}
/*文件結束的welcome.php / /位置:./application/controllers/welcome.php */
表格頁面:
<div class="grid_11">
<h2>About</h2>
<?php echo form_open('site/creata'); ?>
<label for="title"> title </label>
<input type="text" name="title" id="title">
<label for="content"> content </label>
<input type="text" name="content" id="content">
<br>
<input type="submit" value="send">
<?php echo form_close(); ?>
</div>
的CONTROLER:
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
類網站的擴展是CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see http://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
$this->load->view('home');
}
function add_post() {
$this->load->view('add_post');
}
function creata() {
$data = array (
'title' => $this->input->post('title'),
'post' => $this->input->post('content')
);
$this->load->model('site_model');
$this->site_model->add_records($data);
}
}
/*文件結束的welcome.php / /地點:./application/ controllers/welcome.php */
感謝您的回覆。需要注意的是,腳本在localhost上運行良好,只有當我將其上傳到我的服務器時纔會出現問題。我檢查了數據庫和相同的設置。建議的修改也不能解決問題 – user3581731
你是否從'url'中刪除了'index.php'?它在服務器上正常工作嗎? –
是的,我添加了一個htaccess文件。一切正常,除了這個FORM – user3581731