PHP code example of perfectneeds / seo-multi-lang-bundle
1. Go to this page and download the library: Download perfectneeds/seo-multi-lang-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
perfectneeds / seo-multi-lang-bundle example snippets
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new VM5\EntityTranslationsBundle\VM5EntityTranslationsBundle(),
new PN\SeoBundle\PNSeoBundle(),
new \PN\LocaleBundle\PNLocaleBundle(),
new \PN\ServiceBundle\PNServiceBundle(),
// ...
);
}
// src/PN/Bundle/SeoBundle/Entity/Seo.php
namespace PN\Bundle\SeoBundle\Entity;
use Doctrine\ORM\Mapping\UniqueConstraint;
use Doctrine\ORM\Mapping as ORM;
// DON'T forget the following use statement!!!
use PN\SeoBundle\Entity\Seo as BaseSeo;
use PN\SeoBundle\Model\SeoTrait;
/**
* Seo
* @ORM\HasLifecycleCallbacks
* @ORM\Table("seo", uniqueConstraints={@UniqueConstraint(name="slug_unique", columns={"slug", "seo_base_route_id", "deleted"})})
* @ORM\Entity(repositoryClass="PN\Bundle\SeoBundle\Repository\SeoRepository")
*/
class Seo extends BaseSeo {
use SeoTrait;
/**
* @ORM\OneToMany(targetEntity="PN\Bundle\SeoBundle\Entity\Translation\SeoTranslation", mappedBy="translatable", cascade={"ALL"}, orphanRemoval=true)
*/
protected $translations;
public function __construct()
{
parent::__construct();
// your own logic
}
// src/PN/Bundle/SeoBundle/Entity/Translation/SeoTranslation.php
namespace PN\Bundle\SeoBundle\Entity\Translation;
use Doctrine\ORM\Mapping as ORM;
// DON'T forget the following use statement!!!
use PN\SeoBundle\Entity\Translation\SeoTranslation as BaseSeoTranslation;
/**
* @ORM\Entity
* @ORM\Table(name="seo_translations")
*/
class SeoTranslation extends BaseSeoTranslation {
/**
* @var
* @ORM\Id
* @ORM\ManyToOne(targetEntity="PN\Bundle\SeoBundle\Entity\Seo", inversedBy="translations")
* @ORM\JoinColumn(name="translatable_id", referencedColumnName="id")
*/
protected $translatable;
}
// src/PN/Bundle/SeoBundle/Repository/SeoRepository.php
namespace PN\Bundle\SeoBundle\Repository;
use PN\SeoBundle\Repository\SeoRepository as BaseSeoRepository;
class SeoRepository extends BaseSeoRepository {
}
// src/PN/Bundle/SeoBundle/Entity/Seo.php
namespace PN\Bundle\SeoBundle\Entity;
use Doctrine\ORM\Mapping\UniqueConstraint;
use Doctrine\ORM\Mapping as ORM;
use PN\SeoBundle\Entity\Seo as BaseSeo;
use PN\SeoBundle\Model\SeoTrait;
/**
* Seo
* @ORM\HasLifecycleCallbacks
* @ORM\Table("seo", uniqueConstraints={@UniqueConstraint(name="slug_unique", columns={"slug", "seo_base_route_id"})})
* @ORM\Entity(repositoryClass="PN\Bundle\SeoBundle\Repository\SeoRepository")
*/
class Seo extends BaseSeo {
use SeoTrait;
/**
* @ORM\OneToOne(targetEntity="\PN\Bundle\CMSBundle\Entity\DynamicPage", mappedBy="seo")
*/
protected $dynamicPage;
// Add here your own relations
public function __construct()
{
parent::__construct();
// your own logic
}
namespace PN\Bundle\CMSBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use PN\ServiceBundle\Model\DateTimeTrait;
use VM5\EntityTranslationsBundle\Model\Translatable;
use PN\LocaleBundle\Model\LocaleTrait;
/**
* DynamicPage
*
* @ORM\HasLifecycleCallbacks
* @ORM\Table(name="dynamic_page")
* @ORM\Entity(repositoryClass="PN\Bundle\CMSBundle\Repository\DynamicPageRepository")
*/
class DynamicPage implements Translatable {
use DateTimeTrait,
LocaleTrait;
....
/**
* @ORM\OneToOne(targetEntity="\PN\Bundle\SeoBundle\Entity\Seo", inversedBy="dynamicPage", cascade={"persist", "remove" })
*/
protected $seo;
....
}
namespace PN\Bundle\CMSBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
// DON'T forget the following use statement!!!
use PN\SeoBundle\Form\SeoType;
class DynamicPageType extends AbstractType {
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('seo', SeoType::class)
......
;
}
.....
}
/**
* @Route("/{slug}", name="fe_dynamic_page_show", methods={"GET", "POST"})
*/
public function showAction(Request $request, $slug) {
$em = $this->getDoctrine()->getManager();
$entity = $this->get("fe_seo")->getSlug($request, $slug, new DynamicPage());
if ($entity instanceof RedirectResponse) {
return $entity;
}
if (!$entity) {
throw $this->createNotFoundException();
}
// your own logic
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.