* 配置
視圖view 依賴于smarty,需要composer安裝smarty,原則上swoolefy一般不作為視圖渲染的,定義為一個api框架
```
composer require smarty/smarty
```
在應用層配置文件中
~~~
'components' => [
// 第一種方式利用配置項設置
'view' => [
'class' => 'Swoolefy\Core\View',
],
// 第二種動態創建,更加靈活,推薦
'view' => function($com_name) {
$view = new Swoolefy\Core\View();
return $view;
}
]
~~~
* 獲取實例
在應用中
~~~
$view = Application::getApp()->view;
~~~
我們在控制器中使用
~~~
$this->assign('name', $name);
$this->assign('books', $books);
$this->display('test.html');
~~~
其實就是通過view組件實例進行封裝的,例如在`Swoolefy\Core\AppTrait.php`中
~~~
/**
* assign
* @param string $name
* @param string|array $value
* @return void
*/
public function assign($name,$value) {
Application::getApp()->view->assign($name,$value);
}
/**
* display
* @param string $template_file
* @return void
*/
public function display($template_file=null) {
Application::getApp()->view->display($template_file);
}
/**
* fetch
* @param string $template_file
* @return void
*/
public function fetch($template_file=null) {
Application::getApp()->view->display($template_file);
}
/**
* returnJson
* @param array $data
* @param string $formater
* @return void
*/
public function returnJson($data,$formater = 'json') {
Application::getApp()->view->returnJson($data,$formater);
}
~~~
- 歡迎使用swoolefy
- 環境說明
- 開發部署
- 安裝
- 創建應用
- 啟動|停止服務
- nginx代理
- 創建Controller
- 應用結構
- App應用對象
- Event請求處理
- 超全局管理
- 熱更新
- inotify實現worker進程熱重啟
- http服務
- 應用層配置
- 協議層配置
- 路由規則
- 控制器
- 數據模型
- websocket服務
- 應用層配置
- 協議層配置
- 數據封裝格式
- 控制器
- 數據模型
- 二進制數據處理
- rpc服務
- 應用層配置
- 協議程配置
- 數據包協議格式
- 服務控制器
- 服務數據模型
- udp服務
- 應用層配置
- 協議層配置
- 數據包封裝格式
- 控制器
- 存在問題
- 常用組件
- log
- view
- session
- cache(redis)
- db(mysql)
- mongodb
- 其他服務管理
- 自定義進程管理
- 異步任務管理
- 內存表管理
- 定時器管理
- 異常捕捉處理
- 進程池管理
- systerm采集進程服務