ReportWidgets - which is correct way (more Winterish :D #805
-
class MembersAtRisk extends ReportWidgetBase
{
public function render()
{
try {
$this->loadData();
}
catch (Exception $ex) {
$this->vars['error'] = $ex->getMessage();
}
return $this->makePartial('widget');
}
protected function loadData()
{
$this->vars['members_list'] = # what put here?
}
} And in members_list I want special filtered list of members (not used anywhere else) And now there's three ways I can imagine:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
More or less like this use WebVPF\PlugName\Models\Member;
class MembersAtRisk extends ReportWidgetBase
{
// ...
protected function loadData()
{
$this->vars['members_list'] = Member::where('is_activated', true)->get();
}
} Here is an example with data from the Winter.User plugin: https://github.com/wintercms/wn-user-plugin/blob/7208cc1af5b8d5af6089eb4c08225c84547a0efd/reportwidgets/Statistics.php |
Beta Was this translation helpful? Give feedback.
-
But for complex views you can use: $this->vars['members_list'] = Db::select('select * from users where active = ?', [1]); |
Beta Was this translation helpful? Give feedback.
More or less like this
Here is an example with data from the Winter.User plugin: https://github.com/wintercms/wn-user-plugin/blob/7208cc1af5b8d5af6089eb4c08225c84547a0efd/reportwidgets/Statistics.php