Skip to content

Commit

Permalink
init project
Browse files Browse the repository at this point in the history
  • Loading branch information
One2r committed Jan 21, 2018
1 parent 43f3feb commit 83a27ef
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 0 deletions.
31 changes: 31 additions & 0 deletions application/Bootstrap.php
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
}
}
16 changes: 16 additions & 0 deletions application/controllers/Error.php
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
}
}
29 changes: 29 additions & 0 deletions application/controllers/Index.php
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;
}
}
1 change: 1 addition & 0 deletions application/library/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
项目库文件放在这里
18 changes: 18 additions & 0 deletions application/models/Sample.php
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;
}
}
27 changes: 27 additions & 0 deletions application/plugins/Sample.php
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) {
}
}
3 changes: 3 additions & 0 deletions application/views/error/error.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
echo "Error Msg:" . $exception->getMessage();
?>
3 changes: 3 additions & 0 deletions application/views/index/index.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
echo $content, " I am ", $name;
?>
5 changes: 5 additions & 0 deletions conf/application.ini
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]
3 changes: 3 additions & 0 deletions public/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php
8 changes: 8 additions & 0 deletions public/index.php
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();
?>
7 changes: 7 additions & 0 deletions readme.txt
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错误日志;

0 comments on commit 83a27ef

Please sign in to comment.