![]() |
passing URI based variable and variable inside class - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10) +--- Thread: passing URI based variable and variable inside class (/showthread.php?tid=62195) |
passing URI based variable and variable inside class - jigapate - 06-18-2015 Hello, exampler URL,-- example.com/index.php/products/shoes/sandals/123 This will pass as like below. public function shoes($sandals, $id) { echo $sandals; echo $id; } But how do we pass another variable along with URI segments? example if i declare $var = 'test' in class then how to access that in method? Thanks, RE: passing URI based variable and variable inside class - Avenirer - 06-18-2015 To pass a variable (a property) between methods of a class, you define them before the constructor: public $var = 'test'; And inside the methods you can access and modify them with $this->var; RE: passing URI based variable and variable inside class - soonerdm - 07-02-2015 In the example above as URL is example.com/index.php/products/shoes/sandals/123 Is there a way to access the ID via a $_GET ??? example: <?=$_GET['sandals']?> would print 123 |