[solved]Turn a php class into CI library? |
[eluser]zimco[/eluser]
Yes, i read the manual, but I keep messing this up and my brain is fried. What am i doing wrong? Here's the class i am trying to make into a library i can use: Code: <?php Here's my controller Code: function myXml($scanDataFile) { I keep getting errors like: Undefined property: ...::$xmlObj Missing argument 1
[eluser]Shay Falador[/eluser]
You are doing this wrong. The line: Code: $xmlObj = new Xmltoarray($xml_data); This line: Code: $this->load->library('XmlToArray'); In order to create the object named xmlObj in the $this you should do one of the following: 1) Instead of: Code: $this->load->library('XmlToArray'); Code: $this->load->library('XmlToArray','xmlObj'); Code: $xmlObj = new Xmltoarray($xml_data); Code: $this->xmlObj = new Xmltoarray($xml_data);
[eluser]zimco[/eluser]
Thanks for the reply and explanations. So, i changed my controller as you suggested: Code: function myXml($scanDataFile) { Now i get back the following errors all related to the php class/Library. Did i do something wrong in setting up the library for use with CI? Quote:A PHP Error was encountered
[eluser]Shay Falador[/eluser]
Well I was wrong and you were doing what I said wrong too Code: function myXml($scanDataFile) { You should consider using REQUIRE_ONCE and calling it normally because you may want more than once..
[eluser]zimco[/eluser]
D'oh Chalk it up to flatlining friday brain cells! With your help and re-reading manual, i discovered that i have to send any parameters to a library as an array. So, by tweaking these lines: Code: $params = array('xml' => $xml_data); It sends the xml data to the library. Of course, i then have errors like array to string conversion to work out, but thanks for all your help. Maybe monday will be better day for my brain.... |
Welcome Guest, Not a member yet? Register Sign In |