symfony retrieveByPermalink and tryPermalink
common symfony Peer class skeleton
<?php
class XxxPeer extends BaseXxxPeer
{
/**
* generate permalink and try uniqueness, if not it adds number
*
* @param string $text
* @return string
*/
public static function tryPermalink($text = false) {
if($text) {
$uri = myString::urilize($text);
$c = new Criteria;
$c->add(self::PERMALINK, $uri);
if(self::doCount($c) > 0) {
return $uri.'-'.(self::getCount()+1);
} else {
return $uri;
}
} else {
return 'kategorie-'.(self::getCount()+1);
}
}
/**
* return count of items
*
* @return int
*/
public static function getCount() {
return self::doCount(new Criteria());
}
/**
* retrieve object by permalink
*
* @param string $permalink
* @return object
*/
public static function retrieveByPermalink($permalink) {
$c = new Criteria();
$c->add(self::PERMALINK, $permalink);
return self::doSelectOne($c);
}
}
?>
podrizena classa
----------------
public function save($con = null) {
if($this->getPermalink() != myString::urilize($this->getName()))
$this->setPermalink(ItemPeer::tryPermalink($this->getName()));
$ret = parent::save($con);
return $ret;
}
Tagy:
php 57 řádků | 2008-02-04 20:33:38 | air.kadlec@seznam.cz