-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
One2r
committed
Jan 21, 2018
1 parent
43f3feb
commit 83a27ef
Showing
12 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/** | ||
* @name Bootstrap | ||
* @author root | ||
* @desc 所有在Bootstrap类中, 以_init开头的方法, 都会被Yaf调用, | ||
* @see http://www.php.net/manual/en/class.yaf-bootstrap-abstract.php | ||
* 这些方法, 都接受一个参数:Yaf_Dispatcher $dispatcher | ||
* 调用的次序, 和申明的次序相同 | ||
*/ | ||
class Bootstrap extends Yaf_Bootstrap_Abstract { | ||
|
||
public function _initConfig() { | ||
//把配置保存起来 | ||
$arrConfig = Yaf_Application::app()->getConfig(); | ||
Yaf_Registry::set('config', $arrConfig); | ||
} | ||
|
||
public function _initPlugin(Yaf_Dispatcher $dispatcher) { | ||
//注册一个插件 | ||
$objSamplePlugin = new SamplePlugin(); | ||
$dispatcher->registerPlugin($objSamplePlugin); | ||
} | ||
|
||
public function _initRoute(Yaf_Dispatcher $dispatcher) { | ||
//在这里注册自己的路由协议,默认使用简单路由 | ||
} | ||
|
||
public function _initView(Yaf_Dispatcher $dispatcher) { | ||
//在这里注册自己的view控制器,例如smarty,firekylin | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
/** | ||
* @name ErrorController | ||
* @desc 错误控制器, 在发生未捕获的异常时刻被调用 | ||
* @see http://www.php.net/manual/en/yaf-dispatcher.catchexception.php | ||
* @author root | ||
*/ | ||
class ErrorController extends Yaf_Controller_Abstract { | ||
|
||
//从2.1开始, errorAction支持直接通过参数获取异常 | ||
public function errorAction($exception) { | ||
//1. assign to view engine | ||
$this->getView()->assign("exception", $exception); | ||
//5. render by Yaf | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
/** | ||
* @name IndexController | ||
* @author root | ||
* @desc 默认控制器 | ||
* @see http://www.php.net/manual/en/class.yaf-controller-abstract.php | ||
*/ | ||
class IndexController extends Yaf_Controller_Abstract { | ||
|
||
/** | ||
* 默认动作 | ||
* Yaf支持直接把Yaf_Request_Abstract::getParam()得到的同名参数作为Action的形参 | ||
* 对于如下的例子, 当访问http://yourhost/mfby/index/index/index/name/root 的时候, 你就会发现不同 | ||
*/ | ||
public function indexAction($name = "Stranger") { | ||
//1. fetch query | ||
$get = $this->getRequest()->getQuery("get", "default value"); | ||
|
||
//2. fetch model | ||
$model = new SampleModel(); | ||
|
||
//3. assign | ||
$this->getView()->assign("content", $model->selectSample()); | ||
$this->getView()->assign("name", $name); | ||
|
||
//4. render by Yaf, 如果这里返回FALSE, Yaf将不会调用自动视图引擎Render模板 | ||
return TRUE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
项目库文件放在这里 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
/** | ||
* @name SampleModel | ||
* @desc sample数据获取类, 可以访问数据库,文件,其它系统等 | ||
* @author root | ||
*/ | ||
class SampleModel { | ||
public function __construct() { | ||
} | ||
|
||
public function selectSample() { | ||
return 'Hello World!'; | ||
} | ||
|
||
public function insertSample($arrInfo) { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/** | ||
* @name SamplePlugin | ||
* @desc Yaf定义了如下的6个Hook,插件之间的执行顺序是先进先Call | ||
* @see http://www.php.net/manual/en/class.yaf-plugin-abstract.php | ||
* @author root | ||
*/ | ||
class SamplePlugin extends Yaf_Plugin_Abstract { | ||
|
||
public function routerStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { | ||
} | ||
|
||
public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { | ||
} | ||
|
||
public function dispatchLoopStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { | ||
} | ||
|
||
public function preDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { | ||
} | ||
|
||
public function postDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { | ||
} | ||
|
||
public function dispatchLoopShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
echo "Error Msg:" . $exception->getMessage(); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
echo $content, " I am ", $name; | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[common] | ||
application.directory = APPLICATION_PATH "/application" | ||
application.dispatcher.catchException = TRUE | ||
|
||
[product : common] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
RewriteEngine On | ||
RewriteCond %{REQUEST_FILENAME} !-f | ||
RewriteRule .* index.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
define('APPLICATION_PATH', dirname(__FILE__)."/../"); | ||
|
||
$application = new Yaf_Application( APPLICATION_PATH . "/conf/application.ini"); | ||
|
||
$application->bootstrap()->run(); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
可以按照以下步骤来部署和运行程序: | ||
1.请确保机器root@25f6d6f17ac6已经安装了Yaf框架, 并且已经加载入PHP; | ||
2.把mfby目录Copy到Webserver的DocumentRoot目录下; | ||
3.需要在php.ini里面启用如下配置,生产的代码才能正确运行: | ||
yaf.environ="product" | ||
4.重启Webserver; | ||
5.访问http://yourhost/mfby/,出现Hellow Word!, 表示运行成功,否则请查看php错误日志; |