...
Add new php class IndexController under directory ./PF.Site/Apps/TodoList/Controller/
paste example code.
Code Block | ||||
---|---|---|---|---|
| ||||
<?php
namespace Apps\TodoList\Controller;
// Index controller must be child of \Phpfox_Component class.
//
class IndexController extends \Phpfox_Component
{
public function process()
{
// Get phpFox core template service
$template = $this->template();
// set view title
$template->setTitle('To Do List');
// set view breadcrumb
// get url
$url = $this->url()->makeUrl('to-do-list');
$template->setBreadCrumb('To Do List',$url);
// add your section menus
$template->buildSectionMenu('to-do-list', [
'Browse' => $this->url()->makeUrl('/to-do-list'),
'Create' => $this->url()->makeUrl('/to-do-list/add'),
]);
}
}
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
<p>Hello, to do list home page</p>
|
Now we define route to define configurations, edit start.php, paste following code.
Code Block | ||||
---|---|---|---|---|
| ||||
<?php namespace Apps\TodoList; // Load phpFox module service instance, this is core of phpFox service, // module service contains your app configuration. $module =\Phpfox_Module::instance(); // Instead of \Apps\FirstApp every where. Let register an alias **first_app** that map to our app. $module->addAliasNames('todo', 'TodoList'); // Register your controller here $module->addComponentNames('controller', [ 'todo.index' => Controller\IndexController::class, ]); // Register template directory $module->addTemplateDirs([ 'todo' => PHPFOX_DIR_SITE_APPS . 'whereTodoList/views', ]); route('to-do-list',function (){ \Phpfox_Module::instance()->dispatch('todo.index'); return 'controller'; }); |
All your php classes must have namespace Apps\TodoList, This help autoloader know where to load scripts.
Open browse, in address bar append /index.php/to-do-list/, then see the result.
Add Main Menu
Main menu will be added automatically by phpFox, edit Install.php,
update function setAlias
Code Block | ||||
---|---|---|---|---|
| ||||
<?php
protected function setAlias()
{
$this->alias = 'todo';
}
|
update function setOthers
Code Block | ||||
---|---|---|---|---|
| ||||
<?php
protected function setOthers()
{
//add the menu for your app
$this->menu = [
"name" => "To Do List", // Menu label
"url" => "/to-do-list", // Menu Url
"icon" => "tasks" // Menu icons, see http://fontawesome.io/icons/
];
}
|
In case you want to use a defined phrase for menu label, you can use the below script
Code Block | ||||
---|---|---|---|---|
| ||||
<?php
$this->menu = [
"phrase_var_name" => "menu_to_do_list", // Var name for the phrease of menu
"url" => "/to-do-list", // Menu Url
"icon" => "tasks" // Menu icons, see http://fontawesome.io/icons/
];
|
...
pasted code into IndexController.php
Code Block | ||||
---|---|---|---|---|
| ||||
$template->menu('Add To Do', $this->url()->makeUrl('/to-do-list/add'));
|
...