[SonataAdminBundle] « Call to a member function isGranted() on a non-object » après l'installation
Bonjour,
Bon je suis un peu perdu dans l'installation et la configuration de Sonata Admin Generator.
Je travaille sur un serveur debian. Symfony 2.1. Je précise que j'ai une bonne expérience de php en général.. Mais je découvre Symfony !
J'ai donc utilisé le composer.phar pour installer les bundles pré-requis :
Code:
1 2 3 4
| "friendsofsymfony/user-bundle": "*",
"sonata-project/admin-bundle": "*",
"sonata-project/user-bundle": "*",
"sonata-project/doctrine-orm-admin-bundle": "dev-master" |
j'ai ajouté ca dans mon config.yml :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| sonata_block:
default_contexts: [cms]
blocks:
sonata.admin.block.admin_list:
contexts: [admin]
sonata.block.service.text:
sonata.block.service.rss:
sonata_admin:
security:
handler: sonata.admin.security.handler.noop
title: Sonata Project
title_logo: /bundles/sonataadmin/logo_title.png
templates:
# default global templates
layout: SonataAdminBundle::standard_layout.html.twig
ajax: SonataAdminBundle::ajax_layout.html.twig
# default actions templates, should extend a global templates
list: SonataAdminBundle:CRUD:list.html.twig
show: SonataAdminBundle:CRUD:show.html.twig
edit: SonataAdminBundle:CRUD:edit.html.twig
dashboard:
blocks:
# display a dashboard block
- { position: left, type: sonata.admin.block.admin_list }
# Customize this part to add new block configuration
- { position: right, type: sonata.block.service.text, settings: { content: "<h2>Welcome to the Sonata Admin</h2> <p>This is a <code>sonata.block.service.text</code> from the Block Bundle, you can create and add new block in these area by configuring the <code>sonata_admin</code> section.</p> <br /> For instance, here a RSS feed parser (<code>sonata.block.service.rss</code>):"} }
groups:
sonata_page:
items:
- vince.cms.admin.article
default: ~
services:
vince.cms.admin.article:
class: Vince\CmsBundle\Admin\ArticleAdmin
tags:
- { name: vince.cms.admin, manager_type: orm, group: sonata_page, label: article }
arguments: [null, Vince\CmsBundle\Entity\Article, VinceCmsBundle:ArticleAdmin] |
J'ai une entité Article, très simple :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
| <?php
namespace Vince\CmsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Vince\CmsBundle\Entity\Article
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="Vince\CmsBundle\Entity\ArticleRepository")
*/
/**
* @ORM\Entity
* @ORM\Table(name="article")
*/
class Article
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private $user;
/**
* @var string $name
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var string $content
*
* @ORM\Column(name="content", type="text")
*/
private $content;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return Article
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set content
*
* @param string $content
* @return Article
*/
public function setContent($content)
{
$this->content = $content;
return $this;
}
/**
* Get content
*
* @return string
*/
public function getContent()
{
return $this->content;
}
/**
* Set user
*
* @param Vince\CmsBundle\Entity\User $user
* @return Article
*/
public function setUser(\Vince\CmsBundle\Entity\User $user = null)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* @return Vince\CmsBundle\Entity\User
*/
public function getUser()
{
return $this->user;
}
} |
j'ai fait le dossier Admin et ajouté un ArticleAdmin.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| <?php
namespace Vince\CmsBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Show\ShowMapper;
use Knp\Menu\ItemInterface as MenuItemInterface;
use Vince\CmsBundle\Entity\Article;
class ArticleAdmin extends Admin
{
/**
* @param \Sonata\AdminBundle\Show\ShowMapper $showMapper
*
* @return void
*/
protected function configureShowField(ShowMapper $showMapper)
{
$showMapper
->add('name')
->add('content')
;
}
/**
* @param \Sonata\AdminBundle\Form\FormMapper $formMapper
*
* @return void
*/
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->with('General')
->add('name')
->add('content')
->end()
;
}
/**
* @param \Sonata\AdminBundle\Datagrid\ListMapper $listMapper
*
* @return void
*/
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('name')
->add('content')
->add('_action', 'actions', array(
'actions' => array(
'view' => array(),
'edit' => array(),
'delete' => array(),
)
))
;
}
/**
* @param \Sonata\AdminBundle\Datagrid\DatagridMapper $datagridMapper
*
* @return void
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('name')
;
}
} |
Pour le moment, j'ai laissé l'accès a tout le monde, c'est juste pour tester, donc dans mon security.yml :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| jms_security_extra:
secure_all_services: false
expressions: true
security:
providers:
fos_userbundle:
id: fos_user.user_provider.username
encoders:
FOS\UserBundle\Model\UserInterface: sha512
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
logout: true
anonymous: true
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: IS_AUTHENTICATED_ANONYMOUSLY }
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN |
quand je vais sur la page
//app_dev.php/admin/dashboard
j'ai une erreur .. que je ne comprends vraiment pas :
Code:
Fatal error: Call to a member function isGranted() on a non-object in /home/******/sites/sf2/html/vendor/sonata-project/admin-bundle/Sonata/AdminBundle/Admin/Admin.php on line 2337
:calim2:
Franchement, Symfony a une très bonne réputation.. mais quand on tombe la dessus, dur de savoir ou chercher !
j'ai du oublier quelque chose quelque part.. pourtant pas faute d'avoir lu, relu et re relu les pages de documentation de sonata-project !
Une idée ??
Merci d'avance !