在Controller中直接调用Dao类,就可以实现MVC分层。即不使用Service层。
class indexController extends Controller {
public $initphp_list = array('test');
public function run() {
$data = array('id' => 100);
$this->getTestDao()->addTest($data);
$this->view->display(); //模板显示
}
/**
* @return testService
*/
private function getTestDao() {
return InitPHP::getDao('test','test');
}
}
Dao层需要继承框架中的Dao类(Dao基类)。Dao层可以使用$this->dao调用框架中提供的Db和Cache接口。调用Dao的方法是全局方法:InitPHP::getDao('Dao名称')。
class testDao extends Dao {
public function test() {
$this->dao->db->insert(array('name' => 'cccccccc'), 'test');
print_r($this->dao->db->get_all('test'));
}
}
Service层需要继承框架中的Service类(Service基类)。Service层可以使用$this->service调用框架中提供的接口。调用Service的方法是全局方法:InitPHP::getService('Service名称')
class testService extends Service {
public function test() {
$this->getTestaDao()->test();
}
/**
* @return testDao
*/
private function getTestDao() {
return InitPHP::getDao('test', 'test');
}
/**
* @return testaDao
*/
private function getTestaDao() {
return InitPHP::getDao('testa', 'test');
}
}
Controller层需要继承框架中的Controller类(Controller基类)。Controller层可以使用$this->controller和$this->view调用框架中提供的接口
class indexController extends Controller {
public $initphp_list = array('test');
public function run() {
echo '< img src="http://127.0.0.1/initphp2/demo/index.php?c=index&a=test">';
$this->view->display(); //模板显示
}
public function test() {
$code = $this->getLibrary('code');
$code->getcode();
}
/**
* @return testService
*/
private function getTestService() {
return InitPHP::getService('test','test');
}
}
View层,模板层
asddddddddddddddddddddasdasd<!--{echo $a;}-->