Exemple #1
0
 // Set up a current path resolver so the paginator can generate proper links
 Paginator::currentPathResolver(function () {
     return isset($_SERVER['REQUEST_URI']) ? strtok($_SERVER['REQUEST_URI'], '?') : '/';
 });
 // Set up a current page resolver
 Paginator::currentPageResolver(function ($pageName = 'page') {
     $page = isset($_REQUEST[$pageName]) ? $_REQUEST[$pageName] : 1;
     return $page;
 });
 $perPage = 5;
 // results per page
 $columns = ['*'];
 // (optional, defaults to *) array of columns to retrieve from database
 $pageName = 'page';
 // (optional, defaults to 'page') query string parameter name for the page number
 if (User::all()->count() <= $perPage) {
     exit("Need more than <strong>{$perPage}</strong> users in your <i>illuminate_non_laravel</i> database to see this work");
 }
 // Set $page (optional, defaults to null) to the current page;
 // if this is not set, the currentPageResolver will be used
 $page = isset($_REQUEST[$pageName]) ? $_REQUEST[$pageName] : null;
 // Query and paginate the results
 $results = User::orderBy('id')->paginate($perPage, $columns, $pageName, $page);
 // Display the table of users
 echo '<h1>Users</h1>';
 echo '<table>';
 foreach ($results as $user) {
     echo "<tr><td>User number {$user->id}</td></tr>";
 }
 echo '<table>' . "\n";
 // Render the Bootstrap framework compatible pagination html;
Exemple #2
0
 * Requires: illuminate/database
 *
 * @source https://github.com/illuminate/database
 */
$app = new \Slim\Slim();
$app->add(new \Zeuxisoo\Whoops\Provider\Slim\WhoopsMiddleware());
$app->get('/', function () {
    $capsule = new Capsule();
    $capsule->addConnection(['driver' => 'mysql', 'host' => 'localhost', 'database' => 'illuminate_non_laravel', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '']);
    // Set the event dispatcher used by Eloquent models... (optional)
    $capsule->setEventDispatcher(new Dispatcher(new Container()));
    // Set the cache manager instance used by connections... (optional)
    // $capsule->setCacheManager(...);
    // Make this Capsule instance available globally via static methods... (optional)
    $capsule->setAsGlobal();
    // Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
    $capsule->bootEloquent();
    // Use it
    echo '<pre>';
    $user = Capsule::table('users')->where('id', 1)->get();
    var_dump($user);
    $users = User::all();
    var_dump($users);
    // More examples and docs here: https://github.com/illuminate/database
});
$app->get('/encapsulated', function () {
    echo '<pre>';
    $users = UserEncapsulated::all();
    var_dump($users);
});
$app->run();