how to use database class in own library |
[eluser]GSV[/eluser]
Hello all. I need use database class in my own library. How to initialize it in library for accessing? Sorry for my english
[eluser]coolfactor[/eluser]
Have you read the User Guide? Same way you'd do it in your controller, except you first need to get an instance of your controller. Code: $CI =& get_instance(); Then just load and access your database library the same way you would elsewhere: Code: $CI->load->db();
[eluser]GSV[/eluser]
[quote author="coolfactor" date="1188207195"]Have you read the User Guide? Same way you'd do it in your controller, except you first need to get an instance of your controller. [/quote] Thank you for answer Yes, I have read. But I have little special task. controller: Code: $this->load->library('Search_Server'); library search_server.php : Code: class Search_Server extends HTML_AJAX_Server { file class.Search.php : Code: class Search { I need access to database class in my class Search() In this case I have error: PHP Fatal error: Call to undefined function get_instance() I think, it need some include.
[eluser]Rick Jolly[/eluser]
Well, you have access to the CI instance in the library so you could pass it into the Search class by reference. Maybe this will work?: Code: class Search_Server extends HTML_AJAX_Server { Code: class Search {
[eluser]coolfactor[/eluser]
By the time the Search class is loaded and instantiated, the get_instance() function should be available. I'm not sure why it's not working for him. From what I see, he's taking a rather complicated approach to the problem. GSV, please tell us what you want to do from the beginning, and maybe we can offer a different approach.
[eluser]GSV[/eluser]
I need connect AJAX (prefer PEAR::HTML_AJAX) to the project. Code: ini_set("include_path", ".:../:./pear:../pear:/var/www/html/rmb/pear:/var/www/html/rmb/system/application/libraries"); class SearchServer works fine, but when I make object in Search::Search(), I have the same error PHP Fatal error: Call to undefined function get_instance() |
Welcome Guest, Not a member yet? Register Sign In |