我正在使用SonataAdminBundle我的应用程序中管理实体.该网站的管理员可以添加视频,其中一些首先需要由他们的扬声器批准.已经有一个授权系统正在运行 - 我有一个工作代码,它将生成一个特殊链接,并通知可以批准或拒绝视频的发言人,并自动通知管理员.
我想自定义我的管理部分,因此ask for authorization视频旁边会有一个按钮.我可以在list action(/admin/acme/videos/list)或右边nav(/admin/acme/videos/x/edit/)中的某个编辑操作中使用它
这样做的最佳方法是什么?文档对块自定义说的很少,但我发现这个例子可能是我正在寻找的东西,但我无法弄清楚如何使用它.
一个选项是使用preUpdate钩子,并为编辑操作添加一个复选框,但按钮会更好.
我正在尝试在奏鸣曲管理包中添加一个动作.我更改了我的Admin类:
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('id')
->add('name')
// add custom action links
->add('_action', 'actions', array(
'actions' => array(
'view' => array(),
'calculate' => array('template' => 'myappMyBundle:Admin:list__action_calculate.html.twig'),
'edit' => array(),
)
))
;
}
Run Code Online (Sandbox Code Playgroud)
和
protected function configureSideMenu(MenuItemInterface $menu, $action, Admin $childAdmin = null)
{
if (!$childAdmin && !in_array($action, array('edit'))) {
return;
}
$admin = $this->isChild() ? $this->getParent() : $this;
$id = $admin->getRequest()->get('id');
$menu->addChild('calculate', array('uri' => 'http://google.com?id=' . $id));
}
Run Code Online (Sandbox Code Playgroud)
并在src/myapp/MyBundle/Resources/views/Admin /中放入一个名为list__action_calculate.html.twig的模板:
{% if admin.isGranted('EDIT', object) and admin.hasRoute('edit') %} …Run Code Online (Sandbox Code Playgroud) 我有一个product实体,它有一个images存储产品图像名称的part_number字段,但图像名称取决于一个独特的字段,所以如果用户在部件号中出错,他想编辑它,那么我也有更改图像名称
我试过这个,但它不起作用:
// class ProductsAdmin extends Admin
public function preUpdate($product) {
$old_product = $this->getSubject();
if ($old_product->getPartNumber() != $product->getPartNumber)
{
// change file names
}
$this->saveFile($product);
}
Run Code Online (Sandbox Code Playgroud)
我如何获得preUpdate()函数中的原始行?
我正在使用Sonata管理包为我的应用程序一切正常,在我的应用程序中我有用户和管理员,管理员可以添加/编辑/删除用户当我尝试更新用户时出现问题密码数据被用户覆盖表.我已经覆盖了preUpdate管理控制器的方法,我得到了$object一个用户实体管理器的实例,所以如果用户离开更新密码并保存数据密码丢失.
public function preUpdate($object)
{
$Password = $object->getUserPassword();
if (!empty($Password)) { /* i check here if user has enter password then update it goes well*/
$salt = md5(time());
$encoderservice = $this->getConfigurationPool()->getContainer()->get('security.encoder_factory');
$User = new User();
$encoder = $encoderservice->getEncoder($User);
$encoded_pass = $encoder->encodePassword($Password, $salt);
$object->setUserSalt($salt)->setUserPassword($encoded_pass);
} else { /* here i try to set the old password if user not enters the new password but fails */
$object->setUserPassword($object->getUserPassword());
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试设置$object->setUserPassword($object->getUserPassword());它获取null并将密码更新为null它没有得到编辑数据我试图再次获取存储库(下面)获取密码但没有运气它得到相同
$DM = $this->getConfigurationPool()->getContainer()->get('Doctrine')->getManager()->getRepository("...")->find(id here);
Run Code Online (Sandbox Code Playgroud)
有没有办法可以访问实体管理器中当前实体的原始数据
我收到消息:
无法找到该类的有效管理员:Aman\VarshneyBundle\Entity\ArticleTable,获得太多管理员注册:sonata.admin.appsreview,sonata.admin.review,sonata.admin.article
我无法弄清楚这个问题.
我根据文档安装了SonataUserBundle,一切正常.除了我不能添加自定义验证规则.
我的理解是新规则应该添加到新的验证组,然后更新config.yml以告诉SonataUserBundle(或FosUserBundle)将新规则添加到验证序列.
我已经以各种方式尝试了这一点,但新规则似乎根本没有被接受......
这是我正在使用的配置......
(为了这个例子,我只是尝试将NotNull约束添加到一个新的foo字段.实际上我希望看到这么多工作,然后添加更多的验证规则.)
我已经添加了foo字段,Application\Sonata\UserBundle\Resources\config\doctrine\User.orm.xml并且一切正常,将foo字段添加到User.php类中.
# in Application\Sonata\UserBundle\Resources\config\doctrine\User.orm.xml
...
<field name="foo" type="string" length="100" nullable="true" />
...
Run Code Online (Sandbox Code Playgroud)
在User.php中,我们有getter和setter的属性:
// In Application\Sonata\UserBundle\Entity\User.php
// ...
/**
* @var string
*/
private $foo;
/**
* Set foo
*
* @param string $foo
* @return User
*/
public function setFoo($foo)
{
$this->foo = $foo;
return $this;
}
/**
* Get foo
*
* @return string
*/
public function getFoo()
{
return $this->foo;
}
// ...
Run Code Online (Sandbox Code Playgroud)
然后我将新的验证规则添加到我项目的现有validation.yml文件中:
Application\Sonata\UserBundle\Entity\User:
properties:
foo:
- …Run Code Online (Sandbox Code Playgroud) validation symfony fosuserbundle sonata-admin sonata-user-bundle
我想在sonata管理包中自定义编辑页面中表单字段的呈现, 以包含使用字段文本内容的applet.
我知道我必须configureFormFields在admin类中编辑该函数,但我需要知道3件事:
我将SonataAdminBunle与symfony 2.2结合使用时出现问题.我有一个Project实体和一个ProjectImage实体,并指定这两者之间的一对多关系,如下所示:
class Project
{
/**
* @ORM\OneToMany(targetEntity="ProjectImage", mappedBy="project", cascade={"all"}, orphanRemoval=true)
*/
private $images;
}
class ProjectImage
{
/**
* @ORM\ManyToOne(targetEntity="Project", inversedBy="images")
* @ORM\JoinColumn(name="project_id", referencedColumnName="id")
*/
private $project;
}
Run Code Online (Sandbox Code Playgroud)
我已经配置了ProjectAdmin和ProjectImageAdmin:
class ProjectAdmin extends Admin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('title')
->add('website')
->add('description', 'textarea')
->add('year')
->add('tags')
->add('images', 'sonata_type_collection', array(
'by_reference' => false
), array(
'edit' => 'inline',
'inline' => 'table',
'sortable' => 'id',
))
;
}
}
class ProjectImageAdmin extends Admin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('file', …Run Code Online (Sandbox Code Playgroud) 我安装了SonataAdmin Bundle.一切正常,但是当我从仪表板添加任何用户时,它会抛出一个警告:
警告:IntlDateFormatter :: format():datefmt_format:在C:\ wamp\www\sonata-sandbox\vendor\symfony\symfony\src\Symfony\Component\Form \中获取数组或整数时间戳值或DateTime对象第260行的Extension\Core\Type\DateType.php
我想在Sonata Admin show模板中生成一个小表单.到目前为止,我所做的是在自定义CRUD中为从Sonata的默认CRUD扩展的特定实体(顺序)创建函数;
public function approveOrderAction($id = null)
{
$request = $this->getRequest();
$id = $request->get($this->admin->getIdParameter());
$order = $this->admin->getObject($id);
$approveForm = $this->createFormBuilder($order)
->add('reqSecondApprover', 'checkbox', array('label' => 'Require second Approval', 'required' => false))
->add('secondApprover', 'choice', array('choices' => Crud::getWhatever(array('Developer')), 'required' => false))
->getForm();
$approveForm->handleRequest($request);
if ($approveForm->isSubmitted() && $approveForm->isValid()) {
$secondApproval = $request->request->get('form');
$approval = $approveForm->getData();
if (isset($secondApproval['reqSecondApprover'])) {
$order->setStatus(PmodOrder::STATUS_PARTLY_APPROVED);
} else {
$order->setStatus(PmodOrder::STATUS_APPROVED);
$order->setSecondApprover(null);
}
$em->persist($approval);
$em->flush();
return new RedirectResponse($this->admin->generateUrl('show'));
}
return $this->render('AppBundle:PmodOrder:order_approve.html.twig', array(
'order' => $order,
'form' => $approveForm->createView(),
));
}
Run Code Online (Sandbox Code Playgroud)
在我的orderAdmin我有 …
sonata-admin ×10
symfony ×7
php ×3
symfony-2.1 ×3
sonata ×2
symfony-2.3 ×2
doctrine-orm ×1
forms ×1
intl ×1
validation ×1