Created
September 30, 2014 20:24
-
-
Save tacone/3f8bb8c4e8e57ae42585 to your computer and use it in GitHub Desktop.
Rapyd scratchpad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function edit () | |
{ | |
$model = new Article(); | |
$form = new DataForm($model); //--> $form->model | |
$form->text('title'); | |
$form->text('author.name'); | |
$form->file('cover')->move('/uploads', 'cover{{$id}}'); | |
/* | |
$this->form->afterSave(function($form, $caller){ | |
if (!$caller->moveFile()) | |
{ | |
// rollback DB transaction | |
throw new FileUploadException('file could not be uploaded'); | |
} | |
}); | |
// nel caso ci fossero più file | |
$this->form->onRollback(function($form, $caller){ | |
$caller->rollbackUpload(); | |
}); | |
*/ | |
if (Request::method == 'POST') | |
{ | |
$data = Input::all(); | |
$data = array_dot($data); | |
foreach ( $data as $key => $value) | |
{ | |
$form->set($key, $value); // --> array_set($form->model, $key, $value); | |
} | |
if ($form->validate()) | |
{ | |
$form->save(); | |
/* | |
// begin transaction | |
try { | |
$this->model->save(); | |
foreach ($this->getRelations() as $submodel) | |
{ | |
$submodel->save(); | |
} | |
} catch ($exception) | |
{ | |
$this->rollback(); | |
} | |
// commit transaction | |
*/ | |
$form->redirect(); // to some page | |
} | |
} | |
View::make('edit', compact('form')); | |
} |
non credo, dicevo semplicemente che si possono usare lo stesso senza metterle nel dataform.
Se si tratta di aggiungere qualche metodo facciamolo pure.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
creano problemi?