garygay 发表于 2009-10-21 00:00:11

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

本帖最后由 garygay 于 2009-10-21 10:14 编辑

我的C是insert,方法是insertnews,

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

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

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

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

请赐教!

Hex 发表于 2009-10-21 00:46:13

贴出代码,你肯定有地方写错了。

yinzhili 发表于 2009-10-21 08:25:04

会不会是相对路径的问题? 还是贴出代码来,大家帮你分析吧。

garygay 发表于 2009-10-21 09:41:44

好的 。我把代码都删了 重新写 ,如果不行的话 马上向各位汇报

这里氛围真好。:victory:

garygay 发表于 2009-10-21 10:16:20


//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>

lamtin 发表于 2009-10-21 10:28:26

site_url('insert/insertnews')

Hex 发表于 2009-10-21 10:30:42

呵呵,楼上回答正确,加分!
CI 里不能使用相对路径,必须用绝对路径。

garygay 发表于 2009-10-21 11:27:24

哇 哈哈 果然如此

高手指的是VIEW里面,action吧,那么用site_url,
$this->loadl->helper('url');
是在Contrller里面调用么

Hex 发表于 2009-10-21 11:32:28

只要在调用之前装载 URL helper 就可以了,这个和 include 一个道理。

garygay 发表于 2009-10-21 12:12:58

多谢 Hex:kiss:
页: [1]
查看完整版本: [已附上代码]插入数据的时候,来不成功,URL很奇怪