English 中文(简体)
报表2表格——出入参数。
原标题:Symfony 2 forms - access parameters.ini from the form class

我需要从表格中查阅<代码>参数。

在座各位可以从控制人那里获得:

$myVal = $this->container->getParameter( my_val );

致控制员:

$demoForm = $this->createForm(new demoFormType($myVal), $demoObject);

并且以节省这些价值的形式转给了建筑商(应当明确予以执行)。

然而,这种形式在几个控制人员中使用,因此,简单地从形式类别中以某种“魔法”的方式进入,会更加清洁。

是否可能? 我找不到任何答案。

感谢!

问题回答

我不敢肯定,你所建议的方式是最好的想法。 表格象这样简便。

相反,也许你可以创造新的控制者来继承。

namespace YourBundleController;

use SymfonyBundleFrameworkBundleControllerController;
use YourBundleFormTypedemoFormType;

class FormAwareController extends Controller
{
  protected function createDemoForm( $demoObject )
  {
    $myVal = $this->container->getParameter(  my_val  );
    return $this->createForm( new demoFormType( $myVal, $demoObject ) );
  }
}

之后,将这一类别扩大到你需要的地方。

namespace YourBundleController;

class SampleController extends FormAwareController
{
  public function indexAction()
  {
    $demoObject = new stdClass; // or whatever
    $form = $this->createDemoForm( $demoObject );

    // etc...
  }
}

Define You form as aservice, 然后使用百分比的参数将参数参数转给它。 那么,你的控制者就可以在不需要了解有关初始化进程的任何情况的情况下 gr忙。

这种技术对于建立实体管理人员和其他受扶养人也非常有用。

这里是发送参数的过程。 (一) 辛醇

参数:

app_name = "Application Name";

主计长办公室

$data = array(
app_name =>$this->container->getParameter(  app_name  );
)
return $this->render( Bundle:Home:index.html.twig , $data);

观点

{{app_name}}




相关问题
Mutually exclusive powershell parameters

SCENARIO I m writing a cmdlet for Powershell 2.0 using Visual Studio 2008 and .NET 3.5 the cmdlet requires 3 arguments. my intended grammar of the cmdlet is something like this: cmdletname [foo|...

Elegant way building url request with parameters

There must me a more elegant way to build a URL with parameters in .NET then for example Response.Write("<a href=HeadOfMarketView.aspx"+Session["HOM"] != null ? Session["HOM"]+">Head of Market&...

Can you pass by reference in Java?

Sorry if this sounds like a newbie question, but the other day a Java developer mentioned about passing a paramter by reference (by which it was ment just pass a Reference object) From a C# ...

How to name a method that has an out parameter?

What is the common preference to name a method that has an out parameter inside? Usually I use Get as a prefix to mention that the method returns a value (like GetMyBusiness). But what if there is ...

How to create program startup parameters in python

I m just beginning to learn python and the program I m writing requires parameters for it to run with a specific task. For example (programs name is Samtho) samtho -i Mozilla_Firefox How can I do ...

Weird behaviour of h:commandLink action (MethodExpression)

I have two JSPs where I am displaying some info from database in a h:dataTable. One of them is showing all the info, and one of them user specifically. I have showXML.jsp that shows the "XML" column ...

using parameter in SQL with LIKE keyword

from my C#-programm, I access a SQL Server 2008 Database. I have a table with a fulltextindex and want to search for an indexed entry: SELECT page_id FROM page_categories WHERE page_title LIKE @title ...

采用网路服务方法

我撰写了一个网络服务,期望一个参数(所谓的“hlink”)成为一种ur。 在使用网络服务之前,URLEncode 所涉参数(“hlink”)。 然后我打电话......。

热门标签