• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Slugify\Slugify类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Cocur\Slugify\Slugify的典型用法代码示例。如果您正苦于以下问题:PHP Slugify类的具体用法?PHP Slugify怎么用?PHP Slugify使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Slugify类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: bundlePost

 function bundlePost($request)
 {
     $data = $request->except(['subdoot']);
     $slugify = new Slugify();
     $data['slug'] = $slugify->slugify($request->get('title'), '_');
     if (strlen($data['slug']) > 46) {
         $data['slug'] = substr($data['slug'], 0, 46);
     }
     //6 character string for a permalink
     $permalink = $this->generateRandomString();
     //Make sure the permalink is unique
     while (Post::wherePermalink($permalink)->exists()) {
         $permalink = $this->generateRandomString();
     }
     $data['permalink'] = $permalink;
     //Insert the post into the db
     $post = new Post($data);
     //Attach the post to the user who created it
     //$post->user()->associate(\App\User::find(Auth::user()->id));
     // $user = \App\User::find(Auth::user()->id);
     // $subdoot = Subdoot::find($request->get('subdoot'));
     // $user->posts()->save($post);
     // $subdoot->posts()->save($post);
     $post->user()->associate(\App\User::find(Auth::user()->id));
     $post->save();
     $post->subdoot()->associate(Subdoot::find($request->get('subdoot')));
     $post->save();
     //Attach the post to the subdoot it was submitted in
     //$post->subdoot()->associate(Subdoot::find($request->get('subdoot')));
     return $post;
 }
开发者ID:nehero,项目名称:updoot,代码行数:31,代码来源:SubdootController.php


示例2: postSave

 /**
  * @param Picture $picture
  * @param array $data
  */
 protected function postSave(Picture $picture, array $data)
 {
     if (isset($data['meta']) && isset($data['meta']['filename'])) {
         $module = $this->getServiceContainer()->getModuleManager()->load('gossi/trixionary');
         $file = new File($module->getUploadPath()->append($data['meta']['filename']));
         $slugifier = new Slugify();
         $filename = sprintf('%s-%u.%s', $slugifier->slugify($picture->getAthlete()), $picture->getId(), $file->getExtension());
         $filepath = $module->getPicturesPath($picture->getSkill())->append($filename);
         $file->move($filepath);
         // create thumb folder
         $thumbspath = $module->getPicturesPath($picture->getSkill())->append('thumbs');
         $dir = new Directory($thumbspath);
         if (!$dir->exists()) {
             $dir->make();
         }
         // create thumb
         $imagine = new Imagine();
         $image = $imagine->open($filepath->toString());
         $max = max($image->getSize()->getWidth(), $image->getSize()->getHeight());
         $width = $image->getSize()->getWidth() / $max * self::THUMB_MAX_SIZE;
         $height = $image->getSize()->getHeight() / $max * self::THUMB_MAX_SIZE;
         $size = new Box($width, $height);
         $thumbpath = $thumbspath->append($filename);
         $image->thumbnail($size)->save($thumbpath->toString());
         // save to picture
         $picture->setUrl($module->getPicturesUrl($picture->getSkill()) . '/' . $filename);
         $picture->setThumbUrl($module->getPicturesUrl($picture->getSkill()) . '/thumbs/' . $filename);
         $picture->save();
     }
     // activity
     $user = $this->getServiceContainer()->getAuthManager()->getUser();
     $user->newActivity(array('verb' => $this->isNew ? Activity::VERB_UPLOAD : Activity::VERB_EDIT, 'object' => $picture, 'target' => $picture->getSkill()));
 }
开发者ID:gossi,项目名称:trixionary,代码行数:37,代码来源:PictureDomain.php


示例3: removeGroupAction

 /**
  * @Route("/remove/{id}", name="civix_front_superuser_group_remove")
  * @Method({"POST"})
  */
 public function removeGroupAction(Group $group)
 {
     $entityManager = $this->getDoctrine()->getManager();
     /** @var $csrfProvider \Symfony\Component\Form\Extension\Csrf\CsrfProvider\SessionCsrfProvider */
     $csrfProvider = $this->get('form.csrf_provider');
     if ($csrfProvider->isCsrfTokenValid('remove_group_' . $group->getId(), $this->getRequest()->get('_token'))) {
         $slugify = new Slugify();
         $groupName = $slugify->slugify($group->getOfficialName(), '');
         $mailgun = $this->get('civix_core.mailgun')->listremoveAction($groupName);
         if ($mailgun['http_response_code'] != 200) {
             $this->get('session')->getFlashBag()->add('error', 'Something went wrong removing the group from mailgun');
             return $this->redirect($this->generateUrl('civix_front_superuser_manage_groups'));
         }
         try {
             $this->get('civix_core.customer_manager')->removeCustomer($group);
         } catch (\Exception $e) {
             $this->get('session')->getFlashBag()->add('error', $e->getMessage());
             return $this->redirect($this->generateUrl('civix_front_superuser_manage_groups'));
         }
         $entityManager->getRepository('CivixCoreBundle:Group')->removeGroup($group);
         $this->get('session')->getFlashBag()->add('notice', 'Group was removed');
     } else {
         $this->get('session')->getFlashBag()->add('error', 'Something went wrong');
     }
     return $this->redirect($this->generateUrl('civix_front_superuser_manage_groups'));
 }
开发者ID:austinpapp,项目名称:push-notifications-temp,代码行数:30,代码来源:GroupController.php


示例4: postSavePage

 /**
  * Saved edited page; called via ajax
  * @return string
  */
 public function postSavePage()
 {
     $okay = true;
     $page_id = $_REQUEST['page_id'];
     $page_content = $_REQUEST['thedata'];
     if ($page_id > 0) {
         $page = Page::find($page_id);
     } else {
         $page = new Page();
         $slugify = new Slugify();
         $browser_title = $_REQUEST['browser_title'];
         $page->browser_title = $browser_title;
         $page->slug = $slugify->slugify($browser_title);
         // verify that the slug is not already in the db
         $results = Page::where('slug', '=', $slugify->slugify($browser_title))->get();
         foreach ($results as $result) {
             $okay = false;
         }
     }
     $page->page_content = $page_content;
     if ($okay) {
         $page->save();
         echo "OK";
     } else {
         echo "Browser Title already in use";
     }
 }
开发者ID:pagchen,项目名称:acme,代码行数:31,代码来源:AdminController.php


示例5: postSavePage

 /**
  * Saved edited page; called via ajax
  * @return string
  */
 public function postSavePage()
 {
     $okay = true;
     $page_id = $this->request->input('page_id');
     $page_content = $this->request->input('thedata');
     if ($page_id > 0) {
         $page = Page::find($page_id);
     } else {
         $page = new Page();
         $slugify = new Slugify();
         $browser_title = $this->request->input('broswer_title');
         $page->browser_title = $browser_title;
         $page->slug = $slugify->slugify($browser_title);
         $results = Page::where('slug', '=', $slugify->slugify($browser_title))->first();
         if ($results) {
             $okay = false;
         }
     }
     $page->page_content = $page_content;
     if ($okay) {
         $page->save();
         echo "OK";
     } else {
         echo "Browser title is already in use!";
     }
 }
开发者ID:tsawler,项目名称:phpunit-testing,代码行数:30,代码来源:AdminController.php


示例6: run

 /**
  * Automatically generated run method
  *
  * @param Request $request
  * @return Response
  */
 public function run(Request $request)
 {
     $file = $request->files->get('file');
     try {
         // validate: upload progress
         if (!$file->isValid()) {
             throw new FileException($file->getErrorMessage());
         }
         // validate: mime type
         $mimeTypes = ['image/png', 'image/jpeg', 'image/jpg', 'video/mp4', 'video/quicktime'];
         if (!in_array($file->getClientMimeType(), $mimeTypes)) {
             throw new FileException('No matching mime type');
         }
         // validate: extension
         $exts = ['png', 'jpg', 'jpeg', 'mp4', 'mov'];
         if (!in_array($file->getClientOriginalExtension(), $exts)) {
             throw new FileException('No matching extension');
         }
         // move uploaded file
         $slugifier = new Slugify();
         $fileName = $file->getClientOriginalName();
         $fileName = str_replace('.' . $file->getClientOriginalExtension(), '', $fileName);
         $fileName = $slugifier->slugify($fileName) . '.' . $file->getClientOriginalExtension();
         $file->move($this->getModule()->getUploadPath()->toString(), $fileName);
         $payload = new Success(['filename' => $fileName, 'url' => $this->getModule()->getUploadUrl() . '/' . urlencode($fileName)]);
     } catch (FileException $e) {
         $payload = new Failed(['error' => $e->getMessage()]);
     }
     return $this->responder->run($request, $payload);
 }
开发者ID:gossi,项目名称:trixionary,代码行数:36,代码来源:UploadAction.php


示例7: saveInvites

 public function saveInvites(array $emails, Group $group)
 {
     $emails = array_diff($emails, $this->entityManager->getRepository('CivixCoreBundle:DeferredInvites')->getEmails($group, $emails));
     $users = $this->entityManager->getRepository('CivixCoreBundle:User')->getUsersByEmails($emails);
     $usersEmails = array();
     $invites = array();
     $slugify = new Slugify();
     $groupName = $slugify->slugify($group->getOfficialName(), '');
     /** @var $user \Civix\CoreBundle\Entity\User */
     foreach ($users as $user) {
         if (!$group->getInvites()->contains($user) && !$group->getUsers()->contains($user)) {
             $this->mailgun->listaddmemberAction($groupName, $user->getEmail(), $user->getUsername());
             $user->addInvite($group);
             $invites[] = $user;
             $usersEmails[] = $user->getEmail();
         }
     }
     foreach (array_diff($emails, $usersEmails) as $email) {
         $deferredInvite = $this->createDeferredInvites($email, $group);
         $this->entityManager->persist($deferredInvite);
         $invites[] = $deferredInvite;
     }
     $this->entityManager->flush();
     return $invites;
 }
开发者ID:austinpapp,项目名称:push-notifications-temp,代码行数:25,代码来源:InviteSender.php


示例8: prePersist

 /**
  * @param \Acme\BasicCmsBundle\Document\Page $document
  * @return void
  */
 public function prePersist($document)
 {
     $slugify = new Slugify();
     $document->setSlug($slugify->slugify($document->getTitle()));
     $parent = $this->getModelManager()->find(null, '/cms/pages');
     $document->setParentDocument($parent);
 }
开发者ID:nikophil,项目名称:cmf-tests,代码行数:11,代码来源:PageAdmin.php


示例9: preSave

 protected function preSave(Object $object)
 {
     // set slug
     if (Text::create($object->getSlug())->isEmpty()) {
         $slugifier = new Slugify();
         $object->setSlug($slugifier->slugify($object->getTitle()));
     }
 }
开发者ID:gossi,项目名称:trixionary,代码行数:8,代码来源:ObjectDomain.php


示例10: preCreate

 /**
  * @param Group $model
  */
 protected function preCreate(Group $model)
 {
     if (Text::create($model->getSlug())->isEmpty()) {
         $title = $model->getTitle();
         $slugifier = new Slugify();
         $model->setSlug($slugifier->slugify($title));
     }
 }
开发者ID:gossi,项目名称:trixionary,代码行数:11,代码来源:GroupDomain.php


示例11: isUnique

 private function isUnique($data)
 {
     $rooms = $this->service->get('rooms');
     $name = htmlentities($data['name']);
     $slugify = new Slugify();
     $slug = $slugify->slugify($name);
     return !RoomFinder::set($rooms)->findOneBySlug($slug);
 }
开发者ID:nirgendswo,项目名称:justText,代码行数:8,代码来源:Room.php


示例12: invoke

 /**
  * @test
  * @covers Cocur\Slugify\Bridge\ZF2\SlugifyViewHelper::__invoke()
  */
 public function invoke()
 {
     $actual = 'Hällo Wörld';
     $expected = call_user_func($this->viewHelper, $actual);
     $this->assertEquals($expected, $this->slugify->slugify($actual));
     $expected = call_user_func($this->viewHelper, $actual, '_');
     $this->assertEquals($expected, $this->slugify->slugify($actual, '_'));
 }
开发者ID:ferch01991,项目名称:BlogLaravel,代码行数:12,代码来源:SlugifyViewHelperTest.php


示例13: getFilename

 /**
  * Return the filename which is passed or get from file
  * Filename is slug.
  *
  * @param UploadedFile $image
  * @param $filename
  * @return string
  */
 protected function getFilename(UploadedFile $image, $filename)
 {
     if (empty($filename)) {
         // use filename from uploaded file
         $filename = str_replace('.' . $image->getClientOriginalExtension(), '', $image->getClientOriginalName());
     }
     $slugify = new Slugify();
     return $slugify->slugify($filename);
 }
开发者ID:alcodo,项目名称:powerimage,代码行数:17,代码来源:CreateImage.php


示例14: titleToTags

 public function titleToTags($title)
 {
     $slugify = new Slugify();
     $stopwords = array('with', 'your', 'and', 'for', 'the', 'com', 'iii', 'fuer', 'mit', 'der', 'die', 'das', 'org', 'und', 'you', 'net', 'from');
     $tags = array_slice(array_unique(array_filter(explode(' ', $slugify->slugify($title, ' ')), function ($tag) use($stopwords) {
         return strlen($tag) >= 3 && !in_array($tag, $stopwords);
     })), 0, 10);
     return count($tags) == 0 ? 'untagged' : implode(',', $tags);
 }
开发者ID:emilyemorehouse,项目名称:readlater,代码行数:9,代码来源:TagTransformer.php


示例15: preSave

 /**
  * @param Skill $skill
  * @param mixed $data
  */
 protected function preSave(Skill $skill)
 {
     // set slug
     if (Text::create($skill->getSlug())->isEmpty()) {
         $name = str_replace('°', '', $skill->getName());
         $slugifier = new Slugify();
         $skill->setSlug($slugifier->slugify($name));
     }
     $this->isNew = $skill->isNew();
 }
开发者ID:gossi,项目名称:trixionary,代码行数:14,代码来源:SkillDomain.php


示例16: fill

 public function fill(array $attributes)
 {
     parent::fill($attributes);
     if (array_key_exists('slug', $attributes) === false && array_key_exists('title', $attributes)) {
         // create slug
         $slugify = new Slugify();
         $this->slug = $slugify->slugify($attributes['title']);
     }
     return $this;
 }
开发者ID:alcodo,项目名称:alpaca,代码行数:10,代码来源:Topic.php


示例17: UpdateArticle

 /**
  * Updates the specified Article.
  *
  * @param $id string
  * @param $title string
  * @param $content string
  * @return void
  */
 public static function UpdateArticle($id, $title, $content)
 {
     $slugify = new Slugify();
     $article = Article::find($id);
     $article->title = $title;
     $article->title_slug = $slugify->slugify($title);
     $article->content_markdown = $content;
     $article->content = Parsedown::instance()->setMarkupEscaped(true)->text($content);
     $article->save();
 }
开发者ID:drmyersii,项目名称:drm2.co,代码行数:18,代码来源:BlogService.php


示例18: __construct

 public function __construct($name = null)
 {
     parent::__construct();
     // Load Twig templates
     $loader = new \Twig_Loader_Filesystem(getcwd() . '/src/templates');
     $this->twig = new \Twig_Environment($loader, array('debug' => false));
     $this->twig->addExtension(new \Twig_Extension_Debug());
     // Custom filter for parsing the endpoint URI
     $this->twig->addFilter(new \Twig_SimpleFilter('parseUri', function ($baseUrl, $uriTemplate, $action) {
         // Check if the URI Template has parameters
         if (strpos($uriTemplate, '{?') !== false) {
             $resultString = preg_match('/{(.*?)}/', $uriTemplate, $matches);
             $resultString = $matches[1];
             if (strpos($resultString, '?') !== false) {
                 $resultString = str_replace(',', '&', substr($resultString, 1));
                 $urlParameters = explode('&', $resultString);
             }
             foreach ($urlParameters as $key => $urlParameter) {
                 $urlParameters[$key] = $urlParameter . '=' . $action['parameters'][$key]['example'];
             }
             $start = strpos($uriTemplate, '{');
             $convertedUrl = substr_replace($uriTemplate, '', $start);
             foreach ($urlParameters as $key => $urlParameter) {
                 $convertedUrl .= ($key === 0 ? '?' : '&') . $urlParameter;
             }
         } else {
             if (strpos($uriTemplate, '{') !== false) {
                 foreach ($action['parameters'] as $parameter) {
                     $convertedUrl = str_replace('{' . $parameter['name'] . '}', $parameter['example'], $uriTemplate);
                 }
             } else {
                 $convertedUrl = $uriTemplate;
             }
         }
         return $baseUrl . $convertedUrl;
     }));
     // Custom filter for parsing Markdown
     $this->twig->addFilter(new \Twig_SimpleFilter('markdown', function ($string) {
         return Markdown::defaultTransform($string);
     }));
     // Custom filter for creating a slug with an optional prefix/suffix
     $this->twig->addFilter(new \Twig_SimpleFilter('slugify', function ($string, $prefix = null, $suffix = null) {
         $slugify = new Slugify();
         return $slugify->slugify($prefix . $string . $suffix);
     }));
     // Custom filter for extracting keys from a multidimensional array
     $this->twig->addFilter(new \Twig_SimpleFilter('arrayFromKey', function ($array, $key) {
         $result = array();
         foreach ($array as $value) {
             $result[] = $value[$key];
         }
         return $result;
     }));
 }
开发者ID:pixelfusion,项目名称:api-blueprint-parser,代码行数:54,代码来源:BaseCommand.php


示例19: render

 /**
  * @param array $value
  * @param string $prefix
  * @param string $separator
  * @return string
  */
 public function render(array $value = null, $prefix = '', $separator = ' ')
 {
     $slugify = new Slugify();
     if ($value === null) {
         $value = $this->renderChildren();
     }
     $value = array_map(function ($item) use($prefix, $slugify) {
         return mb_strtolower($prefix . $slugify->slugify($item));
     }, $value);
     return implode($separator, $value);
 }
开发者ID:johannessteu,项目名称:JobButler,代码行数:17,代码来源:ImplodeViewHelper.php


示例20: setFile

 public function setFile($file)
 {
     $slugify = new Slugify();
     $upload_directory = $this->getUploadDirectory();
     $filename_without_extension = str_replace("." . $file->getClientOriginalExtension(), "", $file->getClientOriginalName());
     $filename = $slugify->slugify($filename_without_extension) . "." . $file->getClientOriginalExtension();
     $filepath = $upload_directory . "/" . $filename;
     $file = $file->move($upload_directory, $filename);
     $this->setFilename($filename);
     $this->setFilepath($filepath);
     return $this;
 }
开发者ID:bireme,项目名称:proethos2,代码行数:12,代码来源:Document.php



注:本文中的Cocur\Slugify\Slugify类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Codebird\Codebird类代码示例发布时间:2022-05-23
下一篇:
PHP sql\db_Skt类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap