Guest User

Untitled

a guest
Jun 19th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. <?
  2. function categoriaSave($dados)
  3. {
  4. if(!isset($dados['nome']) || !preg_match('#\S+#', $dados['nome']))
  5. return array(
  6. 'retorno' => false,
  7. 'dados' => $dados,
  8. 'msg' => 'O campo \'Nome\' deve ser peenchido!');
  9.  
  10.  
  11. if(isset($dados['id']) && $dados['id'])
  12. $db = Doctrine::getTable('ProdutoCategoria')->find($dados['id']);
  13. else
  14. $db = new ProdutoCategoria();
  15.  
  16. unset($dados['id']);
  17. foreach($dados as $k=>$p)
  18. $db->$k = $p;
  19.  
  20. $db->save();
  21.  
  22. $retorno = array(
  23. 'retorno' => true,
  24. 'dados' => $db->toArray(),
  25. 'msg' => 'Categoria salva com sucesso!'
  26. );
  27.  
  28. return $retorno;
  29. }
  30.  
  31. ?>
Add Comment
Please, Sign In to add comment