English 中文(简体)
CakePHP: 获取形式助手的“现”模式,供应到原值>create()
原标题:CakePHP: Accessing the form helper s "current" model as supplied to $form->create()

在我提出的CakePHP1.3申请中,我需要一种形式控制,即:

  1. Comprised of multiple form elements, and
  2. Reusable in more than one form. I d like to avoid code duplication if I can.

因此,我制造了一个因素,使我能够控制我的形式,在把控制与红.行动的价值联系起来时,我已经打上了路障。 现在,当你重新使用违约的实地类型时,卡纳克民阵对你来说就是这样,但我需要从<代码>$this->data中获取信息,并在此过程中自行这样做。

问题在于:<代码>$this->data。

array(
     Model  => array( /* fields from Model */ ),
     AnotherModel  => array( /* fields from AnotherModel */ )
);

在我可以解释的内容中,我不知道我的领域属于什么模式。 然而,我向形式帮助者讲述了这一信息,当时我称之为_$form->create()(认为其中含有Im写作的内容),因此,似乎能够告诉我。 确实,的标语:defaultModel,但令人痛心的是,这一财产是空的。

现在,简单的解决办法是将模型作为参数。 我可以这样做。 但是,我想避免我能够坐下来的直径流,似乎应该这样做,但我可以说明一下。 是否有办法?

感谢!

最佳回答

现在我感到悲观。 我本应在上任之前检查超级阶级。 表格Helper继承来自助手的AppHelper的遗产,而助手拥有一种<代码>model(<>,即 does切的手法。

Lesson learned. :)

问题回答

回避问题,但另一种办法是将表格Helper分类,增加一种习惯方法,以建立控制:

App::import( Helper ,  Form );

class CustomFormHelper extends FormHelper {
    public function customControl() {
        $control = $this->input(…);
        $control.= $this->checkbox(…);
        return $control;
    }
}




相关问题
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 ...

热门标签