控制器文件名和控制器类名相同,采用驼峰法,首字母大写,如:
Course.php 课程控制器
Ticket.php 门票
User.php 用户
路径 app/web/controller/Course.php
<?php
namespace app\web\controller;
class Course
{
public function index()
{
return 'TimoPHP Controller Simple Example.';
}
}
/app/web/template/default
app/web/template/default/Course/index.tpl.php
default 是模版主题
Course 控制器名称
index 控制器方法名
<?php
namespace app\web\controller;
use Timo\Core\View;
class Course
{
public function index()
{
$view = View::instance();
$view->assign('courses', []);
return $view->render();
}
}
继承Timo\Core\Controller
namespace app\web\controller;
use Timo\Core\Controller;
class Course extends Controller
{
public function index()
{
$this->assign('courses', []);
return $this->render();
}
public function show()
{
$course = [
'id' => '1002',
'title' => '控制器的多种使用方式',
'content' => ''
];
$data = [
'title' => $course['title'] . ' - TimoPHP课程',
'course' => $course
];
return $this->render('', $data);
}
}