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

[已解决] url怎么传递变量

[复制链接]
发表于 2012-1-13 16:19:20 | 显示全部楼层 |阅读模式
<a id ="a1" href="<?php echo site_url('admin.php/back/left/id/1')?>" target="leftFrame"><div id = "ad1" class="ad" onmouseover="movead1()" onmouseout = "outad1()" ><div style="margin-top:30px"><font style="color:#488bd1;"><strong> 常用 </strong></font></div></div></a>
<div id = "ad2" class="ad" onmouseover="movead2()" onmouseout = "outad2()" onmousedown ="downad1()"><div style="margin-top:30px"><font style="color:#488bd1;"><strong> 常用 </strong></font></div></div>
模板中url是这样写的
我再控制器里这样写
        public function left()
        {
                $this ->Comm_model ->is_login();
                $id = $_GET['id'];
                echo $id;


                $this ->load ->view('left');
        }
然后就报错了
A PHP Error was encountered

Severity: Notice

Message: Undefined index: id

Filename: controllers/back.php

Line Number: 33,这是为什么啊?

<div id = "ad3" class="ad" onmouseover="movead3()" onmouseout = "outad3()" onmousedown ="downad1()"><div style="margin-top:30px"><font style="color:#488bd1;"><strong> 常用 </strong></font></div></div>
发表于 2012-1-13 17:22:13 | 显示全部楼层
get方式在url中应该是在问号'?'后,比如 http://domain.com/?page=1
在控制器里获取这个url中page的值的方式:
PHP复制代码
$this->input->get('page', TRUE);
复制代码
 楼主| 发表于 2012-1-13 17:29:55 | 显示全部楼层
这样子是不是要在congfig文件中设置

$config['enable_query_strings'] = true;
是不是 啊?
发表于 2012-1-13 17:55:29 | 显示全部楼层
色彩 发表于 2012-1-13 17:29
这样子是不是要在congfig文件中设置

$config['enable_query_strings'] = true;

不需要。
发表于 2012-1-13 17:56:32 | 显示全部楼层
你用的是 URL 分段传参,这个要参考手册:
http://codeigniter.org.cn/user_guide/general/controllers.html

本版积分规则