PHP code example of ibrows / sonata-admin-annotation-bundle
1. Go to this page and download the library: Download ibrows/sonata-admin-annotation-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/ */
ibrows / sonata-admin-annotation-bundle example snippets
namespace YourApp\Admin;
use Ibrows\Bundle\SonataAdminAnnotationBundle\Admin\AbstractSonataAdminAnnotationAdmin;
abstract class AbstractAdmin extends AbstractSonataAdminAnnotationAdmin
{
}
namespace YourApp\Admin;
use Ibrows\Bundle\SonataAdminAnnotationBundle\Admin\SonataAdminAnnotationAllTrait;
use Sonata\AdminBundle\Admin\Admin;
abstract class AbstractAdmin extends Admin
{
use SonataAdminAnnotationAllTrait;
}
bash
$ php composer.phar update ibrows/sonata-admin-annotation-bundle
php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Ibrows\Bundle\SonataAdminAnnotationBundle\IbrowsSonataAdminAnnotationBundle($this),
);
}
php
namespace YourApp\Entity;
use Ibrows\Bundle\SonataAdminAnnotationBundle\Annotation as Sonata;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity
* @Sonata\Order\ListMapperAll
* @Sonata\Order\ShowMapperAll
* @Sonata\Order\FormMapperAll
*
* @Sonata\Order\ShowAndFormreorder(with="General", keys={"name"})
* @Sonata\Order\ShowAndFormreorder(keys={"taxRate"})
*
* @Sonata\AutoService()
*/
class Country
{
/**
* @var integer $id
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Sonata\ListMapper(identifier=true)
* @Sonata\Order\FormMapperExclude
* @Sonata\ShowMapper(with="General")
*/
protected $id;
/**
* @var string $name
* @ORM\Column(type="string")
* @Sonata\ShowMapper(with="General")
*/
protected $name;
/**
* @var float
* @ORM\Column(type="float", name="shipping_free_limit")
*/
protected $shippingFreeLimit;
/**
* @var float
* @ORM\Column(type="float", name="shipping_fixed_rate")
*/
protected $shippingFixedRate;
/**
* @var float
* @ORM\Column(type="float", name="tax_rate")
*/
protected $taxRate;
/**
* @ORM\ManyToMany(targetEntity="Article", inversedBy="countries")
* @ORM\JoinTable(name="article_country")
* @Sonata\Order\ListMapperExclude
* @Sonata\FormMapper(options={"
php
namespace YourApp\Admin;
use Ibrows\Bundle\SonataAdminAnnotationBundle\Reader\SonataAdminAnnotationReaderInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Show\ShowMapper;
abstract class AbstractAdmin extends Admin
{
/**
* @param ListMapper $listMapper
*/
protected function configureListFields(ListMapper $listMapper)
{
$this->getSonataAnnotationReader()->configureListFields($this->getClass(), $listMapper);
}
/**
* @param FormMapper $formMapper
*/
protected function configureFormFields(FormMapper $formMapper)
{
$this->getSonataAnnotationReader()->configureFormFields($this->getClass(), $formMapper);
}
/**
* @param ShowMapper $showMapper
*/
protected function configureShowFields(ShowMapper $showMapper)
{
$this->getSonataAnnotationReader()->configureShowFields($this->getClass(), $showMapper);
}
/**
* @param DatagridMapper $datagridMapper
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$this->getSonataAnnotationReader()->configureDatagridFilters($this->getClass(), $datagridMapper);
}
/**
* @return ContainerInterface
*/
protected function getContainer()
{
return $this->getConfigurationPool()->getContainer();
}
/**
* @return SonataAdminAnnotationReaderInterface
*/
protected function getSonataAnnotationReader()
{
return $this->getContainer()->get('ibrows_sonataannotation.reader');
}
}