Pass Id getting from URL to many function in CodeIgniter - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Pass Id getting from URL to many function in CodeIgniter (/showthread.php?tid=72899) |
Pass Id getting from URL to many function in CodeIgniter - msz900 - 02-26-2019 I am getting an ID from a url like: Code: <?php echo base_url();?>Product/product/<?php echo $product->id;?>" In my sidebar on the same function[view -> Product/product] I am getting it correctly. but when I click some other function in my sidebar the Id is not coming like: Code: public function Product($id) it is working on this page as expected, but when I jump to different function in my sidebar the id is not working because it is not getting it... like: Code: public function Data() What I want: How to get the Id which I pass above to all my sidebar functions. Edit: Currently I am passing the $id using URL like: PHP Code: <?php echo base_url();?>Product/product/<?php echo $product->id;?>" The above URL clearly shows that the $id will go to Product function which is available in PRODUCT controller. but there are also other functions in PRODUCT controller in which I want that $id. So, My Question here is: How to get that $id in my all PRODUCT controller functions. RE: Pass Id getting from URL to many function in CodeIgniter - jreklund - 02-26-2019 public function Product($id) <-- $id included public function Data() <-- $id not included Change it into: public function Data($id) RE: Pass Id getting from URL to many function in CodeIgniter - msz900 - 02-26-2019 (02-26-2019, 10:48 AM)jreklund Wrote: public function Product($id) <-- $id included Tried but its also not working.. RE: Pass Id getting from URL to many function in CodeIgniter - ciadmin - 02-26-2019 $this->product($id) will only have a value for $id if that method is called as part of servicing a request, Product/product/id. Calling it the way you do, from the request handling method Product/data, makes no sense. RE: Pass Id getting from URL to many function in CodeIgniter - msz900 - 02-26-2019 (02-26-2019, 07:19 PM)ciadmin Wrote: $this->product($id) will only have a value for $id if that method is called as part of servicing a request, Product/product/id. Yes Sir, I understand it, That's the reason I have posted the question so I can know that how to achieve the above requirements. As I want to show the id in all sidebar functions. RE: Pass Id getting from URL to many function in CodeIgniter - InsiteFX - 02-27-2019 Then you will need to pass the $id to all of your sidebar functions/methods. PHP Code: function one($id) Or you could assign the $id to your session data and check it in every function/method. RE: Pass Id getting from URL to many function in CodeIgniter - msz900 - 02-27-2019 (02-27-2019, 02:57 AM)InsiteFX Wrote: Then you will need to pass the $id to all of your sidebar functions/methods. Actually Sir I have already tried the value passing into another / all sidebar functions but the result is same, if I use the session or I will pass it into all the function the id is not flowing into the other functions. I am updating my question by adding more explanation, may be it will help all the users to understand it clearly. RE: Pass Id getting from URL to many function in CodeIgniter - InsiteFX - 02-27-2019 It has to work if your passing the id through the function call. Are you sure that you are receiving the id? PHP Code: class Product extends CI_Controller Now when ever you need the id in that controllers methods just call getId(); PHP Code: $id = $this->getId(); It should still work if your using sessions. RE: Pass Id getting from URL to many function in CodeIgniter - msz900 - 02-27-2019 (02-27-2019, 09:37 AM)InsiteFX Wrote: It has to work if your passing the id through the function call. Yes I am 200% sure that I am getting the Id but the Id is only visible in my function / view where I am sending it using the url: But it is not reflecting in other functions / views, because the $id variable is empty and does not contain any value and its throwing Argument Error : PHP Code: Type: ArgumentCountError RE: Pass Id getting from URL to many function in CodeIgniter - InsiteFX - 02-28-2019 Then you need to check the value of $id to see if it is 0. |