View To Do Item
Create php service class TodoList under Service directory, past following code
Code Block |
---|
|
<?php
namespace Apps\TodoList\Service;
use Phpfox;
class TodoList extends \Phpfox_Service
{
public function getForBrowse($id)
{
return \Phpfox::getLib('database')
db()->select('t.*')
->from(Phpfox::getT('todolist_task'), 't')
->where('task_id='. (int)$id)
->execute('getSlaveRow');
}
}
|
...
Code Block |
---|
|
// register service
$module->addServiceNames([
'todo.browse' => Service\Browse::class,
'todo' => Service\TodoList::class,
]);
|
Create a new controller AddController ViewController under Controller directory, then paste following code
Code Block |
---|
|
<?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,
]);
}
}
|
...
Code Block |
---|
|
$module->addComponentNames('controller', [
'toto'todo.view' => Controller\ViewController::class,
]);
|
Code Block |
---|
php | php |
route('to-do-list/view/:id/:name', function () {
\Phpfox_Module::instance()->dispatch('todo.view');
return 'controller';
});
|
...
Why the file name is view.html.php, let's review the naming rule mentioned in the previous chapters.
...
First, add code below to the bottom of file view.html.php under views/controller.
Code Block |
---|
| actionscript3 |
---|
| actionscript3 |
---|
|
{module name='feed.comment'}
|
Wiki Markup |
---|
By using {module name='...'}, you integrate block to your view.
|
...
Code Block |
---|
|
<?php
public function getForBrowse($id)
{
if (Phpfox::isModule('friend')) {
db()->select('f.friend_id AS is_friend, ')
->leftJoin(Phpfox::getT('friend'), 'f', "f.user_id = t.user_id AND f.friend_user_id = " . Phpfox::getUserId());
}
if (Phpfox::isModule('like')) {
db()->select('l.like_id AS is_liked, ')
->leftJoin(Phpfox::getT('like'), 'l', 'l.type_id = \'todo\' AND l.item_id = t.task_id AND l.user_id = ' . Phpfox::getUserId());
}
return db()->select('t.*')
->from(Phpfox::getT('todolist_task'), 't')
->where('task_id='. (int)$id)
->execute('getSlaveRow');
}
|
Finally, update ViewController with the following code.
Code Block |
---|
|
<?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']);
$this->setParam('aFeed', array(
'comment_type_id' => 'todo',
'privacy' => $aItem['privacy'],
'like_type_id' => 'todo',
'feed_is_liked' => $aItem['is_liked'],
'feed_is_friend' => $aItem['is_friend'],
'item_id' => $aItem['task_id'],
'user_id' => $aItem['user_id'],
'total_comment' => $aItem['total_comment'],
'total_like' => $aItem['total_like'],
'feed_link' => \Phpfox_Url::instance()->makeUrl('to-do-list/view'). $aItem['task_id'],
'feed_title' => $aItem['name'],
'feed_display' => 'view',
'feed_total_like' => $aItem['total_like'],
'report_module' => 'todo',
'report_phrase' => _p('report_this_todo'),
'time_stamp' => $aItem['time_stamp']
)
);
$template
->setTitle($aItem['name'])
->setBreadCrumb($aItem['name'], $url);
$template->assign([
'aItem' => $aItem,
]);
}
}
|
Visit to do list homepage, click a detail title to be redirected to detailed page, the final result will be 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.
...