public static function index()
 {
     // Haetaan kaikki henkilöt tietokannasta
     $people = Person::all();
     // Renderöidään views/people kansiossa sijaitseva tiedosto index.html muuttujan $people datalla
     View::make('User/index.html', array('people' => $people));
 }
示例#2
0
 public function testOptionsForAllPeople()
 {
     $options = array('count' => 1);
     self::createTestPerson();
     self::createTestPerson();
     $people = Person::all($options);
     $this->assertSame(1, count($people));
 }
 public function testInvalidOptionsErrorHandling()
 {
     try {
         $options = "count: 5";
         $people = Person::all($options);
     } catch (Util\Exception $e) {
         $expected = 'invalid_options_error';
         $this->assertSame($expected, $e->type);
         $this->assertTrue($e instanceof Util\Exception);
     }
 }
 public function index()
 {
     //		$this->load->view('welcome_message');
     $persons = Person::all();
     foreach ($persons as $person) {
         echo "Name: " . $person->name . '<br><br>';
         $telephones = $person->telephone;
         foreach ($telephones as $telephone) {
             echo $telephone->telephone_type->type . ': ' . $telephone->telephone . '<br>';
         }
         echo '<hr>';
     }
 }
示例#5
0
$tito->reload();
echo "{$tito->name} has " . count($tito->orders) . " orders for: " . join(', ', ActiveRecord\collect($tito->orders, 'item_name')) . "\n\n";
// get all orders placed by Tito
foreach (Order::find_all_by_person_id($tito->id) as $order) {
    echo "Order #{$order->id} for {$order->item_name} (\${$order->price} + \${$order->tax} tax) ordered by " . $order->person->name . "\n";
    if (count($order->payments) > 0) {
        // display each payment for this order
        foreach ($order->payments as $payment) {
            echo "  payment #{$payment->id} of \${$payment->amount} by " . $payment->person->name . "\n";
        }
    } else {
        echo "  no payments\n";
    }
    echo "\n";
}
// display summary of all payments made by Tito and Jax
$conditions = array('conditions' => array('id IN(?)', array($tito->id, $jax->id)), 'order' => 'name desc');
foreach (Person::all($conditions) as $person) {
    $n = count($person->payments);
    $total = array_sum(ActiveRecord\collect($person->payments, 'amount'));
    echo "{$person->name} made {$n} payments for a total of \${$total}\n\n";
}
// using order has_many people through payments with options
// array('people', 'through' => 'payments', 'select' => 'people.*, payments.amount', 'conditions' => 'payments.amount < 200'));
// this means our people in the loop below also has the payment information since it is part of an inner join
// we will only see 2 of the people instead of 3 because 1 of the payments is greater than 200
$order = Order::find($pokemon->id);
echo "Order #{$order->id} for {$order->item_name} (\${$order->price} + \${$order->tax} tax)\n";
foreach ($order->people as $person) {
    echo "  payment of \${$person->amount} by " . $person->name . "\n";
}
示例#6
0
 public function index()
 {
     $people = Person::all();
     return View::make('people.index', ['people' => $people]);
 }
$person->Firstname = "Kona";
$person->Age = "20";
$person->Sex = "F";
$creation = $person->Create();
// Update Person Info
$person->id = "4";
$person->Age = "32";
$saved = $person->Save();
// Find person
$person->id = "4";
$person->Find();
d($person->Firstname, "Person->Firstname");
d($person->Age, "Person->Age");
// Delete person
$person->id = "17";
$delete = $person->Delete();
// Get all persons
$persons = $person->all();
// Aggregates methods
d($person->max('age'), "Max person age");
d($person->min('age'), "Min person age");
d($person->sum('age'), "Sum persons age");
d($person->avg('age'), "Average persons age");
d($person->count('id'), "Count persons");
function d($v, $t)
{
    echo '<pre>';
    echo '<h1>' . $t . '</h1>';
    var_dump($v);
    echo '</pre>';
}
 /**
  * Display a listing of people
  *
  * @return Response
  */
 public function index()
 {
     $people = Person::all();
     return View::make('people.index', compact('people'));
 }
示例#9
0
文件: all.php 项目: javanile/schemadb
//
require_once '_common.php';
//
use Javanile\SchemaDB\Readable;
//
class Person extends Readable
{
    //
    public $id = self::PRIMARY_KEY;
    //
    public $name = "";
    public $surname = "";
    public $age = 0;
    public $address1 = 0;
    public $address2 = 0;
}
//
class Address extends Readable
{
    //
    public $id = self::PRIMARY_KEY;
    //
    public $name = "";
    public $latitude = 0;
    public $longitude = 0;
    public $city = "";
}
//
$Persons = Person::all(['name', 'address' => Address::join()]);
//
Person::dump($Persons);
示例#10
0
 function testUpdateOnCollection()
 {
     $person = new Person();
     $person->age = 23;
     $person->lessThan('age', 23)->update();
     $people = $person->find();
     $this->assertEquals(count($people), 4);
     $person = new Person();
     $person->age = 100;
     $person->all()->update();
     $people = $person->find();
     $this->assertEquals(count($people), 6);
 }
示例#11
0
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
    return view('welcome');
});
//Route::group(['prefix' => 'api/v1', 'middleware' => 'auth:api'], function () {
//    Route::post('/short', 'UrlMapperController@store');
//});
//
//Auth::guard('api')->user();
Route::get('/auth/login', function () {
    return "No tens Accés a l'API";
});
Route::group(['prefix' => 'api', 'middleware' => 'throttle:6,10'], function () {
    Route::get('people', function () {
        return Person::all();
    });
});
示例#12
0
<?php

include_once "person_class.php";
if (count($_POST) > 0) {
    $newkid = new Person();
    $newkid->first_name = $_POST["first_name"];
    $newkid->last_name = $_POST["last_name"];
    $newkid->city = $_POST["city"];
    $newkid->state = $_POST["state"];
    $newkid->zip = $_POST["zip"];
    $newkid->email = $_POST["email"];
    $newkid->save();
}
$people = Person::all();
?>
<h1>Look at all my people</h1>
<table border="1">
    <thead>
        <tr><th>First</th>
            <th>Last</th>
            <th>City</th>
            <th>State</th>
            <th>Zip</th>
            <th>Email</th>
            <th>Action</th></tr>
    </thead>
    <tbody>
        <?php 
foreach ($people as $person) {
    echo "<tr>\n";
    echo "\t<td>{$person[1]}</td>\n";