include in library |
[eluser]presto5[/eluser]
I have a library, where i'm trying to use the other class: Code: //.../datepicker.php Code: //.../application/libraries/ig.php And when i'm trying to do: Code: $this->load->library('ig'); Fatal error: Class 'datepicker' not found Why???? I know for shure, that datepicker.php already included
[eluser]ejangi[/eluser]
Are you autoloading the URL helper? If not base_url() is probably returning null.
[eluser]presto5[/eluser]
I'm autoloading base_url(). I know for shure, that datepicker.php is included, because i put echo "Test"; in it and it appears before the error.
[eluser]tonanbarbarian[/eluser]
base_url will return just that, a URL so if you use it with an include it will be trying to do the following Code: include( base_url().'include/calendar/datepicker.php'); Code: include( 'http://www.example.com/include/calendar/datepicker.php'); BASEPATH or APPPATH
[eluser]presto5[/eluser]
base_url() is what i need. I said before, with file include everything is fine because i see the messsage. I don't know why it doesn't see the class.
[eluser]tonanbarbarian[/eluser]
try changing the include to a require. that way if it cannot find the file to include it will return a fatal error personally I feel the issue is using a url to access the file rather than a filepath, but I am sure you know best. another option would be to output the included files after you include your other file to see if it is really being included or not Code: include( base_url().'include/calendar/datepicker.php'); If it is not then the path to the file is wrong and again I would suggest using a file path not a URL
[eluser]esra[/eluser]
These should work: Code: $CI =& get_instance(); Code: $CI =& get_instance(); Code: $CI =& get_instance();
[eluser]Craig A Rodway[/eluser]
base_url() is not what you need. Using base_url() (which will result in http://example.com/include/calendar/datepicker.php for example) will not work to include that class if you want to use the PHP class object itself and its functions (eg. new datepicker();). When you include via http (as you are doing) you are simply including the output (if any) of that page as if you viewed it in a web browser - you do not get access to any of the classes or functions or PHP code (hence why you can't load the datepicker object). That is why you need to include it's filesystem path, as shown in esra's last example: Code: require(BASEPATH.'include/calendar/datepicker.php'); This is why you see your test echo, but cannot create a new object using $picker = new datepicker();.
[eluser]presto5[/eluser]
Thanks everybody!!! Especially, Craig. I'll know it for future. Because i thought there is no difference between http path and filesystem path. ANd this is the first time i faced with it. Thanks a lot!!! |
Welcome Guest, Not a member yet? Register Sign In |