开发者

Passing parameter to same page with CodeIgniter

I have a controller that loads a page view. The page is actually a template of sorts; when a user clicks a button, content is loaded into a div based on the parameters passed through the button link. All button URLs go to the same page, it just passes a parameter. So for example, I have a page controller and a page_view file. When I click on the login button I want to go to the same page, but just pass action="login". If I clicked on "see stats", then I would want to pass action="stats".

Without Codeigniter I know I can just set the URLs on the buttons to "?action=stats" or "thisurl?action=stats", and within the page itself I have code that checks 开发者_运维百科to see what the value of action is, and then generated content based on value.

How can I do this with the CodeIgniter framework?


You can call methods on a controller. So if you call a page like /your_controller/login, then it will call the login method in the controller and you can change the view to match that:

class Main extends CI_Controller {
    function Main(){
       parent::__construct();
       // called when /main is accessed
       // load your main view here
    }

    function login(){
      // called when /main/login is accessed
      // tweak view to match login view
    }
}

More info here: http://codeigniter.com/user_guide/general/urls.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜