pass a variable to a controller |
[eluser]Corbee[/eluser]
Hi, I'm a newbie and am experimenting with a walkthrough and am trying to pass a variable to another controller. how do I do that? here is my code. I wanted to pass the $name Code: <?php I tried passing it to the controller below and it didn't work Code: function pdcat($name) what do you think is the right way to pass the variable? Thanks
[eluser]Militis[/eluser]
First, welcome to the wonderful world of Codeigniter. Second, I'd like you to refer to this page of the user guide: http://ellislab.com/codeigniter/user-gui...elper.html More specifically, the anchor() section: Quote:Note: If you are building links that are internal to your application do not include the base URL (http://...). This will be added automatically from the information specified in your config file. Include only the URI segments you wish appended to the URL. So that line would look something like this: Code: echo anchor("products/pdcat/$id",$name); Now, I'm guessing when you tried this: Code: function pdcat($name) Code: echo anchor("products/pdcat/$id/$name",$name); Code: function pdcat($id, $name) The params passed to your function in the controller are the URI segments. In the case of your current code, $id. In the case of my modified version, $id and $name in that order. There are lots of other ways to do it, and some are probably better than others. The user guide was a great help to me while learning and later developing my first projects. It still is, in fact. For your convenience, here's a link to the Table of Contents.
[eluser]Corbee[/eluser]
It works, thank you very much!!! Also thanks for the links and the explanation. It made things much clear for me now than before.
[eluser]Mimi kesini[/eluser]
i have try the code but not working.. please help me.. i want to pass the variable to other file index... in my login controller $data = array(); $this->load->model('login_model'); $user = $data['Username']; echo anchor('edit_user',$user); in my user_edit controller function index($user) { echo $user; //$this->load->model('motools_model'); //$un = $user; //$data = array(); //$data = $this->motools_model->editUser($un); //$this->load->view('edit_user_view',$data); } they said: Missing argument 1 for edit_user::index() and Undefined variable: user please help me....
[eluser]Klain[/eluser]
[quote author="Mimi kesini" date="1292500575"]i have try the code but not working.. please help me.. i want to pass the variable to other file index... in my login controller $data = array(); $this->load->model('login_model'); $user = $data['Username']; echo anchor('edit_user',$user); in my user_edit controller function index($user) { echo $user; //$this->load->model('motools_model'); //$un = $user; //$data = array(); //$data = $this->motools_model->editUser($un); //$this->load->view('edit_user_view',$data); } they said: Missing argument 1 for edit_user::index() and Undefined variable: user please help me.... [/quote] login controller: echo anchor('edit_user/'.$user,"Edit user"); the url will be something like : xxx/index.php/edit_user/user_id |
Welcome Guest, Not a member yet? Register Sign In |