Problem passing data to my library from controller to run common functions |
[eluser]Unknown[/eluser]
Hello. I'm frustrated, and I'm sure it's me, because I'm new to CI. Help would be appreciated. Background: I have the infrastructure of the site and the various pages displaying nicely but I want to work on being DRY (Don't Repeat Yourself) so I want to start using my own library for common code. I have one controller for each view and I'm utilizing several templates that result in a different look, when desired. All is good but I now want to 'move' my controller specific, yet virtually identical, code to my library. Info I'm attempting to move from controller to library, for now: -Banner information (which banner to display, img location, id, link, etc.) -Other images that are used in header, but change depending on webpage or theme -May move meta information control from controller to db Problem: I'm attempting to pass two simple variables from the controller to my library. I use an array, as outlined in the users guide (& other sources), but I keep getting the following error: Message: Undefined variable: bannernumber Filename: libraries/banner.php Some controller code: Code: $params = array('bannernumber' => '2', 'badgenumber' => '1'); Some banner code: Code: class Banner { I know it's all me but I thought it would be wise to get another set of eyes on it to let me know what thing, or things, I need to rectify. Your suggestions are welcome. Thanks!
[eluser]MasterHernan[/eluser]
Your banner code: Code: class Banner { Fixed code: Code: class Banner { You were sending the array to the function and the function was receiving it as a private function variable, the object variable that you are looking for was not defined. You don't need to pass the $params again if you grab them in the __construct function and save it to the object since you are submitting it when you call the library. For more information check out: http://ellislab.com/codeigniter/user-gui...aries.html #Passing Parameters When Initializing Your Class |
Welcome Guest, Not a member yet? Register Sign In |