本文整理汇总了PHP中Yii类的典型用法代码示例。如果您正苦于以下问题:PHP Yii类的具体用法?PHP Yii怎么用?PHP Yii使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Yii类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLogger
/**
* @return Logger
*/
public function getLogger()
{
if (!isset($this->_logger)) {
$this->_logger = \Yii::getLogger();
}
return $this->_logger;
}
示例2: init
public function init()
{
parent::init();
if (!$this->items) {
throw new InvalidConfigException(\Yii::t('front', 'No required parameter given') . ' - items');
}
}
示例3: getUrlUploadMultiImages
public static function getUrlUploadMultiImages($obj, $user_id)
{
$url_arr = array();
$min_size = 1024 * 1000 * 700;
$max_size = 1024 * 1000 * 1000 * 3.5;
foreach ($obj["tmp_name"] as $key => $tmp_name) {
$ext_arr = array('png', 'jpg', 'jpeg', 'bmp');
$name = StringHelper::filterString($obj['name'][$key]);
$storeFolder = Yii::getPathOfAlias('webroot') . '/images/' . date('Y-m-d', time()) . '/' . $user_id . '/';
$pathUrl = 'images/' . date('Y-m-d', time()) . '/' . $user_id . '/' . time() . $name;
if (!file_exists($storeFolder)) {
mkdir($storeFolder, 0777, true);
}
$tempFile = $obj['tmp_name'][$key];
$targetFile = $storeFolder . time() . $name;
$ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
$size = $obj['name']['size'];
if (in_array($ext, $ext_arr)) {
if ($size >= $min_size && $size <= $max_size) {
if (move_uploaded_file($tempFile, $targetFile)) {
array_push($url_arr, $pathUrl);
} else {
return NULL;
}
} else {
return NULL;
}
} else {
return NULL;
}
}
return $url_arr;
}
示例4: run
public function run($action, $to, $id)
{
$to = CActiveRecord::model($this->getController()->CQtreeGreedView['modelClassName'])->findByPk((int) $to);
$moved = CActiveRecord::model($this->getController()->CQtreeGreedView['modelClassName'])->findByPk((int) $id);
if (!is_null($to) && !is_null($moved)) {
try {
switch ($action) {
case 'child':
$moved->moveAsLast($to);
break;
case 'before':
if ($to->isRoot()) {
$moved->moveAsRoot();
} else {
$moved->moveBefore($to);
}
break;
case 'after':
if ($to->isRoot()) {
$moved->moveAsRoot();
} else {
$moved->moveAfter($to);
}
break;
}
} catch (Exception $e) {
Yii::app()->user->setFlash('CQTeeGridView', $e->getMessage());
}
}
$this->getController()->redirect(array($this->getController()->CQtreeGreedView['adminAction']));
}
示例5: run
/**
* Run this widget.
* This method registers necessary javascript and renders the needed HTML code.
*/
public function run()
{
list($name, $id) = $this->resolveNameID();
if (isset($this->htmlOptions['id'])) {
$id = $this->htmlOptions['id'];
} else {
$this->htmlOptions['id'] = $id;
}
if (isset($this->htmlOptions['name'])) {
$name = $this->htmlOptions['name'];
} else {
$this->htmlOptions['name'] = $name;
}
if ($this->hasModel()) {
echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
} else {
echo CHtml::textField($name, $this->value, $this->htmlOptions);
}
$options = CJavaScript::encode($this->options);
$js = "jQuery('#{$id}').datepicker({$options});";
if (isset($this->language)) {
$this->registerScriptFile($this->i18nScriptFile);
$js = "jQuery('#{$id}').datepicker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['{$this->language}'], {$options}));";
}
$cs = Yii::app()->getClientScript();
$cs->registerScript(__CLASS__, $this->defaultOptions ? 'jQuery.datepicker.setDefaults(' . CJavaScript::encode($this->defaultOptions) . ');' : '');
$cs->registerScript(__CLASS__ . '#' . $id, $js);
}
示例6: run
/**
* Renders the content of the widget.
* @throws CException
*/
public function run()
{
// Hide empty breadcrumbs.
if (empty($this->links)) {
return;
}
$links = array();
if (!isset($this->homeLink)) {
$content = CHtml::link(Yii::t('zii', 'Inicio'), Yii::app()->homeUrl);
$links[] = $this->renderItem($content);
} else {
if ($this->homeLink !== false) {
$links[] = $this->renderItem($this->homeLink);
}
}
foreach ($this->links as $label => $url) {
if (is_string($label) || is_array($url)) {
$content = CHtml::link($this->encodeLabel ? CHtml::encode($label) : $label, $url);
$links[] = $this->renderItem($content);
} else {
$links[] = $this->renderItem($this->encodeLabel ? CHtml::encode($url) : $url, true);
}
}
echo CHtml::tag('ul', $this->htmlOptions, implode('', $links));
}
示例7: getPackages
/**
* Magic getter. Returns this widget's packages.
*/
public function getPackages()
{
if (!isset($this->_packages)) {
$this->_packages = array_merge(parent::getPackages(), array('TwoColumnSortableWidgetManagerJS' => array('baseUrl' => Yii::app()->request->baseUrl, 'js' => array('js/sortableWidgets/TwoColumnSortableWidgetManager.js'), 'depends' => array('SortableWidgetManagerJS'))));
}
return $this->_packages;
}
示例8: request
/**
* @param string $url
* @param string $method
* @param string $body
*
* @return FhirResponse
*/
public function request($url, $method = 'GET', $body = null)
{
$server_name = null;
foreach ($this->servers as $name => $server) {
if (substr($url, 0, strlen($server['base_url']))) {
$server_name = $name;
break;
}
}
$this->applyServerConfig($server_name ? $this->servers[$server_name] : array());
$this->http_client->setUri($url);
$this->http_client->setMethod($method);
if ($body) {
$this->http_client->setRawData($body, 'application/xml+fhir; charset=utf-8');
}
$response = $this->http_client->request();
$this->http_client->resetParameters();
if ($body = $response->getBody()) {
$use_errors = libxml_use_internal_errors(true);
$value = Yii::app()->fhirMarshal->parseXml($body);
$errors = libxml_get_errors();
libxml_use_internal_errors($use_errors);
if ($errors) {
throw new Exception("Error parsing XML response from {$method} to {$url}: " . print_r($errors, true));
}
} else {
$value = null;
}
return new FhirResponse($response->getStatus(), $value);
}
示例9: init
public function init()
{
// register class paths for extension captcha extended
Yii::$classMap = array_merge(Yii::$classMap, array('CaptchaExtendedAction' => Yii::getPathOfAlias('ext.captchaExtended') . DIRECTORY_SEPARATOR . 'CaptchaExtendedAction.php', 'CaptchaExtendedValidator' => Yii::getPathOfAlias('ext.captchaExtended') . DIRECTORY_SEPARATOR . 'CaptchaExtendedValidator.php'));
$this->search = new Search();
$this->link = new Linksite();
}
示例10: init
public function init()
{
$this->name = \Yii::t('skeeks/shop/app', 'Delivery services');
$this->modelShowAttribute = "name";
$this->modelClassName = ShopDelivery::className();
parent::init();
}
示例11: onBeforeGrid
/**
* Позволяет тонко сконфигурировать грид перед самой отрисовкой
*
* @param BeforeGridEvent $event
*/
public function onBeforeGrid(BeforeGridEvent $event)
{
if (isset(Yii::app()->controller->buttons)) {
foreach (Yii::app()->controller->buttons as $key => $buttonConfig) {
if (isset($buttonConfig['code']) && $buttonConfig['code'] == 'create') {
// Модули - типы создаваемого экземпляра
$addButtonData = null;
$phpScripts = PhpScript::model()->findAllByAttributes(array('id_php_script_interface' => PhpScript::ID_PHP_SCRIPT_INTERFACE_MODULE));
if (count($phpScripts) > 0) {
$addButtonData = '<button class="btn navbar-btn btn-success dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button>';
$addButtonData .= '<ul class="dropdown-menu">' . "\n";
foreach ($phpScripts as $phpScript) {
/**
* @var $phpScript PhpScript
*/
$linkModule = ObjectUrlRule::createUrlFromCurrent(BackendModule::ROUTE_INSTANCE_LIST, array(ObjectUrlRule::PARAM_OBJECT_INSTANCE => -1, ObjectUrlRule::PARAM_SYSTEM_MODULE => $phpScript->id_php_script_type));
$addButtonData .= "<li><a href='" . $linkModule . "'>" . $phpScript->description . "</a></li>";
}
$addButtonData .= '</ul>' . "\n";
}
$buttonConfig['addButtonData'] = $addButtonData;
Yii::app()->controller->buttons[$key] = $buttonConfig;
break;
}
}
}
}
示例12: performAjaxValidation
protected function performAjaxValidation($model)
{
if (isset($_POST['ajax']) && $_POST['ajax'] === 'create-category-form') {
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
示例13: afterSave
public function afterSave()
{
parent::afterSave();
$sql = "UPDATE p_nfy_subscription_categories " . "set category = 'role_{$this->role_name}.' " . "where category = 'role_{$this->oldName}.';";
Yii::app()->db->createCommand($sql)->execute();
return true;
}
示例14: checkAccess
public function checkAccess()
{
// Save users last action on this space
$membership = $this->space->getMembership(Yii::app()->user->id);
if ($membership != null) {
$membership->updateLastVisit();
} else {
// Super Admin can always enter
if (!Yii::app()->user->isAdmin()) {
// Space invisible?
if ($this->space->visibility == Space::VISIBILITY_NONE) {
// Not Space Member
throw new CHttpException(404, Yii::t('SpaceModule.behaviors_SpaceControllerBehavior', 'Space is invisible!'));
}
}
}
// Delete all pending notifications for this space
$notifications = Notification::model()->findAllByAttributes(array('space_id' => $this->space->id, 'user_id' => Yii::app()->user->id), 'seen != 1');
foreach ($notifications as $n) {
// Ignore Approval Notifications
if ($n->class == "SpaceApprovalRequestNotification" || $n->class == "SpaceInviteNotification") {
continue;
}
$n->seen = 1;
$n->save();
}
}
示例15: loadModel
public function loadModel($id)
{
if (($model = DictionaryGroup::model()->findByPk($id)) === null) {
throw new CHttpException(404, Yii::t('DictionaryModule.dictionary', 'Requested page was not found'));
}
return $model;
}