[已附上代码]插入数据的时候,来不成功,URL很奇怪
本帖最后由 garygay 于 2009-10-21 10:14 编辑我的C是insert,方法是insertnews,
然后每次插入数据都不成功,url是
localhost/test/index.php/insert/insert/insertnews
每插入一次,URL就增加一次insert。
之前成功过,是因为载入类的大小写问题,后来以为是PHP5.3的原因,改了,还是这样。
请赐教! 贴出代码,你肯定有地方写错了。 会不会是相对路径的问题? 还是贴出代码来,大家帮你分析吧。 好的 。我把代码都删了 重新写 ,如果不行的话 马上向各位汇报
这里氛围真好。:victory:
//Controller:insert.php
<?php
class Insert extends Controller{
function insert (){
parent::Controller();
$this->load->database();
}
function index(){
$this->load->view('insertnewsviews');
}
function insertnews(){
$data=array('title'=>$_POST['title'],'content'=>$_POST['content'],'time'=>time());
$this->load->Model('InsertModel');
$this->InsertModel->insert($data);
echo 'ok';
}
}
?>
//Model:insertmodel.php
<?php
class InsertModel extends Model{
function insertmodel(){
parent::Model();
}
function insert($data){
$this->db->insert('news',$data);
}
}
?>
//View:insertnewsviews.php
<html>
<head>
<meta http-equiv='content' content='text/html;charset=utf-8'/>
</head>
<body>
<form action='insert/insertnews' method='post'>
title<input type='text' name='title'/><br/>
content<input type='text' name='content'><br/>
<input type='submit' value='ADD'/>
</form>
</body>
</html>
site_url('insert/insertnews') 呵呵,楼上回答正确,加分!
CI 里不能使用相对路径,必须用绝对路径。 哇 哈哈 果然如此
高手指的是VIEW里面,action吧,那么用site_url,
$this->loadl->helper('url');
是在Contrller里面调用么 只要在调用之前装载 URL helper 就可以了,这个和 include 一个道理。 多谢 Hex:kiss:
页:
[1]