用户
 找回密码
 入住 CI 中国社区
搜索
查看: 3789|回复: 9
收起左侧

[HELP] [已附上代码]插入数据的时候,来不成功,URL很奇怪

[复制链接]
发表于 2009-10-21 00:00:11 | 显示全部楼层 |阅读模式
本帖最后由 garygay 于 2009-10-21 10:14 编辑

我的C是insert,方法是insertnews,

然后每次插入数据都不成功,url是

localhost/test/index.php/insert/insert/insertnews

每插入一次,URL就增加一次insert。

之前成功过,是因为载入类的大小写问题,后来以为是PHP5.3的原因,改了,还是这样。

请赐教!
发表于 2009-10-21 00:46:13 | 显示全部楼层
贴出代码,你肯定有地方写错了。
发表于 2009-10-21 08:25:04 | 显示全部楼层
会不会是相对路径的问题? 还是贴出代码来,大家帮你分析吧。
 楼主| 发表于 2009-10-21 09:41:44 | 显示全部楼层
好的 。我把代码都删了 重新写 ,如果不行的话 马上向各位汇报

这里氛围真好。
 楼主| 发表于 2009-10-21 10:16:20 | 显示全部楼层
PHP复制代码
 
//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';
                }
        }
               
?>
 
复制代码
PHP复制代码
 
//Model:insertmodel.php
<?php
        class InsertModel extends Model{
                function insertmodel(){
                        parent::Model();
                }
                function insert($data){
                        $this->db->insert('news',$data);
                }
        }
?>
 
复制代码
PHP复制代码
 
//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>
 
复制代码
发表于 2009-10-21 10:28:26 | 显示全部楼层
site_url('insert/insertnews')

评分

参与人数 1威望 +2 收起 理由
Hex + 2 我很赞同

查看全部评分

发表于 2009-10-21 10:30:42 | 显示全部楼层
呵呵,楼上回答正确,加分!
CI 里不能使用相对路径,必须用绝对路径。
 楼主| 发表于 2009-10-21 11:27:24 | 显示全部楼层
哇 哈哈 果然如此

高手指的是VIEW里面,action吧,那么用site_url,
$this->loadl->helper('url');
是在Contrller里面调用么
发表于 2009-10-21 11:32:28 | 显示全部楼层
只要在调用之前装载 URL helper 就可以了,这个和 include 一个道理。
 楼主| 发表于 2009-10-21 12:12:58 | 显示全部楼层
多谢 Hex

本版积分规则