Coder Social home page Coder Social logo

fastphp's Introduction

FastPHP

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

简述

fastphp是一款简单的PHP MVC框架,目的是方便学习《手把手编写自己的PHP MVC框架》教程的同学下载源代码,详细介绍请参考网站:http://www.awaimai.com/128.html

要求:

  • PHP 5.4.0+

目录说明

project                 根目录
├─app                   应用目录
│  ├─controllers        控制器目录
│  ├─models             模块目录
│  ├─views              视图目录
├─config                配置文件目录
├─fastphp               框架核心目录
├─static                静态文件目录
├─index.php             入口文件

使用

1.安装

主要介绍通过composer和git两种安装方法,选择其一即可。

方法1:Composer安装(推荐)

composer create-project yeszao/fastphp project --no-dev

其中,--no-dev表示不安装-dev依赖包(PHPUnit)。

方法2:Github安装:

git clone https://github.com/yeszao/fastphp.git project

说明:这两个命令都会创建并将代码安装到project目录。

2. 创建数据库

在数据库中创建名为 project 的数据库,并插入两条记录,命令:

CREATE DATABASE `project` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE `project`;

CREATE TABLE `item` (
    `id` int(11) NOT NULL auto_increment,
    `item_name` varchar(255) NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
 
INSERT INTO `item` VALUES(1, 'Hello World.');
INSERT INTO `item` VALUES(2, 'Lets go!');

3.修改数据库配置文件

打开配置文件 config/config.php ,使之与自己的数据库匹配

$config['db']['host'] = 'localhost';
$config['db']['username'] = 'root';
$config['db']['password'] = '123456';
$config['db']['dbname'] = 'project';

4.配置Nginx或Apache

在Apache或Nginx中创建一个站点,把 project 设置为站点根目录(入口文件 index.php 所在的目录)。

然后设置单一入口, Apache服务器配置:

<IfModule mod_rewrite.c>
    # 打开Rerite功能
    RewriteEngine On

    # 如果请求的是真实存在的文件或目录,直接访问
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    # 如果访问的文件或目录不是真事存在,分发请求至 index.php
    RewriteRule . index.php
</IfModule>

Nginx服务器配置:

location / {
    # 重新向所有非真实存在的请求到index.php
    try_files $uri $uri/ /index.php$args;
}

5.测试访问

然后访问站点域名:http://localhost/ 就可以了。

fastphp's People

Contributors

lixworth avatar yeszao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fastphp's Issues

fastphp/fastphp/base/Model.php line16

get_class($this) 获取到的是完整的包括命名空间在内的类名,如根据 UsersModel 获取到的是 app\models\usersmodel

应该改为 explode('\\', get_called_class())[2],需要切分字符串,才能获得 usermodel

Fastphp.php 第87行 无法传递多个参数

Fastphp.php 第87行
call_user_func_array(array($dispatch, $actionName), $param);//无法传递多个参数。
更正为
call_user_func_array(array($dispatch, $actionName), array($param));

自己建立的表,然后手动添加数据后,查询不出来

问题出现过程:
1、程序git下来了,根据自己的需求修改了个别部分代码
2、自己建立的数据库表,然后手动添加数据后,查询不出来,添加数据也添加不成功

查询数据控制器函数

public function index()
    {
        $list = $this->db->fetchAll();

        $res = [
            'code' => '1',
            'msg' => '操作成功',
            'data' => $list
        ];

        echo json_encode($res);
    }

添加数据函数

    public function add()
    {
        $data = $_POST['data'];
        // 这里接受的数据正常,是前台post过来的数据
        // var_dump($data); 

        $count =  $this->db->add($data);

        $res = [
            'code' => '1',
            'msg' => '操作成功',
            'data' => $count
        ];

        echo json_encode($res);
    }

很疑惑,不知道是什么问题;
添加你QQ了,麻烦通过一下。

对于不会操作“站点根目录配置到fastphp目录” 出现控制器不存在的解决思路

我知道很多免费空间没有配置站点根目录的操作权限
或者难得有一个站点,想把多个子目录利用起来的菜鸟们
运行下载的fastphp时,总会出现控制器不存在的问题

其实就是url字段出现了一个应用目录名称。
我有一个不成熟的解决思路(当然,我知道把应用目录列为站点根目录可以防止网站侵入,但fastphp的index.php并没有如TP5那样放在public目录中,所以有了现在这个思路)

在index.php中增加

// fastphp 为应用目录名
define('APP_NAME', '/fastphp');

然后再核心文件fastphp.php中调整路由函数

public function route()
    {
      .......
      $url = $_SERVER['REQUEST_URI']; 

        //用到了子目录名称"fastphp" 所以自己需要把这个删除掉 
        //在入口文件中定义了 APP_NAME
        $url = substr($url, strlen(APP_NAME));

这样在访问localhost/fastphp/index.php?{controller}/{action}就可以成功了

需要补充的是,对view中的视图
请把相关地址 增加“/fastphp”内容
如把href="/item/index"修改为
href="/fastphp/item/index"

这样才运行有效

感谢作者,一个极简的MVC phpframwork
学到很多

nginx location的问题

hello 歪麦
nginx location 好像有点问题,某些页面下,搜索功能无法正常使用。
需更正为:try_files $uri $uri/ /index.php?$query_string;

CSS中的错误stati文件夹

您好我注意到,当我输入URL时,框架中存在/static/css/main.css文件中的错误返回以下错误:

app \ controllers \ StaticControllerController不存在

我怎么解决这个问题?

谢谢。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.