...
Create php class RecentItems under directory ./PF.Site/Apps/TodoList/Block/
paste Paste following code
Code Block | ||||
---|---|---|---|---|
| ||||
<?php namespace Apps\TodoList\Block; // RecentMembers block must be a child of \Phpfox_Components // class RecentItems extends \Phpfox_Component { // this method will be invoked by phpfox public function process() { // assign variables to template $this->template() ->assign([ 'sHeader' => 'Recent Items', // block title 'aItems' => ['Item 1', 'Item 2', 'Item 3'], ]); return 'block'; } } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
<ul>
{foreach from=$aItems item=item}
<li class="category">
<p>
{$item}
</p>
{/foreach}
</ul>
|
Update start.php, paste following code
Code Block | ||||
---|---|---|---|---|
| ||||
$module->addComponentNames('block', [
'todo.recent_items' => Block\RecentItems::class,
]);
|
Update Install.php, change setComponent() and setComponentBlock()
Code Block | ||||
---|---|---|---|---|
| ||||
protected function setComponent()
{
$this->component = [
"block" => [
"recent_items" => "",
],
"controller" => [
"index" => "todo.index",
]
];
}
protected function setComponentBlock()
{
$this->component_block = [
"Recent Items" => [
"type_id" => "0",
"m_connection" => "todo.index",
"component" => "recent_items",
"location" => "3",
"is_active" => "1",
"ordering" => "1"
],
];
}
|
Then update your app to apply your modification. How (how to update app configurations)
Open browser again, see result:
!images/https://docs.phpfox.com/download/attachments/851993/create-your-first-block.png?api=v2!