English 中文(简体)
核心发言部分
原标题:Overwriting Core Symfony2 Components
  • 时间:2012-04-06 23:53:58
  •  标签:
  • php
  • symfony

Alright, Gonna应诚实。 如同一些决定一样,Symfony决定用其核心档案处理,企图掩盖这些档案。 例如

Symfony/Component/Form/Extension/Core/Type/ FieldType.php

im 试图改变如果一个表态有父母一方,因为自己做一些冷却式铺设,就会出现的名字。

只是试图使其成为<代码>fullName和$id。 两者均为<代码>form->getName();

 public function buildView(FormView $view, FormInterface $form)
    {
        $name = $form->getName();

        if ($view->hasParent()) {
            $parentId = $view->getParent()->get( id );
            $parentFullName = $view->getParent()->get( full_name );

            // Custom Logic
            //$id = sprintf( %s_%s , $parentId, $name);
            //$fullName = sprintf( %s[%s] , $parentFullName, $name);
            $id = $form->getName();
            $fullName = $form->getName();
        } else {
            $id = $name;
            $fullName = $name;
        }

        $types = array();
        foreach ($form->getTypes() as $type) {
            $types[] = $type->getName();
        }

        $view
            ->set( form , $view)
            ->set( id , $id)
            ->set( name , $name)
            ->set( full_name , $fullName)
            ->set( errors , $form->getErrors())
            ->set( value , $form->getClientData())
            ->set( read_only , $form->isReadOnly())
            ->set( required , $form->isRequired())
            ->set( max_length , $form->getAttribute( max_length ))
            ->set( pattern , $form->getAttribute( pattern ))
            ->set( size , null)
            ->set( label , $form->getAttribute( label ))
            ->set( multipart , false)
            ->set( attr , $form->getAttribute( attr ))
            ->set( types , $types)
        ;
    }
最佳回答

建立助手职能。

public function fixForm(SymfonyComponentFormFormView $form)
{
    foreach($form as &$child)
    {
        $name = $child->get( full_name );
        $id = $child->get( id );
        $matches = array();
        preg_match( /^(?<form>.+)[(?<ele>.+)]/ , $name, $matches);
        if(isset($matches[ ele ]))
            $child->set( full_name , $matches[ ele ]);
        $matches = array();
        preg_match( /^(?<first>.+)_(?<second>.+)/ , $id, $matches);
        if(isset($matches[ second ]))
            $child->set( id , $matches[ second ]);
    }
    return $form;
}

及其工作。 当你需要确定形式时,就应该这样说。

问题回答

我认为,你可以尝试的是建立自己的形式类型。

你可以把自己的表格放在你自己的布道上,即你拥有像“试验”/Form/Type”这样的干净结构。

In this fieldtype you can make your changes you need.

我怎么能做一个习惯的实地类型?

这里是一个很有帮助的哨所,显示有热能形成一种习惯的外地类型。

它是一个简短的 h,希望你找到一个好的解决办法,并且能够告诉我们它的工作以及你是如何解决的。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签