First thing you need to do is install sentry using composer, as composer is now supported and comes with CI 3.1.
composer require cartalyst/sentry 2.0.* composer require illuminate/database 4.0.* composer require ircmaxell/password-compat 1.0.*
Then, enable composer based auto-loading in codeigniter from application/config/config.php. Since by default composer creates the vendor folder at the root we need to give the path to the auto-loader file.
$config['composer_autoload'] = 'vendor/autoload.php';
Also, you need to update application/config/database.php to use PDO driver and don’t forget to import the SQL onto your database to create the required tables. You will find the SQL dump at vendor/cartalyst/sentry/schema folder.
Now you are ready to use sentry, just add the following line at any controller you want to use the sentry object.
use Cartalyst\Sentry\Facades\CI\Sentry as Sentry;
A sample use-case can be –
<?php defined('BASEPATH') OR exit('No direct script access allowed');
use Cartalyst\Sentry\Facades\CI\Sentry as Sentry;
class Welcome extends MY_Controller {
public function signup()
{
$sentry = Sentry::createSentry();
$sentry->register(array(
'email' => 'faisal@mailinator.com',
'password' => 'abcdefg'
),true);
}
}
Leave a comment