Welcome Guest, Not a member yet? Register   Sign In
Object Programming with CodeIgniter
#4

Sounds like you came up with a pretty good solution in the end. Smile

I have become a huge fan of Composer. To handle the situations like yours, I would enable Composer in CodeIgniter's config file

Code:
$config['composer_autoload'] = TRUE;[/url]

Then, I would edit the composer.json file to create autoloading for my application as a whole. Sometimes, I will point this to the default 'application' folder. Other times, I would point this a separate folder. I guess it depends on what I think the app will need and my mood that day :) Assuming we're using the default application folder, I would modify the composer.json file like this:

[code]
"autoload": {
       "psr-4": {
           "App\\": "application/"
       }
   },

Then, I would make that User class, still located in application/libraries, to have a namespace of App\Libraries.

Code:
<?php namespace App\Libraries;

class User  {
   protected $model;

   public function __construct( App\Models\User_model $model)
   {
       $this->model = $model;
   }
}

Then, in your other classes all you have to do is create a new User object.

Code:
$user = new App\Libraries\User( $this->user_model );

Something like that anyway. I'm still revising my tasks to be easier for testing, but I believe that would all work. While I probably went overboard there, hopefully you see the main point of using Composer as an autoloader. Smile[/code]
Reply


Messages In This Thread
Object Programming with CodeIgniter - by _this - 04-27-2015, 11:48 PM
RE: Object Programming with CodeIgniter - by kilishan - 04-28-2015, 07:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB