本文整理汇总了PHP中yii\helpers\Inflector::slug方法的典型用法代码示例。如果您正苦于以下问题:PHP Inflector::slug方法的具体用法?PHP Inflector::slug怎么用?PHP Inflector::slug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\Inflector
的用法示例。
在下文中一共展示了Inflector::slug方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new Participant model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate($meeting_id)
{
$mtg = new Meeting();
$title = $mtg->getMeetingTitle($meeting_id);
$model = new Participant();
$model->meeting_id = $meeting_id;
$model->invited_by = Yii::$app->user->getId();
// load friends for auto complete field
$friends = Friend::getFriendList(Yii::$app->user->getId());
if ($model->load(Yii::$app->request->post())) {
if (!User::find()->where(['email' => $model->email])->exists()) {
// if email not already registered
// create new user with temporary username & password
$temp_email_arr[] = $model->email;
$model->username = Inflector::slug(implode('-', $temp_email_arr));
$model->password = Yii::$app->security->generateRandomString(12);
$model->participant_id = $model->addUser();
} else {
// add participant from user record
$usr = User::find()->where(['email' => $model->email])->one();
$model->participant_id = $usr->id;
}
// validate the form against model rules
if ($model->validate()) {
// all inputs are valid
$model->save();
return $this->redirect(['/meeting/view', 'id' => $meeting_id]);
} else {
// validation failed
return $this->render('create', ['model' => $model, 'title' => $title, 'friends' => $friends]);
}
} else {
return $this->render('create', ['model' => $model, 'title' => $title, 'friends' => $friends]);
}
}
示例2: init
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if (!$this->id) {
$this->id = Inflector::slug($this->label);
}
}
示例3: getDetailUrl
public function getDetailUrl($contextNavItemId = null)
{
if ($contextNavItemId) {
return \luya\helpers\Url::toModule($contextNavItemId, 'gallery/album/index', ['albumId' => $this->id, 'title' => \yii\helpers\Inflector::slug($this->title)]);
}
return \luya\helpers\Url::to('gallery/album/index', ['albumId' => $this->id, 'title' => \yii\helpers\Inflector::slug($this->title)]);
}
示例4: getDetailUrl
public function getDetailUrl($contextNavItemId = null)
{
if ($contextNavItemId) {
return \cms\helpers\Url::toMenuItem($contextNavItemId, 'news/default/detail', ['id' => $this->id, 'title' => \yii\helpers\Inflector::slug($this->title)]);
}
return \luya\helpers\Url::toManager('news/default/detail', ['id' => $this->id, 'title' => \yii\helpers\Inflector::slug($this->title)]);
}
示例5: up
public function up()
{
$this->addColumn('{{%topic}}', 'slug', Schema::TYPE_STRING . ' NOT NULL');
$topics = (new Query())->select('id, title')->from('{{%topic}}')->all();
foreach ($topics as $topic) {
$this->update('{{%topic}}', array('slug' => Inflector::slug($topic['title'])), 'id = :id', array(':id' => $topic['id']));
}
}
示例6: run
public function run()
{
$alias = Inflector::slug(Yii::$app->request->post('name'));
// if ($this->checkCommand->bindValues([':alias'=> $alias])->queryScalar() === false) {
//}
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return ['alias' => $alias, 'code' => 100];
}
示例7: testSlug
public function testSlug()
{
$data = ['Привет. Hello, Йии-- Framework !--- Как дела ? How it goes ?' => 'privet-hello-jii-framework-kak-dela-how-it-goes', 'this is a title' => 'this-is-a-title', 'недвижимость' => 'nedvizimost', 'áàâéèêíìîóòôúùûã' => 'aaaeeeiiiooouuua', 'Ναδάλης ṃỹṛèşưḿĕ' => 'nadales-myresume', 'E=mc²' => 'e-mc2', 'è¼å¥' => 'e14a'];
foreach ($data as $source => $expected) {
$this->assertEquals($expected, Inflector::slug($source));
}
//$this->assertEquals('this-is-my-text-', Inflector::slug('! this is my / text $## '));
}
示例8: slugify
private function slugify($slug)
{
if ($this->translit) {
return Inflector::slug(TransliteratorHelper::process($slug), '-', true);
} else {
return $this->slug($slug, '-', true);
}
}
示例9: renderHeadline
/**
* @inheritDoc
*/
protected function renderHeadline($block)
{
$content = $this->parseInline($block['content']);
$hash = Inflector::slug(strip_tags($content));
$hashLink = "<a href=\"#{$hash}\" name=\"{$hash}\" class=\"hashlink\">¶</a>";
$tag = 'h' . $block['level'];
return "<{$tag}>{$content} {$hashLink}</{$tag}>";
}
示例10: run
public function run()
{
$text = Yii::$app->request->post('text');
$translateText = Yii::$app->translate->translate($text, 'en');
$result[] = Inflector::slug($text);
$result[] = Inflector::slug($translateText);
return json_encode($result);
}
示例11: behaviors
/**
* @inheritdoc
*/
public function behaviors()
{
return [TimestampBehavior::className(), ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'alias'], 'value' => function ($event) {
return Inflector::slug($event->sender->title);
}], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_AFTER_FIND => 'body'], 'value' => function ($event) {
return HtmlPurifier::process(Markdown::process($event->sender->content, 'gfm'));
}]];
}
示例12: getFileName
static function getFileName($fileInstanse, $namePostfix = true)
{
$baseName = str_ireplace('.' . $fileInstanse->extension, '', $fileInstanse->name);
$fileName = StringHelper::truncate(Inflector::slug($baseName), 32, '');
if ($namePostfix || !$fileName) {
$fileName .= ($fileName ? '-' : '') . substr(uniqid(md5(rand()), true), 0, 10);
}
$fileName .= '.' . $fileInstanse->extension;
return $fileName;
}
示例13: validateName
public function validateName($attribute)
{
$name = Inflector::camelize(Inflector::slug($this->{$attribute}));
$label = $this->getAttributeLabel($attribute);
if (empty($name)) {
$this->addError($attribute, "'{$label}' должно состоять только из букв и цифр");
} else {
$this->{$attribute} = $name;
}
}
示例14: init
/**
* Initializes the module.
*/
public function init()
{
if (is_null($this->cronGroup)) {
$this->cronGroup = Inflector::slug(Yii::$app->id . '-' . Yii::getAlias('@app'));
} else {
$this->cronGroup = Inflector::slug($this->cronGroup);
}
$this->setComponents([$this->nameComponent => ['class' => 'gofmanaa\\crontask\\components\\Crontab', 'filename' => $this->fileName, 'directory' => $this->fileDir, 'crontabPath' => $this->crontabPath, 'cronGroup' => $this->cronGroup]]);
parent::init();
}
示例15: getFileName
public function getFileName()
{
if (!$this->_fileName) {
$fileName = substr(uniqid(md5(rand()), true), 0, 10);
$fileName .= '-' . Inflector::slug($this->file->baseName);
$fileName .= '.' . $this->file->extension;
$this->_fileName = $fileName;
}
return $this->_fileName;
}