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


PHP Slugify::activateRuleSet方法代码示例

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


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

示例1: customRules

 /**
  * @test
  * @dataProvider customRulesProvider
  */
 public function customRules($rule, $string, $result)
 {
     $slugify = new Slugify();
     $slugify->activateRuleSet($rule);
     $this->assertSame($result, $slugify->slugify($string));
 }
开发者ID:xing393939,项目名称:Laravel-5-Bootstrap-3-Starter-Site,代码行数:10,代码来源:SlugifyTest.php

示例2: addProductAction

 public function addProductAction(Request $request, $productID)
 {
     $slugify = new Slugify();
     $slugify->activateRuleSet('polish');
     $product = $this->getDoctrine()->getRepository('ShopBundle:Products')->findOneById($productID);
     if ($product) {
         $productToView = $product;
         $productForm = $this->makeProductForm($product);
     } else {
         $productToView = '';
         $productForm = $this->makeProductForm();
     }
     $categoriesToView = $this->getDoctrine()->getRepository('ShopBundle:ProductCategories')->findAll();
     $productForm->handleRequest($request);
     if ($productForm->isSubmitted() && $productForm->isValid()) {
         $productData = $productForm->getData();
         $productData->getName();
         try {
             $em = $this->getDoctrine()->getManager();
             $em->getConnection()->beginTransaction();
             if ($productData->getId() != '') {
                 $product = $this->getDoctrine()->getRepository('ShopBundle:Products')->findOneById($productData->getId());
             } else {
                 $product = new Products();
             }
             $product->setName($productData->getName())->setPrice($productData->getPrice())->setPermalink($productData->getPermalink())->setDescription($productData->getDescription())->setIsActive($productData->getIsActive())->setIsNew($productData->getIsNew());
             $categories = json_decode($productData->getCategoriesInput());
             if (is_array($categories) && !empty($categories)) {
                 foreach ($categories as $cat) {
                     $slug = $slugify->slugify($cat->name);
                     $catIsExistingCategory = $this->getDoctrine()->getRepository('ShopBundle:productCategories')->findOneByPermalink($slug);
                     if ($catIsExistingCategory) {
                         $this->addCategoryIfNotRelated($product, $catIsExistingCategory);
                         if ($catIsExistingCategory->getParent()) {
                             $parentCategory = $this->getDoctrine()->getRepository('ShopBundle:ProductCategories')->findOneByPermalink($catIsExistingCategory->getParent());
                             if ($parentCategory) {
                                 $this->addCategoryIfNotRelated($product, $parentCategory);
                                 if ($parentCategory->getParent()) {
                                     $product = $this->addParentsCategoriesToProduct($parentCategory, $product);
                                 }
                             }
                         }
                     } else {
                         $productCategory = (new ProductCategories())->setPermalink($slug)->setName($cat->name);
                         if ($cat->parent) {
                             $parentCategory = $this->getDoctrine()->getRepository('ShopBundle:ProductCategories')->findOneByPermalink($cat->parent);
                             if ($parentCategory) {
                                 $productCategory->setParent($parentCategory);
                                 $this->addCategoryIfNotRelated($product, $parentCategory);
                                 if ($parentCategory->getParent()) {
                                     $product = $this->addParentsCategoriesToProduct($parentCategory, $product);
                                 }
                             }
                         }
                         $this->addCategoryIfNotRelated($product, $productCategory);
                         $em->persist($productCategory);
                     }
                 }
             }
             $em->persist($product);
             $variants = json_decode($productData->getVariantsInput());
             if (is_array($variants) && !empty($variants)) {
                 foreach ($variants as $value) {
                     $slug = $slugify->slugify($value->name);
                     // if (strpos($value->value, ';')) {
                     $oneValue = explode(';', $value->value);
                     foreach ($oneValue as $val) {
                         if ($val != '') {
                             $checkIfProductVariantExist = $this->getDoctrine()->getRepository('ShopBundle:productVariants')->findOneBy(['slug' => $slug, 'value' => $val]);
                             if ($checkIfProductVariantExist) {
                                 $this->addVariantIfNotRelated($product, $checkIfProductVariantExist);
                                 $em->persist($checkIfProductVariantExist);
                             } else {
                                 $productVariant = (new ProductVariants())->setSlug($slug)->setName($value->name)->setValue($val)->setProduct($product);
                                 $em->persist($productVariant);
                             }
                         }
                     }
                     // }
                     // else {
                     //     $productVariant = (new ProductVariants)
                     //         ->setSlug($slug)
                     //         ->setName($value->name)
                     //         ->setValue($value->value);
                     //
                     //     $this->addVariantIfNotRelated($product, $productVariant);
                     //     $em->persist($productVariant);
                     // }
                 }
             }
             $properties = json_decode($productData->getPropertiesInput());
             if (is_array($properties) && !empty($properties)) {
                 foreach ($properties as $value) {
                     $slug = $slugify->slugify($value->name);
                     $checkIfProductPropertyExist = $this->getDoctrine()->getRepository('ShopBundle:productProperties')->findOneBy(['slug' => $slug, 'value' => $value->value]);
                     if ($checkIfProductPropertyExist) {
                         $this->addPropertyIfNotRelated($product, $checkIfProductPropertyExist);
                         $em->persist($checkIfProductPropertyExist);
                     } else {
                         $productProperties = (new ProductProperties())->setSlug($slug)->setName($value->name)->setValue($value->value)->setProduct($product);
//.........这里部分代码省略.........
开发者ID:szpakucjusz,项目名称:patrykShop,代码行数:101,代码来源:ProductsManagerController.php


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