1、sql查询文件缓存使用
$tokens = DB::select('id', 'token') ->from('member') ->where('id', 'in', $users) ->cached(120) ->execute() ->as_array();
文件缓存的思路:采用sha($sql)的方法确定缓存key,value为serialize($result),expire通过time()-filemtime($file)实现。文件名作为key,优化方案,可以取key前2位分目录存放缓存文件。
root@DESKTOP-I4OIMJC /cygdrive/e/html/tproject/framebota/runtime/com.bota.work/cache/2b # ll 总用量 1.0K ----------+ 1 root ???????? 322 6月 5 18:55 2bdb17d58721d378bfec480a7434f2716fdd04c1.txt
2、kohana配置文件读取
$config = Kohana::$config->load('vendor\tongcheng\config');
E:\html\tproject\framebota\platform\config\database.php
$config = Kohana::$config->load('database')->default
E:\html\tproject\framebota\service\flight\config\flight.php
$conf = Kohana::$config->load('flight');
3、kohana加载文件
E:\html\tproject\framebota\platform\config\vendor\tongcheng\config.php
$config = array(); $files = Kohana::find_file('config', 'vendor/tongcheng/config', NULL, TRUE); foreach ($files as $file){ // Merge each file to the configuration array $config = Arr::merge($config, Kohana::load($file)); }
<?php require_once Kohana::find_file('views', 'Train/Common/ordersearch');?>
4、kohana日志记录、日志存放framebota\runtime\com.bota.work\logs\2019\06
Kohana::$log->add(Log::DEBUG, __FILE__."\t".__LINE__."\t\t\t" . var_export($list, true));
5、kohana公共辅助函数
E:\html\tproject\framework\modules\common\classes\Common\HELP.php
HELP::isMobile($keyword)
6、kohana参数验证类函数
E:\html\tproject\framework\system\classes\Valid.php
E:\html\tproject\framework\system\classes\Kohana\Valid.php
Valid::date("2019-06-04 14:51:00")
7、Javascript同名方法或对象同名原型方法,后定义的覆盖前面的使用
String.prototype.StartsWith = function(str) { return this.substr(0, str.length) !== str; } String.prototype.StartsWith = function(str) { return this.substr(0, str.length) == str; } function sss(){ console.log("sss"); } function sss(){ console.log("aaa"); } sss() console.log("liuchao".StartsWith("liu")); 输出 aaa true
8、php类构造方法__construct
class Bar { public function __construct() { print "In BaseClass constructor\n"; } public function Bar() { print "In Bar\n"; // treated as constructor in PHP 5.3.0-5.3.2 // treated as regular method as of PHP 5.3.3 } }
说明:创建Bar对象时候,__construct跟类同名方法都存在,调用__construct,Bar方法此时候不执行,如果__construct没显示定义,则调用类同名方法Bar。
自 PHP 5.3.3 起,在命名空间中,与类名同名的方法不再作为构造函数。这一改变不影响不在命名空间中的类。
namespace Foo; class Bar { public function Bar() { print "In Bar\n"; // treated as constructor in PHP 5.3.0-5.3.2 // treated as regular method as of PHP 5.3.3 } }