0

How to pass the uri->segment values to other controller in codeigniter? I have this URL http://localhost/sample/controller_1/view/73 and I need to get the 73 and use it on another controller like controller_2. Obviously I could get it using end($this->uri->segments); in the controller_1. But I need to pass it on the controller_2. How could I accomplish this?

Also, how could I get the current url using different controller? In my controller_2, I need to get this url from controller 1. http://localhost/sample/controller_1/view/73

Sample code http://pastebin.com/T7J29qYF

  • write your url in a txt file and access that file in controller 2 and read data and use it.. this is 3rd time you asking same question... – Praveen Kumar Feb 27 '16 at 07:19
  • please add more specific code, like your MVC code – Yoshioka Feb 27 '16 at 07:22
  • @PraveenKumar, I can't write in static as $id is generated only. Yes because still no solution of my problem. I'm very sorry. – Vandolph Reyes Feb 27 '16 at 07:24
  • @Yoshioka, okay. Here is it. http://pastebin.com/T7J29qYF I try to make the example more easy. – Vandolph Reyes Feb 27 '16 at 07:31
  • then insert it in your database and access it on controller 2 with `id desc limit 1` – Praveen Kumar Feb 27 '16 at 07:43
  • Thanks @PraveenKumar, but I already tried it. It will not work as I need to view first the URL with $id before I insert it on the database. Basically, I will insert something on db using controller_2 with the contoller_1 $id. That's why I need to get first the $id before inserting. – Vandolph Reyes Feb 27 '16 at 07:47
  • what is the problem if you insert from controller1 ?? – Praveen Kumar Feb 27 '16 at 08:04
  • Controller 1 has a view while controller 2 doesn't not have. The controller 1 have functionality which is for controller 1 only. I created the controller 2 because I will use this functionality in other controllers. For example In my controller 1, 3, and 4. I will insert data using controller 2. The insertion is all the same and I want to follow the DRY, so that if I need to change something about the inserting. It will reflect to all of them. No need to change 1 by 1. I hope that make sense. – Vandolph Reyes Feb 27 '16 at 08:10

0 Answers0