Pass parameters to Presenters (fuelphp)

放肆的年华 提交于 2019-12-12 01:41:58

问题


How does one pass a parameters to a Presenter? Reading the documentation there doesn't seem to be a way.

https://fuelphp.com/docs/general/presenters.html

Controller

    $points = Presenter::forge('points', 'viewmy');
    $points->set('id', 5);

Presenter class or view (I tried both):

var_dump($id);
var_dump($this->id);

Both var_dumps generate an undeclared variable error

This in the Presenter class also did not work: $id = $this->get('id');


回答1:


From the page you linked:

In your code, Views and Presenters are interchangeable. You can return Presenters from your controller actions, you can set a Presenter as a Theme partial, or assign it to a section of your page template. The basic API of the Presenter is compatible with the View. This makes it easy to swap a View for a Presenter in your code without having to do a major code overhaul.

They have the exact same interface as regular View objects.

So as per https://fuelphp.com/docs/general/views.html you can do things like using the set() method or passing the parameters in the forge() method.




回答2:


I finally got to the bottom of this issue. I was using the setview function in my Presenter to change based on condition. This was meaning that any values that I had set were getting lost.

Passing the view into the 4th parameter of forge and not setting it in the presenter fixed this issue.



来源:https://stackoverflow.com/questions/42964019/pass-parameters-to-presenters-fuelphp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!