php编写的简单mvc框架
- 框架简单易学,内部引用类均是作者多年积累的实用函数
- 框架已经在多个中小型项目中使用,比较成熟
- 框架封装比较简洁,适合入门者学习研究使用
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/iyifei/myfmvc.git"
}
],
"config": {
"secure-http": false
},
"require": {
"iyifei/myfmvc": "dev-master"
}
}
进入根目录执行 composer install
db.config.php
<?php
/**
* 数据库配置
*/
return array(
//数据库链接配置
'database' => array(
'default' => array(
'host' => 'localhost',
'port' => '3306',
'username' => 'root',
'password' => '123456',
'dbname' => 'myfmvc',
'charset' => 'utf8',
'prefix' => ''
),
),
//默认db
'default_db' => 'default',
);
namespace.config.php
<?php
/**
* 命名空间配置文件
*/
return [
'autoload'=>[
"Common\Model" => SYS_PATH . "/Common/Model",
]
];
<?php
/**
* 入口文件
* User: myf
* Date: 2017/12/28
* Time: 11:44
*/
define('APP_PATH', __DIR__.'/');
define("SYS_PATH",dirname(APP_PATH));
define('COMMON_PATH', SYS_PATH.'/Common/');
define('OP_CONF_DIR','/data/www/opconfig/');
require_once SYS_PATH.'/vendor/autoload.php';
server {
listen 80;
server_name mvc.myf.cn;
root /data/www/myfmvc-demo/App;
index index.php index.html index.htm;
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?_url=$1 last;
break;
}
}
location ~ \.php$ {
include /usr/local/etc/nginx/fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
}
}
<?php
namespace Controller;
use Common\Model\UserModel;
use Myf\Libs\Controller;
/**
* demo
*/
class IndexController extends Controller
{
public function indexAction(){
echo "hello world";
}
public function testAction(){
$this->assign('title',"MyfMVC DEMO");
$userModel = new UserModel();
$users = $userModel->findAll();
$this->assign('users',$users);
$this->display();
}
}
进入App目录,执行 php index.php test/abc