Skip to content

Instantly share code, notes, and snippets.

@Amamatthew
Amamatthew / index_bk.php
Last active October 2, 2017 11:17
crypto-js前端加密+php后端解密(相同页面,随机秘钥)
<?php
session_start();
/** PBKDF2 Implementation (as described in RFC 2898);
*
* @param string p password
* @param string s salt
* @param int c iteration count (use 1000 or higher)
* @param int kl derived key length
* @param string a hash algorithm
*
@Amamatthew
Amamatthew / Factory.php
Last active August 3, 2017 13:52
Factory工厂模式具有为您创建对象的某些方法, 可以使用工厂类创建对象,而不直接使用 new。
<?php
//IUser 接口定义用户对象应执行什么操作。IUser 的实现称为 User
interface IUser
{
function getName();
}
class User implements IUser
{
public function __construct( $id ) { }
@Amamatthew
Amamatthew / get_called_class.php
Last active August 1, 2017 01:32
get_called_class返回调用该方法的类名
<?php
//返回调用该方法的类名
class Father{
public function demo1(){
return get_called_class();
}
public static function demo2(){
return get_called_class();
}
@Amamatthew
Amamatthew / get_class.php
Last active August 1, 2017 01:28
get_class()返回方法类名称
<?php
//创建父类:Father
//方法返回定义该方法的类名
class Father{
public function demo1(){
return get_class();
}
public static function demo2(){
@Amamatthew
Amamatthew / statics.php
Last active July 27, 2017 10:22
ThinkPHP5.0数据模型静态方法获取字段值:value方法
<?php
namespace app\index\controller;
//导入模型类
use app\index\model\Staff;
class Index {
public function index(){
//模型静态调用【数据库查询方法】
@Amamatthew
Amamatthew / tp5_staff.php
Created July 27, 2017 09:27
通过主键查询获取数据对象元素数组
<?php
namespace app\index\controller;
use app\index\model\Staff;
class Index {
public function index(){
//1.执行查询,返回数据对象数组
$result = Staff::all('1009,1010');
@Amamatthew
Amamatthew / Index.php
Last active July 27, 2017 08:25
ThinkPHP数据模型及数据对象
<?php
namespace app\index\controller;
use app\index\model\Staff;
class Index {
public function index(){
/*
1.创建$data数组
$data['id'] = 10;
@Amamatthew
Amamatthew / parse_ini_file.php
Created July 2, 2017 09:06
解析INI文件
<?php
//array parse_ini_file ( string $filename [, bool $process_sections = false [, int $scanner_mode = INI_SCANNER_NORMAL ]] )
// Parse without sections
$ini_array = parse_ini_file("sample.ini");
print_r($ini_array);
// Parse with sections
$ini_array = parse_ini_file("sample.ini", true);
print_r($ini_array);
@Amamatthew
Amamatthew / sample.ini
Created July 2, 2017 09:02
ini配置文件范例
; This is a sample configuration file
; Comments start with ';', as in php.ini
[first_section]
one = 1
five = 5
animal = BIRD
[second_section]
path = "/usr/local/bin"
@Amamatthew
Amamatthew / getTeamByChief.php
Last active June 29, 2017 06:09
多级表的迭代查询
<?php
/**
* 根据主管获取业务员所在团队区域
* @param string $chief 主管
* @return string 区域
*/
public function getTeamByChief($chief)
{
$where = [
"user"=>$chief,