本文整理匯總了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());
}
}