Integration

Note: The database schema is located under vendor/cartalyst/sentry/schema/mysql.sql

Laravel 4

After you have installed the package, just follow the instructions.

Sentry has optional support for Laravel 4 and it comes bundled with a Service Provider and a Facade for easy integration.

After installing the package, open your Laravel config file app/config/app.php and add the following lines.

In the $providers array add the following service provider for this package.

  1. 'Cartalyst\Sentry\SentryServiceProvider',

In the $aliases array add the following facade for this package.

  1. 'Sentry' => 'Cartalyst\Sentry\Facades\Laravel\Sentry',

Migrations

  1. php artisan migrate --package=cartalyst/sentry

Configuration

After installing, you can publish the package configuration file into your application by running the following command:

  1. php artisan config:publish cartalyst/sentry

This will publish the config file to app/config/packages/cartalyst/sentry/config.php where you can modify the package configuration.

CodeIgniter 3.0-dev

After you have installed the package, just follow the instructions.

Visit application/config/config.php and right down the bottom, add the following:

  1. class_alias('Cartalyst\Sentry\Facades\CI\Sentry', 'Sentry');

This will allow you to use Sentry as normal in CodeIgniter and sets up dependencies required for Sentry to run smoothly within the CI environment.

Note:: You must be running your database using the PDO driver (though this would be recommended anyway). Configuration for a MySQL database running PDO could be as follows (in application/config/database.php):

  1. // Ensure the active group is the default config.
  2. // Sentry always runs off your application's default
  3. // database connection.
  4. $active_group = 'default';
  5. // Setup the default config
  6. $db['default'] = array(
  7. // PDO requires the host, dbname and charset are all specified in the "dsn",
  8. // so we'll go ahead and do these now.
  9. 'dsn' => 'mysql:host=localhost;dbname=cartalyst_sentry;charset=utf8;',
  10. 'hostname' => 'localhost',
  11. 'username' => 'root',
  12. 'password' => 'root',
  13. 'database' => '',
  14. 'dbdriver' => 'pdo',
  15. 'dbprefix' => '',
  16. 'pconnect' => TRUE,
  17. 'db_debug' => TRUE,
  18. 'cache_on' => FALSE,
  19. 'cachedir' => '',
  20. 'char_set' => 'utf8',
  21. 'dbcollat' => 'utf8_general_ci',
  22. 'swap_pre' => '',
  23. 'autoinit' => TRUE,
  24. 'encrypt' => FALSE,
  25. 'compress' => FALSE,
  26. 'stricton' => FALSE,
  27. 'failover' => array()
  28. );

FuelPHP 1.x

After you have installed the package, just follow the instructions.

You must put the following in app/bootstrap.php below Autoloader::register():

  1. // Enable composer based autoloading
  2. require APPPATH.'vendor/autoload.php';

Great! You now have composer working with FuelPHP.

Just one more step is involved now, right at the bottom of that same file, app/bootstrap.php, put the following:

  1. class_alias('Cartalyst\Sentry\Facades\FuelPHP\Sentry', 'Sentry');

This will mean you can use the FuelPHP Sentry facade as the class Sentry. Vòila! Sentry automatically works with your current database configuration, there is no further setup required.

Note:: Sentry will always run off the default database connection, so ensure this is working. We may look at adding support for alternate connections in the future however it is not implemented at this stage. Pull requests are welcome.

Native

  1. // Include the composer autoload file
  2. include_once "vendor/autoload.php";
  3. // Import the necessary classes
  4. use Illuminate\Database\Capsule\Manager as Capsule;
  5. // Create the Sentry alias
  6. class_alias('Cartalyst\Sentry\Facades\Native\Sentry', 'Sentry');
  7. // Create a new Database connection
  8. $capsule = new Capsule;
  9. $capsule->addConnection([
  10. 'driver' => 'mysql',
  11. 'host' => 'localhost',
  12. 'database' => 'database',
  13. 'username' => 'root',
  14. 'password' => '',
  15. 'charset' => 'utf8',
  16. 'collation' => 'utf8_unicode_ci',
  17. ]);
  18. $capsule->bootEloquent();

The integration is done and you can now use all the available methods, here’s an example:

  1. // Find a user using the user email address
  2. $user = Sentry::findUserByLogin('john.doe@example.com');