本文整理汇总了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));
}
示例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);
//.........这里部分代码省略.........