[eluser]Alface[/eluser]
I'm having a big problem here, I just can't find a way to auto validate the relational object of Videosalbum, Video object.. it just don't show me any erros, I think thats because I'm using $va->trans_status() than $va->save() as well..
Anyone can help me? Controller:
Code:
function videosalbum($id = NULL, $apagar = NULL){
$va = new Videosalbum($id);
$v = new Video();
if($apagar=='apagar' && $id != NULL){
$va->delete();
redirect(__CLASS__.'/listar/'.__FUNCTION__);
}
if($_POST){
$va->from_array($_POST);
$va->trans_start();
foreach($this->input->post('videos') as $vId => $video){
if($vId == 'novos'){
foreach($video as $novos){
$v->from_array($novos);
if($v->validate()){
// Se o campo estiver preenchido então salva
$v->id = NULL;
$v->save();
$va->save($v);
}
}
}else{
$v->from_array($video);
$v->id = $vId;
if($v->url){
// Se o campo estiver preenchido então salva
$v->save();
$va->save($v);
}else{
// Se o campo estiver em branco então apaga
$v->delete();
}
}