Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

View To Do Item

Create php service class TodoList under Service directory, pasted following code

Code Block
php
php
<?php

namespace Apps\TodoList\Service;

use Phpfox;

class TodoList extends \Phpfox_Service
{
    public function getForBrowse($id)
    {
        return \Phpfox::getLib('database')
            ->select('*')
            ->from(Phpfox::getT('todolist_task'))
            ->where('task_id='. (int)$id)
            ->execute('getSlaveRow');
    }
}

Register service to start.php

Code Block
php
php
// register service
$module->addServiceNames([
    'todo.browse' => Service\Browse::class,
    'todo'        => Service\TodoList::class,
]);

Create a new controller AddController under Controller directory, then paste following code

Code Block
php
php
<?php

namespace Apps\TodoList\Controller;


class ViewController extends \Phpfox_Component
{
    public function process(){

        $template  = $this->template();

        // add your section menus
        $template->buildSectionMenu('to-do-list', [
            'Browse' => $this->url()->makeUrl('/to-do-list'),
            'Create' => $this->url()->makeUrl('/to-do-list/add'),
        ]);

        $template->menu('Add To Do', $this->url()->makeUrl('/to-do-list/add'));

        $id = $this->request()->get('req3');

        $browseService = \Phpfox::getService('todo');
        $aItem  = $browseService->getForBrowse($id);

        $url = $this->url()->permalink('to-do-list.view', $aItem['task_id'], $aItem['name']);

        $template
            ->setTitle($aItem['name'])
            ->setBreadCrumb($aItem['name'], $url);

        $template->assign([
            'aItem'=>$aItem,
        ]);
    }
}

Create a template file view.html.php under views\controller directory, paste following code

Code Block
php
php
<h4>Name</h4>
<p>{$aItem.name}</p>
<h4>Description</h4>
<p>{$aItem.description}</p>
<h4>Status</h4>
<p>{ if $aItem.task_status >0 }complete{else}in-complete{/if}</p>
<h4>Created</h4>
<p>{$aItem.time_stamp|convert_time}</p>

Visit to do list homepage, click a detail title to be redirected to detail page, the final result is similar to

Congratulation, You have basic knowledge about Create, Listing, View a to do list item, using phpFox services database, url, template
Next chapter will show you how to interact to most important of social network feature Activity Feed.

Next Chapter