将参数传递给 Presenter (fuelphp)
Pass parameters to Presenters (fuelphp)
如何将参数传递给 Presenter?阅读文档似乎没有办法。
https://fuelphp.com/docs/general/presenters.html
控制器
$points = Presenter::forge('points', 'viewmy');
$points->set('id', 5);
演示者 class 或视图(我都试过了):
var_dump($id);
var_dump($this->id);
两者都var_dumps产生未声明的变量错误
Presenter 中的这个 class 也不起作用:
$id = $this->get('id');
来自您链接的页面:
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.
它们与常规视图对象具有完全相同的界面。
因此,根据 https://fuelphp.com/docs/general/views.html,您可以使用 set()
方法或在 forge()
方法中传递参数。
我终于弄清了这个问题的真相。我在 Presenter 中使用 setview 函数根据条件进行更改。这意味着我设置的任何值都将丢失。
将视图传递到 forge 的第 4 个参数而不是在演示器中设置它解决了这个问题。
如何将参数传递给 Presenter?阅读文档似乎没有办法。
https://fuelphp.com/docs/general/presenters.html
控制器
$points = Presenter::forge('points', 'viewmy');
$points->set('id', 5);
演示者 class 或视图(我都试过了):
var_dump($id);
var_dump($this->id);
两者都var_dumps产生未声明的变量错误
Presenter 中的这个 class 也不起作用: $id = $this->get('id');
来自您链接的页面:
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.
它们与常规视图对象具有完全相同的界面。
因此,根据 https://fuelphp.com/docs/general/views.html,您可以使用 set()
方法或在 forge()
方法中传递参数。
我终于弄清了这个问题的真相。我在 Presenter 中使用 setview 函数根据条件进行更改。这意味着我设置的任何值都将丢失。
将视图传递到 forge 的第 4 个参数而不是在演示器中设置它解决了这个问题。