Skip to content

Instantly share code, notes, and snippets.

@nateabele
Last active December 23, 2015 17:59
Show Gist options
  • Save nateabele/6672080 to your computer and use it in GitHub Desktop.
Save nateabele/6672080 to your computer and use it in GitHub Desktop.
Get the current user as an object
<?php
/** models/Users.php **/
use lithium\security\Auth;
class Users extends \lithium\data\Model {
// ...
public static function current($request = null) {
if ($request === false) {
return Auth::clear('default');
}
$data = $request ? Auth::check('default', $request) : Auth::check('default');
return $data ? static::create($data, array('exists' => true)) : null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment