当前位置: 首页>>代码示例>>PHP>>正文


PHP Slugify::slugify方法代码示例

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


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

示例1: 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

示例2: search

 public function search($tags)
 {
     $searchUrl = self::CPASBIEN_BASE_URL . '/recherche/' . $this->slugifier->slugify($tags) . '.html';
     $dom = HtmlDomParser::file_get_html($searchUrl);
     $lignes0 = $dom->find('div[class=ligne0]');
     $lignes1 = $dom->find('div[class=ligne1]');
     $torrentsLigne0 = array();
     foreach ($lignes0 as $torrentLigne0) {
         array_push($torrentsLigne0, $this->parseHtmlToTorrent($torrentLigne0));
     }
     $torrentsLigne1 = array();
     foreach ($lignes1 as $torrentLigne1) {
         array_push($torrentsLigne1, $this->parseHtmlToTorrent($torrentLigne1));
     }
     //merge array to respect website order result
     $result = array();
     $index0 = $index1 = 0;
     for ($i = 0; $i < count($torrentsLigne0) + count($torrentsLigne1); $i++) {
         if ($i % 2 == 0) {
             array_push($result, $torrentsLigne0[$index0]);
             $index0++;
         } else {
             array_push($result, $torrentsLigne1[$index1]);
             $index1++;
         }
     }
     return $result;
 }
开发者ID:elpiafo3,项目名称:Torrent-Streamer,代码行数:28,代码来源:CPasBienExtractor.php

示例3: 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

示例4: 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

示例5: slugify

 /**
  * Slugify
  *
  * @param string $text
  * @return string
  */
 public function slugify($text)
 {
     $slugged = $this->slugify->slugify($text);
     $count = 1;
     $orig = $slugged;
     while (in_array($slugged, $this->used)) {
         $slugged = $orig . '-' . $count;
         $count++;
     }
     $this->used[] = $slugged;
     return $slugged;
 }
开发者ID:caseyamcl,项目名称:toc,代码行数:18,代码来源:UniqueSluggifier.php

示例6: getBaseLink

 /**
  * Returns a link for a file
  *
  * @param  File   $file
  * @return string Link
  */
 protected function getBaseLink(File $file)
 {
     $folder = $this->folderRepository->find($file->getFolderId());
     $beautifurl = explode('/', $folder->getUrl());
     $beautifurl = array_filter($beautifurl, function ($beautifurl) {
         return (bool) $beautifurl;
     });
     $beautifurl = array_map(function ($fragment) {
         return $this->slugifier->slugify($fragment);
     }, $beautifurl);
     $beautifurl[] = $file->getName();
     $beautifurl = implode(DIRECTORY_SEPARATOR, $beautifurl);
     return $beautifurl;
 }
开发者ID:kankje,项目名称:xi-filelib,代码行数:20,代码来源:BeautifurlLinker.php

示例7: 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

示例8: 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

示例9: slugifyHonorsSeparatorArgument

 /**
  * @test
  * @covers Cocur\Slugify\Slugify::__construct()
  * @covers Cocur\Slugify\Slugify::slugify()
  */
 public function slugifyHonorsSeparatorArgument()
 {
     $actual = 'file name';
     $expected = 'file__name';
     $this->slugify = new Slugify(['separator' => 'dummy']);
     $this->assertEquals($expected, $this->slugify->slugify($actual, '__'));
 }
开发者ID:xing393939,项目名称:Laravel-5-Bootstrap-3-Starter-Site,代码行数:12,代码来源:SlugifyTest.php

示例10: 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

示例11: 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

示例12: doNotConvertToLowercase

 /**
  * @test
  * @covers Cocur\Slugify\Slugify::__construct()
  * @covers Cocur\Slugify\Slugify::slugify()
  */
 public function doNotConvertToLowercase()
 {
     $actual = 'File Name';
     $expected = 'File-Name';
     $this->slugify = new Slugify(['lowercase' => false]);
     $this->assertEquals($expected, $this->slugify->slugify($actual));
 }
开发者ID:marcelocustodio,项目名称:slugify,代码行数:12,代码来源:SlugifyTest.php

示例13: 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

示例14: 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

示例15: 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


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