PHP code example of hisune / tinymvc

1. Go to this page and download the library: Download hisune/tinymvc library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hisune / tinymvc example snippets


\Tiny\Config::$application = 'demo';
\Tiny\Config::$configDir = __DIR__ . '/../config/';
\Tiny\Config::$varDir = __DIR__ . '/../var/';
\Tiny\Config::$viewDir = __DIR__ . '/../view/';
\Tiny\Config::$controller = array('Controller', 'app/Controller');
register_shutdown_function(array('\Tiny\Exception', 'fatal'));

return array(
    'debug' => false, // 是否开启调试模式
    'flag' => 'xxoo', // session唯一标识
    'show_error' => false, // 是否显示错误
    'timezone' => 'PRC', // 时区
    'token' => false, // 自动加token
    'database' => array(
        'dns' => "mysql:host=127.0.0.1;port=3306;dbname=recharge;charset=UTF8", // 主从分离用逗号','隔开
        'username' => 'root',
        'password' => '',
        'prefix' => '',
        'separate' => false, // 主从分离
        'rand_read' => false, // 随机读取
        'log_queries' => false, // 是否记录所有请求
    ),
);

return array(
    // 路由配置
    'routes' => array(
        'admin' => 'admin', // 方式1,子模块模式
        'page/{id}' => function($id){ // 方式2,直接处理数据
            echo md5($id);
        },
        '{num}' => function ($num, &$controller, &$method, &$pathInfo) { // 方式3:指定c,m,p
            $controller = 'Index';
            $method = 'index';
            $pathInfo = array($num);
        },
        'param/{param?}' => function ($param, &$controller, &$method, &$pathInfo) { // 例:最后一个参数可不传递, 用'?'
            $controller = 'Index';
            $method = 'test';
            $pathInfo = array($param);
        },
    ),
    // 路由匹配后的正则配置
    'pattern' => array(
        'num' => '[0-9]+',
        'param' => '[0-9]*',
    ),
);

 $orders = new model\Orders;
 $orders
     ->alias('o') // 或者用 ->table('__ORDERS__ o')
     ->field('o.order, o.id')
     ->order('? desc', array('o.id'))
     ->where('o.id = ? or o.order = "?"',array("5' and 1=2 union select * from user where id=1/*")) //注入测试
     ->limit('1/*,1') // limit强制整型测试
     ->join('__TEST__ t on t.id = o.test_id', 'left')
     ->group('?', array('o.order'))
     ->having('count(*) > ?', array('1'))
     ->find() // find()无参数

 findOne([int $id]) // R,指定id为where条件
 save([array $data], [boolean $replace]) // C
 update([array $data], [boolean $all]) // U,慎用all
 delete([int $id], [boolean $all]) // D,慎用all
 increment(string $column, [int $value]);
 query(string $sql, [array $param], [boolean $fetchAll])
 execute(string $sql, [array $param])

 count([string $column])
 max([string $column])
 avg([string $column])
 min([string $column])
 sum([string $column])
 distinct([string $column])

field() //第一参数支持array,第一参数为array时,不支持别名,别名用string
where() //第一参数支持array,此时第二参数无效;第一参数为array时,不支持别名,别名请用string;只支持绑定条件变量。
limit() //支持string类似,limit('0, 10'),或双参数类似,limit(0, 10)