예제 #1
0
 public function testBasicFlow()
 {
     $source = [];
     $e = new Endpoint($source);
     assertSame($source, $e->toArray());
     $source = ['name' => 'Frank', 'surname' => 'Sinatra'];
     $e = new Endpoint($source);
     $e->string('name');
     $e->string('surname');
     $e->fromSource();
     $e->fromInput();
     $e->validate();
     $e->writeSource();
     assertSame($source, $e->toArray());
 }
예제 #2
0
 public function anyIndex()
 {
     // load the data
     $model = Article::findOrNew(1);
     // instantiate the form
     $form = new Endpoint($model);
     // define the fields
     $form->text('title')->rules('required|max:10');
     $form->text('author.firstname', 'Author\'s first name')->rules('required');
     $form->text('author.lastname');
     $form->textarea('detail.note');
     $form->textarea('body');
     $form->select('public')->options([0 => 'No', 1 => 'Yes']);
     // read the POST data, if any
     $form->populate();
     // write new data back to the model
     $form->writeSource();
     // if the form has been sent, and has no errors
     if ($form->submitted() && $form->validate()) {
         // we will save the data in the database
         $form->save();
     }
     // we just need to pass the $form instance to the view
     return $form->toArray();
 }