Welcome Guest, Not a member yet? Register   Sign In
what is the way to calling a library in object oriented style?
#1

i need a tip on this. Since CI libraries are classes isn't there a way to just call a class with or without namespace :
$blogs = new Blog(); or
$blogs = new Site\Blog();
$blogs->method();
i mean this way instead of loading it first the CI way before using it.
Thanks
Be Simple Angel
Reply
#2

CodeIgniter does not have any autoloader like you're thinking of, so the only two ways to load the library are $this->load->library() or manually include the file. Once the file is loaded, you can do new Blog() all you want.

The other option is to use Composer and setup namespacing on the application directory, then it will work fine, also.
Reply
#3

Also, you can make your own autoloader and by using a hook you can activate it. Here is a very simple example https://github.com/ivantcholakov/codeign...toload.php
Reply
#4

Any autoloader can be loaded by setting $config['composer_autoload'] to a custom path in application/config/config.php. The path just has to point to a script which will register the autoloader (like Composer's vendor/autoload.php script). This is called before the Hooks class is loaded, so the only way to get an autoloader registered any earlier would be to register it in index.php or modify the CI code (or something odd like register it in a config file).
Reply




Theme © iAndrew 2016 - Forum software by © MyBB