Pass Id getting from URL to many function in CodeIgniter |
02-26-2019, 09:18 AM
(This post was last modified: 02-27-2019, 03:51 AM by msz900. Edit Reason: Added Extra Description )
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.
public function Product($id) <-- $id included
public function Data() <-- $id not included Change it into: public function Data($id)
$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. (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.
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. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(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.
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. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
02-27-2019, 07:09 PM
(This post was last modified: 02-27-2019, 07:49 PM by msz900. Edit Reason: setting ) (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
Then you need to check the value of $id to see if it is 0.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |