本文整理汇总了PHP中herosphp\core\Loader类的典型用法代码示例。如果您正苦于以下问题:PHP Loader类的具体用法?PHP Loader怎么用?PHP Loader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Loader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* 初始化数据库连接
* @param string $table 数据表
* @param array $config 数据库配置信息
*/
public function __construct($table, $config = null)
{
//加载数据表配置
$dbConfigPath = 'db';
if (DB_CFG_PATH != false) {
$dbConfigPath = DB_CFG_PATH;
}
$tableConfig = Loader::config('table', $dbConfigPath);
$this->table = $tableConfig[$table];
//初始化数据库配置
if (!$config) {
//默认使用第一个数据库服务器配置
$dbConfigs = Loader::config('hosts', $dbConfigPath);
$db_config = $dbConfigs[DB_TYPE];
if (DB_ACCESS == DB_ACCESS_SINGLE) {
//单台服务器
$config = $db_config[0];
} else {
if (DB_ACCESS == DB_ACCESS_CLUSTERS) {
//多台服务器
$config = $db_config;
}
}
}
//创建数据库
$this->db = DBFactory::createDB(DB_ACCESS, $config);
}
示例2: index
public function index(HttpRequest $request)
{
print_r($request->getParameter());
////----DB 操作
//DB: 原生query操作
$model = Loader::model('user');
$result = $model->query("select * from user");
$rowArr = $result->fetchAll();
print_r($rowArr);
//DB: 查询
//DB: 插入
/*
$data = array(
"id" => "",
"name" => "xm"
);
$model->insert($data);
*/
//DB: 更新
$data = array("id" => "12", "name" => "yy");
$id = 2;
$model->update($data, $id);
//DB: 删除
$id = 1;
$model->delete($id);
//DB: 事物
$items = array("id" => 1, "title" => "hello title2");
$this->assign('items', $items);
$this->assign('var1', "yu");
//$this->display('index_test2');//这里不要用display这个方法,流程不对,用view
$this->setView('index_test');
//die();
}
示例3: run
public function run()
{
tprintOk("Hello, world!");
$model = Loader::model('article');
$conditions = array("id" => ">300");
$items = $model->getItems($conditions, "id, url, title", null, 1, 20);
tprintOk($items[0]['title']);
}
示例4: delete
/**
* @param HttpRequest $request
*/
public function delete(HttpRequest $request)
{
$id = $request->getParameter('id', 'intval');
$model = Loader::model('article');
if ($id > 0) {
var_dump($model->delete($id));
}
die;
}
示例5: __construct
/**
* 初始化数据库连接
* @param string $table 数据表
* @param array $config 数据库配置信息
*/
public function __construct($table, $config = null)
{
//初始化数据库配置
if (!$config) {
$congfig = Loader::config('db');
}
//创建数据库
$this->db = DBFactory::createDB('mongo', $congfig['mongo']);
$this->table = $table;
}
示例6: createDB
/**
* 创建数据库连接实例
* @param int $accessType 连接方式(连接单个服务器还是连接集群)
* @param array $config 数据库的配置信息
* @return Idb
*/
public static function createDB($accessType = DB_ACCESS_SINGLE, &$config = null)
{
//获取包含路径
$classPath = self::$DB_DRIVER[$accessType]['path'];
Loader::import($classPath, IMPORT_FRAME);
$className = self::$DB_DRIVER[$accessType]['class'];
$key = md5($className . $config['flag']);
if (!isset(self::$DB_POOL[$key])) {
self::$DB_POOL[$key] = new $className($config);
}
return self::$DB_POOL[$key];
}
示例7: getInstance
/**
* @return bool|null|\Redis
*/
public static function getInstance()
{
if (is_null(self::$redis)) {
$configs = Loader::config('redis', 'cache');
if (!$configs) {
return false;
}
self::$redis = new \Redis();
self::$redis->connect($configs['host'], $configs['port']);
}
return self::$redis;
}
示例8: permission
/**
* 更改角色权限
* @param HttpRequest $request
*/
public function permission(HttpRequest $request)
{
$id = $request->getParameter('id', 'intval');
if ($id <= 0) {
$this->showMessage('danger', '参数不合法!');
}
$service = Beans::get($this->getServiceBean());
$item = $service->getItem($id);
$permissions = cn_json_decode($item['permissions']);
//加载权限选项
$permissionOptions = Loader::config('admin', 'permission');
$this->assign('permissions', $permissions);
$this->assign('permissionOptions', $permissionOptions);
$this->assign('item', $item);
$this->setView('admin/role_permission');
}
示例9: create
/**
* 创建缓存
* @param $key
* @param bool $single 是否单例模式
* @return \herosphp\cache\interfaces\ICache
*/
public static function create($key = 'file', $single = true)
{
//如果缓存对象已经创建,则则直接返回
if (isset(self::$CACHE_SET[$key]) && $single == false) {
return self::$CACHE_SET[$key];
}
$configs = Loader::config($key, 'cache');
$className = self::$CACHE_BEAN[$key]['class'];
Loader::import(self::$CACHE_BEAN[$key]['path'], IMPORT_FRAME);
if ($single) {
self::$CACHE_SET[$key] = new $className($configs);
return self::$CACHE_SET[$key];
} else {
return $className($configs);
}
}
示例10: get
/**
* 获取指定ID的Bean
* @param string $key Bean的key
* @param boolean $new 是否创建新的bean,新创建的Bean不会放到容器中,如果要放到容器中,请使用set方法。
* @return Object 返回指定ID的Bean,如果Bean不存在则返回null
*/
public static function get($key, $new = false)
{
if (empty(self::$CONFIGS)) {
self::$CONFIGS = Loader::config('*', 'beans');
if (!self::$CONFIGS) {
return null;
}
}
$beanConfig = self::$CONFIGS[$key];
if ($new || $beanConfig['@single'] === false) {
return self::build($beanConfig);
}
if (!isset(self::$BEAN_POOL[$key])) {
self::$BEAN_POOL[$key] = self::build($beanConfig);
}
return self::$BEAN_POOL[$key];
}
示例11: run
public function run()
{
// $lock = SynLockFactory::getFileSynLock(0x1234);
// tprintError("try to get the lock....");
// $lock->tryLock();
// tprintOk("get the lock.");
// sleep(10);
// tprintWarning("release the lock.");
// $lock->unlock();
$model = Loader::model("news");
$timer = timer();
for ($i = 0; $i < 1000000; $i++) {
$data = array('name' => 'xiaoming', 'pass' => 'xiaoming_pass', 'address' => 'china ShenZhen');
$model->insert($data);
}
tprintOk("插入完成,耗时:" . (timer() - $timer) . " 秒");
}
示例12: start
/**
* 开启session
*/
public static function start()
{
//如果已经开启了SESSION则直接返回
if (isset($_SESSION)) {
return true;
}
//loading session configures
$configs = Loader::config('session', 'session');
switch (SESSION_HANDLER) {
case 'file':
FileSession::start($configs[SESSION_HANDLER]);
break;
case 'memo':
MemSession::start($configs[SESSION_HANDLER]);
break;
}
}
示例13: html
public function html(HttpRequest $request)
{
$CACHER = CacheFactory::create('html');
$CACHER->baseKey('article')->ftype('detail')->factor('299');
$item = $CACHER->get(null);
if (!$item) {
$model = Loader::model('article');
$item = $model->getItem(299);
$this->assign('item', $item);
$html = $this->getExecutedHtml();
if ($CACHER->set(null, $html)) {
__print("生成静态缓存成功!");
}
} else {
echo $item;
}
die;
}
示例14: edit
/**
* 编辑媒体管理员角色界面
* @param HttpRequest $request
*/
public function edit(HttpRequest $request)
{
parent::edit($request);
$item = $this->getTemplateVar('item');
//获取媒体类型
$mediaTypeService = Beans::get('media.type.service');
$mediaType = $mediaTypeService->getItem($item['media_type']);
$permissionTpl = $mediaType['permission_tpl'];
//加载权限选项
$permissions = Loader::config($permissionTpl, 'permission');
$this->assign('permissions', $permissions);
$item['permission'] = cn_json_decode($item['permission']);
$this->assign('item', $item);
$this->assign("seoTitle", "媒体中心后台管理-角色编辑");
$this->assign("seoDesc", "角色管理-角色编辑");
$this->assign("seoKwords", "媒体中心后台管理 角色管理 角色编辑");
$this->setView('role/add');
}
示例15: builtInstance
/**
* 创建Bean实例
* @param string $classPath 要创建的对象的类路径
* @param array $params 参数列表,可以是数组或者单个参数
* @return object|ReflectionClass
* @throws \Exception
*/
public static function builtInstance($classPath, $params = null)
{
if (!is_string($classPath)) {
return null;
}
try {
$importPath = str_replace('\\', '.', $classPath);
Loader::import($importPath, IMPORT_APP, EXT_PHP);
$instance = new ReflectionClass($classPath);
if (is_array($params)) {
return $instance->newInstanceArgs($params);
} elseif ($params) {
return $instance->newInstance($params);
} else {
return $instance->newInstance();
}
} catch (\Exception $e) {
E($e->getMessage());
}
}