本文整理汇总了PHP中Doctrine_Inflector::urlize方法的典型用法代码示例。如果您正苦于以下问题:PHP Doctrine_Inflector::urlize方法的具体用法?PHP Doctrine_Inflector::urlize怎么用?PHP Doctrine_Inflector::urlize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine_Inflector
的用法示例。
在下文中一共展示了Doctrine_Inflector::urlize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doctrine_urlize
/**
* Convert any passed string to a url friendly string. Converts 'My first blog post' to 'my-first-blog-post'
*
* @param string $text Text to urlize
* @return string $text Urlized text
*/
public static function doctrine_urlize($text)
{
// Transliteration
$text = self::transliterate($text);
// Urlize
return Doctrine_Inflector::urlize($text);
}
示例2: executeAddDocument
public function executeAddDocument(sfWebRequest $request)
{
$this->forward404Unless($request->isMethod(sfRequest::PUT));
$document = $request->getParameter('document');
$this->transaction = TransactionTable::getInstance()->find($document['transaction_id']);
$asso = AssoTable::getInstance()->find($document['asso_id']);
$this->checkAuthorisation($asso);
$form = new DocumentForm();
$files = $request->getFiles($form->getName());
$form->bind($request->getParameter($form->getName()), $files);
$infos = new finfo(FILEINFO_MIME_TYPE);
if ($form->isValid() and $infos->file($files['fichier']['tmp_name']) == 'application/pdf') {
$fichier = $this->transaction->getPrimaryKey() . '-' . date('Y-m-d-H-i-s') . '-' . Doctrine_Inflector::urlize($files['fichier']['name']);
if (substr($fichier, -4) == '-pdf') {
$fichier = substr($fichier, 0, -4);
}
$fichier .= '.pdf';
$form->setValue('fichier', $fichier);
$form->setValue('auteur', $this->getUser()->getGuardUser()->getPrimaryKey());
$doc = $form->save();
$path = $doc->getPath();
$dir = substr($path, 0, -strlen($fichier));
if (!is_dir($dir)) {
mkdir($dir);
}
move_uploaded_file($files['fichier']['tmp_name'], $path);
$this->redirect('transaction_show', $this->transaction);
} else {
$this->form = $form;
$this->setTemplate('show', $this->transaction);
$this->getResponse()->setSlot('current_asso', $asso);
}
}
示例3: sortString
public static function sortString($a, $b)
{
if ($a[0] == $b[0]) {
return 0;
}
return Doctrine_Inflector::urlize($a[0]) < Doctrine_Inflector::urlize($b[0]) ? -1 : 1;
}
示例4: postUp
public function postUp()
{
$records = Projects_Model_ProjectTable::getInstance()->findAll();
foreach ($records as $record) {
if (empty($record->name_slug)) {
$record->name_slug = Doctrine_Inflector::urlize($record->name);
$record->save();
}
}
}
示例5: testGermanCharactersAreConvertedCorrectly
public function testGermanCharactersAreConvertedCorrectly()
{
$this->assertEqual(Doctrine_Inflector::urlize('Ästhetik'), 'aesthetik');
$this->assertEqual(Doctrine_Inflector::urlize('ästhetisch'), 'aesthetisch');
$this->assertEqual(Doctrine_Inflector::urlize('Übung'), 'uebung');
$this->assertEqual(Doctrine_Inflector::urlize('über'), 'ueber');
$this->assertEqual(Doctrine_Inflector::urlize('Öl'), 'oel');
$this->assertEqual(Doctrine_Inflector::urlize('ölig'), 'oelig');
$this->assertEqual(Doctrine_Inflector::urlize('Fuß'), 'fuss');
}
示例6: postUp
public function postUp()
{
$table = Doctrine::getTable('News_Model_News');
$records = $table->findAll();
foreach ($records as $record) {
if (empty($record->title_slug)) {
$record->title_slug = Doctrine_Inflector::urlize($record->title);
$record->save();
}
}
}
示例7: generateFilename
/**
* Generates a non-random-filename
*
* @return string A non-random name to represent the current file
*/
public function generateFilename()
{
$filename = $this->getOriginalName();
$ext = filter_var($this->getExtension($this->getOriginalExtension()), FILTER_SANITIZE_URL);
$name = substr($this->getOriginalName(), 0, -strlen($ext));
$i = 1;
while (file_exists($this->getPath() . '/' . $filename)) {
$filename = Doctrine_Inflector::urlize($name) . '-' . $i . $ext;
$i++;
}
return $filename;
}
示例8: buildSlug
protected function buildSlug($record)
{
if (empty($this->_options['fields'])) {
$value = (string) $record;
} else {
$value = '';
foreach ($this->_options['fields'] as $field) {
$value = $record->{$field} . ' ';
}
}
return Doctrine_Inflector::urlize($value);
}
示例9: executeExport
public function executeExport(sfWebRequest $request)
{
$budget = $this->getRoute()->getObject();
$asso = $budget->getAsso();
$this->checkAuthorisation($budget->getAsso());
$categories = $budget->getCategoriesWithEntry()->execute();
$nom = $budget->getPrimaryKey() . '-' . date('Y-m-d-H-i-s') . '-' . Doctrine_Inflector::urlize($budget->getNom());
$html = $this->getPartial('budget/pdf', compact(array('categories', 'asso', 'budget', 'transactions')));
$doc = new Document();
$doc->setNom('Export du budget prévisionnel');
$doc->setAsso($asso);
$doc->setUser($this->getUser()->getGuardUser());
$doc->setTypeFromSlug('budgets');
$path = $doc->generatePDF('Budget Prévisionnel', $nom, $html);
header('Content-type: application/pdf');
readfile($path);
return sfView::NONE;
}
示例10: beforeSave
public function beforeSave($event)
{
if (true !== $this->update && $this->owner->slug) {
return parent::beforeSave($event);
}
if (!is_array($this->columns)) {
throw new CException('Columns have to be in array format.');
}
$availableColumns = array_keys($this->owner->tableSchema->columns);
// Try to guess the right columns
if (0 === count($this->columns)) {
$this->columns = array_intersect($this->_defaultColumnsToCheck, $availableColumns);
} else {
// Unknown columns on board?
foreach ($this->columns as $col) {
if (!in_array($col, $availableColumns)) {
throw new CException('Unable to build slug, column ' . $col . ' not found.');
}
}
}
// No columns to build a slug?
if (0 === count($this->columns)) {
throw new CException('You must define "columns" to your sluggable behavior.');
}
// Fetch values
$values = array();
foreach ($this->columns as $col) {
$values[] = $this->owner->{$col};
}
// First version of slug
$slug = $checkslug = Doctrine_Inflector::urlize(implode('-', $values));
// Check if slug has to be unique
if (false === $this->unique) {
$this->owner->slug = $slug;
} else {
$counter = 0;
while ($this->owner->findByAttributes(array('slug' => $checkslug))) {
$checkslug = sprintf('%s-%d', $slug, ++$counter);
}
$this->owner->slug = $counter > 0 ? $checkslug : $slug;
}
return parent::beforeSave($event);
}
示例11: _deleteRelatedData
private function _deleteRelatedData()
{
if (!$this->_contentTypeName) {
return;
}
$this->logSection('sympal', sprintf('...deleting data related to Sympal plugin ContentType "%s"', $this->_contentTypeName), null, 'COMMENT');
$lowerName = str_replace('-', '_', Doctrine_Inflector::urlize($this->_contentTypeName));
$slug = 'sample-' . $lowerName;
$contentType = Doctrine_Core::getTable('sfSympalContentType')->findOneByName($this->_contentTypeName);
// Find content lists related to this conten type
$q = Doctrine_Core::getTable('sfSympalContentList')->createQuery('c')->select('c.id, c.content_id')->from('sfSympalContentList c INDEXBY c.content_id')->where('c.content_type_id = ?', $contentType['id']);
$contentTypes = $q->fetchArray();
$contentIds = array_keys($contentTypes);
// Delete content records related to this content type
Doctrine_Core::getTable('sfSympalContent')->createQuery('c')->delete()->where('c.content_type_id = ?', $contentType['id'])->orWhereIn('c.id', $contentIds)->execute();
// Delete menu items related to this content type
Doctrine_Core::getTable('sfSympalMenuItem')->createQuery('m')->delete()->where('m.name = ?', array($this->_contentTypeName))->execute();
// Delete the content type record
Doctrine_Core::getTable('sfSympalContentType')->createQuery('t')->delete()->where('t.id = ?', $contentType['id'])->execute();
}
示例12: executeJustificatif
public function executeJustificatif(sfWebRequest $request)
{
$note_de_frais = $this->getRoute()->getObject();
$user = $this->getUser();
$asso = $note_de_frais->getAsso();
$this->checkAuthorisation($asso);
$html = $this->getPartial('noteDeFrais/pdf', compact(array('note_de_frais', 'asso', 'user')));
$nom = $note_de_frais->getPrimaryKey() . '-' . date('Y-m-d-H-i-s') . '-' . Doctrine_Inflector::urlize($note_de_frais->getNom());
$doc = new Document();
$doc->setNom('Attestation à signer');
$doc->setAsso($asso);
$doc->setUser($this->getUser()->getGuardUser());
$doc->transaction_id = $note_de_frais->transaction_id;
$doc->setTypeFromSlug('note_de_frais');
$path = $doc->generatePDF('Note de frais', $nom, $html);
$doc->save();
header('Content-type: application/pdf');
readfile($path);
return sfView::NONE;
}
示例13: _createDefaultContentTypeRecords
protected function _createDefaultContentTypeRecords(&$installVars)
{
$this->logSection('sympal', '...creating default Sympal ContentType records', null, 'COMMENT');
$lowerName = str_replace('-', '_', Doctrine_Inflector::urlize(str_replace('sfSympal', null, $this->_contentTypeName)));
$slug = 'sample_' . $lowerName;
$properties = array();
$contentType = $this->newContentType($this->_contentTypeName, $properties);
$installVars['contentType'] = $contentType;
$properties = array('slug' => $slug);
$content = $this->newContent($contentType, $properties);
$installVars['content'] = $content;
$properties = array('slug' => $lowerName, 'ContentType' => Doctrine_Core::getTable('sfSympalContentType')->findOneByName('ContentList'));
$contentList = $this->newContent('sfSympalContentList', $properties);
$contentList->trySettingTitleProperty('Sample ' . $contentType['label'] . ' List');
$contentList->getRecord()->setContentType($contentType);
$installVars['contentList'] = $contentList;
$properties = array('date_published' => new Doctrine_Expression('NOW()'), 'label' => str_replace('sfSympal', null, $this->_contentTypeName), 'RelatedContent' => $contentList);
$menuItem = $this->newMenuItem($this->_contentTypeName, $properties);
$installVars['menuItem'] = $menuItem;
$properties = array('body' => '<?php echo get_sympal_breadcrumbs($menuItem, $content) ?><h2><?php echo get_sympal_content_slot($content, \'title\') ?></h2><p><strong>Posted by <?php echo $content->CreatedBy->username ?> on <?php echo get_sympal_content_slot($content, \'date_published\') ?></strong></p><p><?php echo get_sympal_content_slot($content, \'body\') ?></p>');
}
示例14: urlize
/**
* Clean for usage in URLs
*
* @param $string
* @return string
*/
private function urlize($string)
{
return Doctrine_Inflector::urlize($string);
}
示例15: beforeSave
/**
* beforeSave
*
* @param CModelEvent $event
*
* @throws CException
* @access public
*/
public function beforeSave($event)
{
// Slug already created and no updated needed
if (true !== $this->update && !empty($this->getOwner()->{$this->slugColumn})) {
Yii::trace('Slug found - no update needed.', __CLASS__ . '::' . __FUNCTION__);
return parent::beforeSave($event);
}
$availableColumns = array_keys($this->getOwner()->tableSchema->columns);
// Try to guess the right columns
if (0 === count($this->columns)) {
$this->columns = array_intersect($this->_defaultColumnsToCheck, $availableColumns);
} else {
// Unknown columns on board?
foreach ($this->columns as $col) {
if (!in_array($col, $availableColumns)) {
if (false !== strpos($col, '.')) {
Yii::trace('Dependencies to related models found', __CLASS__);
list($model, $attribute) = explode('.', $col);
$externalColumns = array_keys($this->getOwner()->{$model}->tableSchema->columns);
if (!in_array($attribute, $externalColumns)) {
throw new CException("Model {$model} does not haz {$attribute}");
}
} else {
throw new CException('Unable to build slug, column ' . $col . ' not found.');
}
}
}
}
// No columns to build a slug?
if (0 === count($this->columns)) {
throw new CException('You must define "columns" to your sluggable behavior.');
}
// Fetch values
$values = array();
foreach ($this->columns as $col) {
if (false === strpos($col, '.')) {
$values[] = $this->getOwner()->{$col};
} else {
list($model, $attribute) = explode('.', $col);
$values[] = $this->getOwner()->{$model}->{$attribute};
}
}
// First version of slug
if (true === $this->useInflector) {
$slug = $checkslug = Doctrine_Inflector::urlize(implode('-', $values));
} else {
$slug = $checkslug = $this->simpleSlug(implode('-', $values));
}
// Check if slug has to be unique
if (false === $this->unique || !$this->getOwner()->getIsNewRecord() && $slug === $this->getOwner()->{$this->slugColumn}) {
Yii::trace('Non unique slug or slug already set', __CLASS__);
$this->getOwner()->{$this->slugColumn} = $slug;
} else {
$counter = 0;
while ($this->getOwner()->resetScope()->exists($this->slugColumn . '=:sluggable', array(':sluggable' => $checkslug))) {
Yii::trace("{$checkslug} found, iterating", __CLASS__);
$checkslug = sprintf('%s-%d', $slug, ++$counter);
}
$this->getOwner()->{$this->slugColumn} = $counter > 0 ? $checkslug : $slug;
}
return parent::beforeSave($event);
}