PHP code example of perfectneeds / seo-single-lang-bundle
1. Go to this page and download the library: Download perfectneeds/seo-single-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-single-lang-bundle example snippets
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new PN\SeoBundle\PNSeoBundle(),
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"})})
* @ORM\Entity(repositoryClass="PN\Bundle\SeoBundle\Repository\SeoRepository")
*/
class Seo extends BaseSeo {
use SeoTrait;
public function __construct()
{
parent::__construct();
// your own logic
}
### Step 4: Create your SeoRepository class
You can use this `Repository` to add any custom methods
// 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;
/**
* DynamicPage
*
* @ORM\HasLifecycleCallbacks
* @ORM\Table(name="dynamic_page")
* @ORM\Entity(repositoryClass="PN\Bundle\CMSBundle\Repository\DynamicPageRepository")
*/
class DynamicPage {
use DateTimeTrait;
....
/**
* @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
}
// src/PN/Bundle/SeoBundle/Repository/SeoRepository.php
namespace PN\Bundle\SeoBundle\Repository;
use PN\SeoBundle\Repository\SeoRepository as BaseSeoRepository;
class SeoRepository extends BaseSeoRepository {
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.