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

请教各位一个关于MATCHBOX的问题

[复制链接]
发表于 2008-2-15 10:36:15 | 显示全部楼层 |阅读模式
请教各位一个关于MATCHBOX的问题,试了一下MATCHBOX类库,按照说明安装正常,安装MATCHBOX后的URL变成以下的形式,比如:http://localhost/index.php/module_name/controller_name/show/16,,即控制器前面多了模块的名称,但发现在解析URL时,上面URL中的controller_name和function_name(即show)能正常解释出来。但show后面跟的参数16却仍然解释为show,即本应传递到控制器的show函数的参数应为'16',但却传了'show',请教各位同学是否还应在哪里设置一下。
发表于 2008-2-15 15:12:07 | 显示全部楼层
我这边一切正常。

刚开始我怀疑是由于index.php的关系(因为我这里去掉了index.php)。但后来我加入index.php后测试,仍然没有问题……

你把你的controller里的相关代码和你的目录结构贴一下吧?
 楼主| 发表于 2008-2-15 15:34:21 | 显示全部楼层
目录结构如下:
file:///c:/question.jpg
这是从网上DOWN的一个用CI来做的网上招聘系统的例子,我借用来试一下MATCHBOX,modules目录下的zp就是module_name
CONTROLLER里的代码如下:

class ZhaopinF extends Controller{
function ZhaopinF(){
  parent::Controller();
  $this->load->module_model("zp","zhaopinM");
  $this->load->module_model("zp","zhaopinMoreM");
  $this->load->module_model("zp","userM");
  $this->load->module_model("zp","zcM");
  $this->load->library('xajax');
  $this->xajax->registerFunction(array('check_name',$this,'check_name'));
  $this->xajax->registerFunction(array('check_birth',$this,'check_birth'));
  $this->xajax->registerFunction(array('check_zc',$this,'check_zc'));
  $this->xajax->registerFunction(array('check_phone',$this,'check_phone'));
  $this->xajax->registerFunction(array('check_school',$this,'check_school'));
  $this->xajax->registerFunction(array('check_zy',$this,'check_zy'));
  $this->xajax->registerFunction(array('check_year',$this,'check_year'));
  
  $this->xajax->processRequests();
}
function index($start=0){
  $conf['per_page']=20;
  $conf['total_rows']=$this->zhaopinM->totalRecordsByCondition("where is_show='1'");
  $conf['base_url']=site_url()."/zp/zhaopinF/index/";
  $conf['uri_segment']=3;
  $this->load->library('pagination',$conf);
  $temp['links']=$this->pagination->create_links();
  $res=$this->zhaopinM->getZpLimitCondition($conf['per_page'],$start,array('is_show'=>'1'));
  $temp['res']=$res;
  $temp['base_url']=base_url();
  $temp['title']="招聘信息页";
  $temp['total_rows']=$this->zhaopinM->totalRecordsByCondition("where is_show='1'");
  $temp['per_page']=$conf['per_page'];
  $this->load->view('zhaopinFV',$temp);
}
function show($id){
  var_dump($id); //这里死活输出'show',应该是‘16’
  $res_zp=$this->zhaopinM->getZhaopinById($id);
  $res=$this->zhaopinMoreM->getZhaopinMoreById($id);
  $temp['base_url']=base_url();
  $temp['res']=$res;
  $temp['title']="更多关于 ".$res_zp->zhiwei;
  $this->load->module_view('zp','zhaopinMoreV',$temp);
}

以下是index函数显示的视图,详细信息>>的URL是:http://localhost/index.php/zp/zhaopinF/show/16
file:///c:/question1.jpg
视图部分代码:
<div id="holder">
  <div id="content" style="width:800px; margin:auto;">
    <table width="100%" class="for_table_f">
      <tr style="background-color:#0099FF;">
        <td width="43%">招聘职位</td>
        <td width="6%">人数</td>
        <td width="33%">截止日期</td>
        <td width="18%">备注</td>
      </tr>
   <?php foreach($res as $record): ?>
      <tr>
        <td><?=$record->zhiwei?></td>
        <td style="text-align:center;"><?=$record->p_num?></td>
        <td><?=$record->end_date?></td>
        <td><?=anchor("zp/zhaopinF/show/".$record->id,"详细信息>>")?></td>
      </tr>
   <?php endforeach; ?>
    </table>
<div id="links" style="text-align:right; padding:5px;">每页 <?=$per_page?> 条记录 共有 <?=$total_rows?> 条记录 <?=$links?></div>
  </div>
</div>
 楼主| 发表于 2008-2-15 15:37:09 | 显示全部楼层
question.jpg

question1.jpg

上面的图看不见,重新帖一下.
发表于 2008-2-15 15:47:27 | 显示全部楼层
我还真看不出有啥问题……

index()里的$start能正确传递吗?
 楼主| 发表于 2008-2-15 15:59:07 | 显示全部楼层
我把整个例子打包上传.供大家一起学习.这个例子是金色的尘写的.我用来测试matchbox,改了一点点,解开后把webroot下的文件放在documentroot下即可以 zp.rar (1.12 MB, 下载次数: 18)
发表于 2008-2-15 16:04:50 | 显示全部楼层
PHP复制代码
function show($id){
  var_dump($id); //这里死活输出'show',应该是‘16’
复制代码

MATCHBOX我倒是没试用过,但是按照我以前用ThinkPHP开发时,使用这种URL,应该如下写
PHP复制代码
function show(){
  var_dump($_GET['id']);
}
复制代码
  1. http://localhost/index.php/module_name/controller_name/show/id/16
复制代码

或许你试试看行不行
发表于 2008-2-15 16:16:29 | 显示全部楼层
CI 应该会自动传递参数,不应该是楼上所说的那样。
发表于 2008-2-15 16:23:04 | 显示全部楼层
原帖由 Hex 于 2008-2-15 16:16 发表
CI 应该会自动传递参数,不应该是楼上所说的那样。

嗯,可能不行吧,上面那样写是用ThinkPHP时的
 楼主| 发表于 2008-2-15 16:54:03 | 显示全部楼层
如果按照CI典型的配置没有整合到MATCH的话,运行是正常的,整合MATCHBOX后,整个URL在CONTROLLER前多了一个MODULE_NAME,我想可能在某个地方没设对.

本版积分规则