Listing 13.12. | |
| ROZDZIAŁ: | 13. Zagadnienia dodatkowe dotyczące warstw M oraz V |
| TXT: | listing-13-12.txt |
public function insertIfNotExists($str)
{
$c = new Criteria();
$c->add(ProducentPeer::NAZWA, $str);
$obj = ProducentPeer::doSelectOne($c);
if (!$obj) {
$obj = new Producent();
$obj->setNazwa($str);
$obj->setSlug(string2slug($str));
$obj->save();
}
return $obj;
}