symfony permalinks v2

smarter version of this

stáhnout snippet
zobrazení: SyntaxHighlighter | GeSHi | Holý text
schema.yml:
-----------
  artist:
    id:
    name: varchar(256)
    permalink: { type: varchar(256), index: true }
    description: longvarchar


Artist.php:
-----------
	public function setName($text) {
		// set name
		parent::setName($text);

		// set link
		$link = myString::urilize($text);

		$permalink = $link;
		$i = 0;

		while(ArtistPeer::retrieveByPermalink($permalink)) {
			$permalink = $link.'-'.++$i;
		}
		$this->setPermalink($permalink);
	}

ArtistPeer.php
--------------
	/**
	 * retrieve object by permalink
	 *
	 * @param string $permalink
	 * @return Artist
	 */
	public static function retrieveByPermalink($permalink) {
		$c = new Criteria();
		$c->add(self::PERMALINK, $permalink);

		return self::doSelectOne($c);
	}


Tagy:
php 41 řádků | 2008-05-26 15:55:30 | air.kadlec@seznam.cz