处理获取url在codeigniter [英] handling get urls in codeigniter

查看:144
本文介绍了处理获取url在codeigniter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在登录页面 login.php?e = 1 时创建一个消息: / login / code>。我会遇到的问题是,在codeigniter当我做 / login / e / 1 / codeigniter似乎认为 e 是一个函数,因此,因为它不存在,所以输出 404
我试着,在索引函数中抓取段像一个get请求,但是这不工作。

 如果在codeigniter中使用代码, > //他们是否尝试访问安全页面? 
if($ this-> uri-> segment(1)=='e'&& $ this-> uri-> segment(2)=='1'):
if($ this-> generic-> getOption('block-msg-out-enable')){
$ this-> msg = $ this-> generic-> getOption block-msg-out');
}
endif;


解决方案

=http://ellislab.com/codeigniter/user-guide/general/controllers.html#remapping =nofollow>链接。



c> c>

(或控制器中的任何其他声明的函数)。

  function _remap ,$ params){

if(method_exists($ this,$ method)){

return call_user_func_array(array($ this,$ method),$ params);

} else {

array_unshift($ params,$ method);
return call_user_func_array(array($ this,index),$ params);

}

}

//第一个评论看看这里

  function _remap($ method,$ params){//这是你的新指数();但它需要参数

if($ method =='e'){

echo $ params [0];

} else {

show_404();

}

}


I am trying to create a message that shows up when login.php?e=1 on the login page: /login/. The issue I am coming to have is that in codeigniter when I do /login/e/1/ codeigniter seems to think e is a function and thus, since it doesnt exist, outputs a 404. I am trying, in the index function to grab the segments like a get request, however this does not work. How can one do typical get requests that would be trivial outside of codeigniter, in codeigniter while staying true to the uri that codeigniter uses?

    // Are they attempting to access a secure page?
    if ($this->uri->segment(1) == 'e' && $this->uri->segment(2) == '1'):
        if ($this->generic->getOption('block-msg-out-enable')) {
            $this->msg = $this->generic->getOption('block-msg-out');
        }
    endif;

解决方案

there is nothing to show just hit this link.

If you are lazy then watch it here.

_remap function overrides index() (or any other declared function in a controller), in a way

function _remap($method, $params) {

    if (method_exists($this, $method)) {

        return call_user_func_array(array($this, $method), $params);

    } else {

        array_unshift($params, $method);
        return call_user_func_array(array($this, "index"), $params);

    }

}

//after 1st comment take a look here

function _remap($method, $params) { //this is "kind" of your new index(); but it takes parameters

    if ($method == 'e') {

        echo $params[0];

    } else {

        show_404();

    }

}

这篇关于处理获取url在codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆