本文整理汇总了PHP中CApp类的典型用法代码示例。如果您正苦于以下问题:PHP CApp类的具体用法?PHP CApp怎么用?PHP CApp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CApp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __callStatic
/**
* Магический метод получения любых классов
*
* @param $name
* @param array $params
* @throws Exception
*/
public static function __callStatic($name, $params = array())
{
/**
* Получаем имя класса из имени функции
*/
$className = "C" . CUtils::strRight($name, "get");
if (!class_exists($className)) {
throw new Exception("В приложении не объявлен класс " . $className);
}
/**
* @var CActiveModel $simpleClass
*/
$simpleClass = new $className();
$table = $simpleClass->getRecord()->getTable();
$id = $params[0];
/**
* Попробуем сначала получить из кэша
*/
$keySeek = $table . "_" . $id;
if (CApp::getApp()->cache->hasCache($keySeek)) {
return CApp::getApp()->cache->get($keySeek);
}
$ar = CActiveRecordProvider::getById($table, $id);
if (!is_null($ar)) {
$obj = new $className($ar);
CApp::getApp()->cache->set($keySeek, $obj, 60);
return $obj;
}
}
示例2: linkCss
public static function linkCss($link)
{
if (strstr($link, 'css/') == 0) {
$link = CApp::settings("APPLICATION")->template_path . $link;
}
return '<link href="' . $link . '" type="text/css" rel="stylesheet">';
}
示例3: run
public function run()
{
$this->ts = time();
$this->plat = CApp::app()->tty()->getParam('plat', 1);
$this->action = CApp::app()->tty()->getParam('action', 'exchange');
$this->auto = CApp::app()->tty()->getParam('auto');
$this->begin_ts = strtotime(CApp::app()->tty()->getParam('begin', date('Y-m-d H:i:s', $this->ts - $this->timeSlice)));
$this->end_ts = strtotime(CApp::app()->tty()->getParam('end', date('Y-m-d H:i:s', $this->ts)));
//自动补数据(补单)
if ($this->auto) {
$this->begin_ts = strtotime(date('Ymd', strtotime("-1 day")) . ' 00:00:00');
$this->end_ts = strtotime(date('Ymd', strtotime("-1 day")) . ' 23:59:59');
}
//不能跨月 否则取当天时间
if (date('Ym', $this->begin_ts) != date('Ym', $this->end_ts)) {
$this->end_ts = strtotime(date('Ymd', $this->begin_ts) . ' 23:59:59');
$this->flag = false;
}
/*
if ($this->action == 'union_exchange')
{
$this->op_id = CApp::app()->tty()->getParam('op_id');
}
*/
if (!array_key_exists($this->plat, $this->curl)) {
die('Error plat!');
}
$this->handleData();
}
示例4: __construct
public function __construct()
{
$_dbConf = CApp::app()->getConf('Db');
foreach ($_dbConf as $identify => $conf) {
$this->_Db[$identify] = CDb::createDb($conf['host'], $conf['user'], $conf['pwd'], $conf['dbName']);
}
}
示例5: createApplication
/**
* Синглтон приложения
*
* @static
* @param array $config
* @return CApp
*/
public static function createApplication(array $config)
{
if (is_null(self::$_inst)) {
self::$_inst = new CApp($config);
}
return self::$_inst;
}
示例6: connect
/**
* Connect to a AS400 DB2 SQL server via ODBC driver
*
* @throws Error on misconfigured or anavailable server
*
* @return void
*/
static function connect()
{
if (self::$dbh) {
return;
}
$config = CAppUI::conf("sante400");
if (null == ($dsn = $config["dsn"])) {
trigger_error("Data Source Name not defined, please configure module", E_USER_ERROR);
CApp::rip();
}
// Fake data source for chrono purposes
CSQLDataSource::$dataSources[$dsn] = new CMySQLDataSource();
$ds =& CSQLDataSource::$dataSources[$dsn];
$ds->dsn = $dsn;
self::$chrono =& CSQLDataSource::$dataSources[$dsn]->chrono;
self::$chrono->start();
$prefix = $config["prefix"];
try {
self::$dbh = new PDO("{$prefix}:{$dsn}", $config["user"], $config["pass"]);
self::$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
mbTrace("cauguht failure on first datasource");
if (null == ($dsn = $config["other_dsn"])) {
throw $e;
}
self::$dbh = new PDO("{$prefix}:{$dsn}", $config["user"], $config["pass"]);
self::$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
self::$chrono->stop("connection");
self::traceChrono("connection");
}
示例7: swapPratIds
/**
* Change prat usernames to prat ids
*
* @return bool
*/
protected function swapPratIds()
{
$ds = CSQLDataSource::get("std");
CApp::setTimeLimit(1800);
$user = new CUser();
// Changement des chirurgiens
$query = "SELECT id_chir\r\n FROM plagesop\r\n GROUP BY id_chir";
$listPlages = $ds->loadList($query);
foreach ($listPlages as $plage) {
$where["user_username"] = "= '" . $plage["id_chir"] . "'";
$user->loadObject($where);
if ($user->user_id) {
$query = "UPDATE plagesop\r\n SET chir_id = '{$user->user_id}'\r\n WHERE id_chir = '{$user->user_username}'";
$ds->exec($query);
$ds->error();
}
}
//Changement des anesthésistes
$query = "SELECT id_anesth\r\n FROM plagesop\r\n GROUP BY id_anesth";
$listPlages = $ds->loadList($query);
foreach ($listPlages as $plage) {
$where["user_username"] = "= '" . $plage["id_anesth"] . "'";
$user->loadObject($where);
if ($user->user_id) {
$query = "UPDATE plagesop\r\n SET anesth_id = '{$user->user_id}'\r\n WHERE id_anesth = '{$user->user_username}'";
$ds->exec($query);
$ds->error();
}
}
return true;
}
示例8: getSetting
/**
* Получить настройку по псевдониму или ключевому полю
*
* @param $key
* @return CSetting
*/
public static function getSetting($key)
{
if (is_string($key)) {
$key = strtoupper($key);
}
$cacheKey = CACHE_APPLICATION_SETTINGS . '_' . $key;
if (!CApp::getApp()->cache->hasCache($cacheKey)) {
$found = false;
if (is_string($key)) {
foreach (CActiveRecordProvider::getWithCondition(TABLE_SETTINGS, "UPPER(alias) = '" . $key . "'")->getItems() as $item) {
$found = true;
$setting = new CSetting($item);
CApp::getApp()->cache->set(CACHE_APPLICATION_SETTINGS . '_' . $setting->getId(), $setting);
CApp::getApp()->cache->set($cacheKey, $setting);
}
} elseif (is_numeric($key)) {
$item = CActiveRecordProvider::getById(TABLE_SETTINGS, $key);
if (!is_null($item)) {
$found = true;
$setting = new CSetting($item);
CApp::getApp()->cache->set(CACHE_APPLICATION_SETTINGS . '_' . $setting->alias, $setting);
CApp::getApp()->cache->set($cacheKey, $setting);
}
}
if (!$found) {
CApp::getApp()->cache->set($cacheKey, null);
}
}
return CApp::getApp()->cache->get($cacheKey);
}
示例9: mine
static function mine($parent_class)
{
$classes = CApp::getChildClasses($parent_class);
$limit = CAppUI::conf("dataminer_limit");
foreach ($classes as $_class) {
$miner = new $_class();
$report = $miner->mineSome($limit, "mine");
$dt = CMbDT::dateTime();
echo "<{$dt}> Miner: {$_class}. Success mining count is '" . $report["success"] . "'\n";
if (!$report["failure"]) {
echo "<{$dt}> Miner: {$_class}. Failure mining counts is '" . $report["failure"] . "'\n";
}
$miner = new $_class();
$report = $miner->mineSome($limit, "remine");
$dt = CMbDT::dateTime();
echo "<{$dt}> Reminer: {$_class}. Success remining count is '" . $report["success"] . "'\n";
if (!$report["failure"]) {
echo "<{$dt}> Reminer: {$_class}. Failure remining counts is '" . $report["failure"] . "'\n";
}
$miner = new $_class();
$report = $miner->mineSome($limit, "postmine");
$dt = CMbDT::dateTime();
echo "<{$dt}> Postminer: {$_class}. Success postmining count is '" . $report["success"] . "'\n";
if (!$report["failure"]) {
echo "<{$dt}> Postminer: {$_class}. Failure postmining counts is '" . $report["failure"] . "'\n";
}
}
}
示例10: init
/**
* @see parent::init()
*/
function init()
{
if (!CMbPath::forceDir($this->dir)) {
trigger_error("Shared memory could not be initialized, ensure that '{$this->dir}' is writable");
CApp::rip();
}
return true;
}
示例11: update
public function update($arrayNewTranslate, $arrayOldTranslate)
{
$arrDiff = array_diff($arrayNewTranslate, $arrayOldTranslate);
$arrIntersect = array_intersect($arrayNewTranslate, $arrayOldTranslate);
$arrResult = array_merge($arrDiff, $arrIntersect);
CApp::setTranslateArray($arrResult);
return $arrResult;
}
示例12: __construct
/**
* CMbSemaphore Constructor
*
* @param string $key semaphore identifier
*/
function __construct($key)
{
$this->path = CAppUI::conf("root_dir") . "/tmp/locks";
CMbPath::forceDir($this->path);
$this->process = getmypid();
$prefix = CApp::getAppIdentifier();
$this->key = "{$prefix}-sem-{$key}";
}
示例13: __construct
/**
* Construct
*
* @param string $key lock identifier
*/
function __construct($key)
{
$this->path = CAppUI::conf("root_dir") . "/tmp/locks";
$this->process = getmypid();
$prefix = CApp::getAppIdentifier();
$this->key = "{$prefix}-lock-{$key}";
$this->filename = "{$this->path}/{$this->key}";
CMbPath::forceDir(dirname($this->filename));
}
示例14: doStore
/**
* @see parent::doStore()
*/
function doStore()
{
if (isset($_FILES['attachment'])) {
$mail_id = CValue::post('mail_id');
$mail = new CUserMail();
$mail->load($mail_id);
$files = array();
foreach ($_FILES['attachment']['error'] as $key => $file_error) {
if (isset($_FILES['attachment']['name'][$key])) {
$files[] = array('name' => $_FILES['attachment']['name'][$key], 'tmp_name' => $_FILES['attachment']['tmp_name'][$key], 'error' => $_FILES['attachment']['error'][$key], 'size' => $_FILES['attachment']['size'][$key]);
}
}
foreach ($files as $_key => $_file) {
if ($_file['error'] == UPLOAD_ERR_NO_FILE) {
continue;
}
if ($_file['error'] != 0) {
CAppUI::setMsg(CAppUI::tr("CFile-msg-upload-error-" . $_file["error"]), UI_MSG_ERROR);
continue;
}
$attachment = new CMailAttachments();
$attachment->name = $_file['name'];
$content_type = mime_content_type($_file['tmp_name']);
$attachment->type = $attachment->getTypeInt($content_type);
$attachment->bytes = $_file['size'];
$attachment->mail_id = $mail_id;
$content_type = explode('/', $content_type);
$attachment->subtype = strtoupper($content_type[1]);
$attachment->disposition = 'ATTACHMENT';
$attachment->extension = substr(strrchr($attachment->name, '.'), 1);
$attachment->part = $mail->countBackRefs('mail_attachments') + 1;
$attachment->store();
$file = new CFile();
$file->setObject($attachment);
$file->author_id = CAppUI::$user->_id;
$file->file_name = $attachment->name;
$file->file_date = CMbDT::dateTime();
$file->fillFields();
$file->updateFormFields();
$file->doc_size = $attachment->bytes;
$file->file_type = mime_content_type($_file['tmp_name']);
$file->moveFile($_file, true);
if ($msg = $file->store()) {
CAppUI::setMsg(CAppUI::tr('CMailAttachments-error-upload-file') . ':' . CAppUI::tr($msg), UI_MSG_ERROR);
CApp::rip();
}
$attachment->file_id = $file->_id;
if ($msg = $attachment->store()) {
CAppUI::setMsg($msg, UI_MSG_ERROR);
CApp::rip();
}
}
CAppUI::setMsg('CMailAttachments-msg-added', UI_MSG_OK);
} else {
parent::doStore();
}
}
示例15: deleteAction
public function deleteAction($id)
{
if ($_SESSION["userRole"] == CApp::settings("USER_ROLES")->ADMIN && $_GET["view"] == "delete" && !empty($_GET["id"])) {
$model = new UserModel();
$model->deleteById($id);
CApp::redirect(CApp::getLink(array("controller" => "user", "view" => "index")));
} else {
CApp::redirect("/");
}
}