Welcome Guest, Not a member yet? Register   Sign In
Setting up CodeIgniter to load system from composer package
#1

[eluser]dmyers[/eluser]
If anyone is interested in learning how to set up CodeIgniter so it uses the CodeIgniter Composer Package for it's system folder. I'll take the time to explain how it's done. I personally use CI 3 (dev) and it's a lot easier to type "composer update" to get the latest package instead of doing it all manually. I also added a loader method to load name spaced (composer vendor folder) packages and attach them to the CodeIgniter Instance so you can access them via "normal" CodeIgniter syntax.

Something like:
Code:
$this->load->object('dmyers\classes\search');

$this->search->run('lime=green');

Just reply to this thread and if there is enough interest I'll put something together.

DMyers
#2

[eluser]ivantcholakov[/eluser]
Code:
$this->load->object('dmyers\classes\search');
$this->load->object('ivan\classes\search');

?
#3

[eluser]dmyers[/eluser]
No problems. If that code example looks a little strange to you or you don't know what the back slashes are used for your probably not ready for PHP namespace or composer.
#4

[eluser]ivantcholakov[/eluser]
I am pointing at a problem - a property name conflict.
#5

[eluser]dmyers[/eluser]
Oh ya, I support adding a custom name just like CodeIgniter's Library Loader

Code:
$this->load->library('class_name', $config, 'object name')

https://ellislab.com/codeigniter/user-gu...oader.html

Code:
$this->load->object('dmyers\classes\search',[],'dmsearch');
$this->load->object('ivan\classes\search');

Since it's a convention already in the Manual and one CodeIgniter developers are familiar with I thought it was the best way to handle it.
#6

[eluser]ivantcholakov[/eluser]
OK, this would work.
#7

[eluser]dmyers[/eluser]
I can see there isn't much interest for this?
Personally, I am having a blast moving my libraries, helpers, models, etc into composer packages and just finished up a wrapper for monolog (which has ton's more features!)

Perhaps I'll try again in a few months...
#8

[eluser]Unknown[/eluser]
I'm definitely interested. I'm familiar with composer and have created a composer.json file outside of CodeIgniter that contains what I need.

Any best practices you have created for migrating to that within CodeIgniter are welcomed.
#9

[eluser]ivantcholakov[/eluser]
@dmyers

Does anything stop you to publish your work at GitHub?
#10

[eluser]dmyers[/eluser]
I was hoping there would be enough interest to do a video and such to show everyone how it works. My CI folder is installed via a composer package https://packagist.org/packages/ellislab/codeigniter and you need to setup composer.json.

Then switch up your index.php to look there. In addition I wanted to go over basics on setting up namespacing on libraries since I don't store most of my stuff in CI defacto folders anymore. I haven't made everything a composer package but where it "fits". In addition I wanted to also show for example how to use guzzle the composer package. I could set it up on github but it seems like it would be looked over without composer knowledge since the entire CI system would be missing and the folder structure would be "strange" to say the least.

Don -




Theme © iAndrew 2016 - Forum software by © MyBB