English 中文(简体)
从CakePHP部分到助手的数据
原标题:Passing data from CakePHP component to a helper

我需要在组成部分和助手之间分享数据。 我把我自制的付费服务制成数据生成器转换成一个卡克萨斯喀彻温板,我愿意填写控制器(使用一个部件)的付款数据,并使用一台助手打印数据。

我迄今所尝试的所有东西都感到过一点太 ha,因此,请你: 是否有任何<>法定方式将数据从一个部分传送给一个助手?


编辑:

我解决了这一特殊情形,在构成部分初始阶段,将原数据类别类别添加到类别Registry。 这样,该助手也可以通过职业类获得治疗。

However, this only works for objects, so the question remains open.

最佳回答
问题回答

还有一个类似的问题,我认为这一解决办法对我来说是最好的。

您可以使用辅助器__ 施工方法,配以控制器和助推器阵列。

Since the Helper::_construct() is called after the Component::beforeRender, you can modify the $controller->helpers[ YourHelperName ] array to pass the data to your helper.

www.un.org/Depts/DGACM/index_spanish.htm

<?php

public function beforeRender($controller){
    $controller->helpers[ YourHelperName ][ data ] = array( A =>1,  B =>2);
}
?>

www.un.org/Depts/DGACM/index_spanish.htm 助手代码:

<?php

function __construct($View, $settings){
    debug($settings);       
            /* outputs:
                array(
                     data  => array(
                         A  => (int) 1,
                         B  => (int) 2
                    )
                )
            */
}

?>

I am using CakePHP 2.0, so this solution should be tested for earlier versions.

除了“Vanja”之外,你还可以在你控制者提出新观点之前这样做:

// In your controller method
// must be set prior to instantiating view
$this->helpers[ YourHelperName ][ paramsOrAnyName ] = [ var  => $passed_var];

$_newView = new View($this);
$return_result = $_newView->render($element_to_view, $layout);




相关问题
PHP Framework: Ebay Like Site

I am going to be builiding a site like ebay - with all the features of ebay. Please note my payment method is limited to paypal. What would be the best PHP framework to use to build this quickly, ...

specifying date format when using $form->inputs() in CakePHP

I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...

Using DISTINCT in a CakePHP find function

I am writing a CakePHP 1.2 app. I have a list of people that I want the user to be able to filter on different fields. For each filterable field, I have a drop down list. Choose the filter ...

Assistance with CakePHP model relationships

How would I represent the following in a CakePHP model? Product ======= product_id .... Cart ==== cart_id .... Carts_Products ============== cart_id product_id quantity

Prevent controller from trying to autoload model

I am a beginning Cake user and trying to do some work on an already existing application. Running into a problem when I create a new controller. I have created StoreController and when I try to call ...

热门标签