• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can i pass params into a controllers __construct() function?


public function __construct($id=null){


The param that i pass in the uri is never picked up by the __construct function.


Please remember to place code within builtin CODE tags for better readability.

To accomplish your goal, ensure you're URI Class Library is loaded and you can do the following:

Note: code is untested.

public function __construct()
  // Replace segment (n)
  $id = $this->uri->segment(n);


Hope that helps.

And to answer your topic's question: No, you can't pass arguments to the controller's __construct() method. If you want to know more about it, have a look at codeigniter/core/CodeIgniter.php and the path of the request from the index.php through all other files until it reaches you controller. Then you should be able to answer your question by yourself Wink

PhilTem is correct.

But you can pass parameters through the constructor in your own libraries.
For models you need to create an intialization method and pass then in thrugh it.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.