Skip to content

Instantly share code, notes, and snippets.

@tristanbes
Last active October 7, 2015 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tristanbes/3188331 to your computer and use it in GitHub Desktop.
Save tristanbes/3188331 to your computer and use it in GitHub Desktop.
<?php
namespace AwesomeNamespace\AwesomeBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
/**
* Profile Admin
*/
class ProfileAdmin extends Admin
{
/**
* Configure the list
*
* @param \Sonata\AdminBundle\Datagrid\ListMapper $list list
*/
protected function configureListFields(ListMapper $list)
{
$list
->addIdentifier('name', null, array('label' => 'Name'))
->add('description', null, array('label' => 'Description'));
}
/**
* Configure the form
*
* @param FormMapper $formMapper formMapper
*/
public function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('translations', 'a2lix_translations', array(
'by_reference' => false,
'locales' => array('fr', 'en'))
);
}
}
@mrcmorales
Copy link

Hello @tristanbes ,

I have this error when I create a new Profile.

I have the same code that in your blog example.

An exception occurred while executing 'INSERT INTO profile (name, description) VALUES (?, ?)' with params {"1":null,"2":null}:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null

Thanks

Regards

@mrcmorales
Copy link

Hello,

The solution to this error is put nullable=true in name and description.

@mrcmorales
Copy link

Hello,

@tristanbes Now I have a problem, AdminSonata want __toString() function, but how I can create this function to print one field in one language?

Another problem, is that listview don't print anything, I would like print every filed but in one language only. Is possible?

Thanks

Regards

@tristanbes
Copy link
Author

@mrcmorales Sorry it seems that github didn't send me notif so i didn't see your comments.

For the __toString, don't worry about it, just put :

public function __toString()
{
    return (string) $this->getName();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment