Passing data from CakePHP component to a helper

前端 未结 3 1879
萌比男神i
萌比男神i 2020-12-18 10:27

I need to share data between a component and helper. I\'m converting my self-made payment service formdata generator to a CakePHP plugin and I\'d like to be able to fill in

3条回答
  •  梦毁少年i
    2020-12-18 10:59

    Having a similar problem, I found this solution to work best for me.

    You could use the helper's __construct method in pair with $controller->helpers array.

    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.

    Component code:

    helpers['YourHelperName']['data'] = array('A'=>1, 'B'=>2);
    }
    ?>
    

    Helper code:

     array(
                            'A' => (int) 1,
                            'B' => (int) 2
                        )
                    )
                */
    }
    
    ?>
    

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

提交回复
热议问题