typecho framework是70寫的一個框架。聽說是參考了java的思想。php
項目地址:https://github.com/typecho/framework
參考項目:https://github.com/typecho/framework-examplejava
先clone這個example,而後咱們要寫個控制器,在action文件夾下新建Hello.phpgit
namespace Example\Action; use TE\Mvc\Action\AbstractAction; class Hello extends AbstractAction { public function execute() { return array('content', 'Hello World'); } }
框架的主要想法是經過一個主出口返回各類須要的相應,好比content是指直接輸出,換成template是把數據傳到模板裏,換成json就是把數據生成一個json。github
要先頁面上顯示咱們還須要寫一下路由。
打開config\routes.php數據庫
return array( '/' => 'Example\Action\Index', '/hello' => 'Example\Action\Hello' );
因爲example中有用到數據庫,咱們先註釋掉。index.php文件中json
Base::setInjectiveObjects(require(ROOT . '/../config/injects.php'));
註釋這行。
而後這樣能夠經過訪問{fileroot}/portal/index.php/hello看到輸出了hello world。框架
仍是Action\Hello.php裏,咱們改execute函數函數
public function execute() { $this->word = 'Hello World'; return array('template', 'hello.php'); }
而後咱們在template中新建一個hello.php文件typecho
<?php echo $word; ?>
就能夠看到頁面輸出hello worldui
好比
http://192.168.33.10/framework-example/portal/index.php/hello?p=hello%20world
把p=hello world傳入hello中
public function execute() { $this->word = $this->request->get('p'); return array('template', 'hello.php'); }
這樣咱們就在頁面上看到hello world。
先這樣