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')); | |
} |
Io le transazioni non le metterei in mezzo, tutto cio' che puo' essere gestito da framework e che è specifico per l'applicazione che stai realizzando è giusto che sia nei model o nel controller.. es.
https://github.com/zofe/rapyd-laravel/blob/master/src/models/Article.php#L42
o in questo caso qualcosa nel controller tipo..
DB::transaction(function() use ($form)
{
$form->save();
});
creano problemi?
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
Sto cercando di fare il quadro di come dovrebbe funzionare la cosa, c'è validazione, redirect, upload dei files, transazioni.
C'è altra roba base che mi sono dimenticato?