本文整理汇总了PHP中app\components\Helper类的典型用法代码示例。如果您正苦于以下问题:PHP Helper类的具体用法?PHP Helper怎么用?PHP Helper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Helper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: up
public function up()
{
for ($i = 0; $i < 45; $i++) {
$data = Helper::getDateIntervalYesterdayInDashOrSlashFormat(new \DateTime(), $i, 'slash');
$url = 'http://www.cbr.ru/scripts/XML_daily.asp?date_req=' . $data;
$xml_contents = file_get_contents($url);
if ($xml_contents === false) {
throw new \ErrorException('Error loading ' . $url);
}
$xml = new \SimpleXMLElement($xml_contents);
$date = $xml->attributes()->Date;
foreach ($xml as $node) {
$current_curr = new \app\models\CurrHistory();
if (\app\models\Currencies::findOne(['valute_id' => $node->attributes()->ID])) {
$current_curr->currency_id = \app\models\Currencies::findOne(['valute_id' => $node->attributes()->ID]);
} else {
$new_currency = new \app\models\Currencies();
$new_currency->name = $node->Name;
$new_currency->valute_id = $node->attributes()->ID;
$new_currency->char_code = $node->CharCode;
$new_currency->num_code = $node->NumCode;
$new_currency->save();
$current_curr->currency_id = $new_currency->id;
}
$current_curr->date = $date;
$current_curr->nominal = $node->Nominal;
$current_curr->value = $node->Value;
$current_curr->save();
}
}
}
示例2: actionIndex
/**
* Renders the start page
* @return string
*/
public function actionIndex()
{
Helper::checkApplication();
if (!Yii::$app->user->isGuest) {
return $this->render('user_index');
}
return $this->render('index');
}
示例3: run
public function run()
{
$object = app\models\Object::getForClass($this->model->className());
/** @var \app\modules\shop\models\AddonCategory $addonCategories */
$addonCategories = app\components\Helper::getModelMap(AddonCategory::className(), 'id', 'name');
/** @var app\modules\shop\models\Addon $bindedAddons */
$bindedAddons = $this->model->bindedAddons;
$addAddonModel = new AddAddonModel();
return $this->render('addons-widget', ['object' => $object, 'addonCategories' => $addonCategories, 'bindedAddons' => $bindedAddons, 'model' => $this->model, 'form' => $this->form, 'addAddonModel' => $addAddonModel]);
}
示例4: createCategory
private function createCategory($name, $parent_id)
{
$model = new Category();
$model->loadDefaultValues();
$model->name = $name;
$model->parent_id = $parent_id;
$model->slug = Helper::createSlug($model->name);
$model->save();
return $model;
}
示例5: beforeSave
public function beforeSave($insert)
{
if (empty($this->description)) {
$this->description = \app\components\Helper::create_descr($this->title, $this->full);
}
if (empty($this->keywords)) {
$this->keywords = \app\components\Helper::create_keywords($this->title, $this->full);
}
return parent::beforeSave($insert);
}
示例6: actionSettings
/**
* @return string|\yii\web\Response
* @throws \yii\web\ServerErrorHttpException
*/
public function actionSettings()
{
if (Yii::$app->request->isPost) {
$model = new Yml();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$model->saveConfig();
} elseif ($model->hasErrors()) {
Yii::$app->session->setFlash('error', Helper::formatModelErrors($model, '<br />'));
}
return $this->refresh();
}
$model = new Yml();
$model->loadConfig();
return $this->render('settings', ['model' => $model]);
}
示例7: run
public function run()
{
$file = UploadedFile::getInstanceByName($this->fileName);
if ($file->hasError) {
throw new HttpException(500, 'Upload error');
}
$transliteratedFileName = Helper::createSlug(substr(strstr(strtolower($file->name), $file->extension, true), 0, -1));
$fileName = $transliteratedFileName . '.' . $file->extension;
if (Yii::$app->getModule('image')->fsComponent->has($fileName)) {
$fileName = $transliteratedFileName . '-' . uniqid() . '.' . $file->extension;
}
Yii::$app->getModule('image')->fsComponent->put($fileName, file_get_contents($file->tempName));
$response = ['filename' => $fileName];
if (isset($this->afterUploadHandler)) {
$data = ['data' => $this->afterUploadData, 'file' => $file, 'dirName' => $this->uploadDir, 'filename' => $fileName, 'params' => Yii::$app->request->post()];
if ($result = call_user_func($this->afterUploadHandler, $data)) {
$response['afterUpload'] = $result;
}
}
return Json::encode($response);
}
示例8: actionAddStaticValue
public function actionAddStaticValue($key, $value = "", $returnUrl)
{
$model = new PropertyStaticValues();
$property = Property::find()->where(['key' => $key])->one();
$model->property_id = $property->id;
if (Yii::$app->request->isPost) {
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$this->redirect($returnUrl);
}
} elseif ($value !== "") {
$model->name = $value;
$model->value = $value;
$model->slug = Helper::createSlug($value);
$model->sort_order = 0;
}
return $this->renderAjax('ajax-static-value', ['model' => $model]);
}
示例9:
<?php
echo $form->field($model, 'overwriteUploadedFiles')->widget(SwitchInput::className());
?>
<?php
echo $form->field($model, 'daysToStoreSubmissions');
?>
<?php
BackendWidget::end();
?>
</div>
<div class="col-md-6 col-sm-12">
<?php
BackendWidget::begin(['title' => Yii::t('app', 'Email configuration'), 'options' => ['class' => 'visible-header']]);
?>
<?php
echo $form->field($model, 'spamCheckerApiKey')->dropDownList(Helper::getModelMap(SpamChecker::className(), 'behavior', 'name'));
?>
<?php
echo $form->field($model, 'emailConfig[transport]')->dropDownList(['Swift_MailTransport' => 'Mail', 'Swift_SmtpTransport' => 'SMTP', 'Swift_SendmailTransport' => 'Sendmail'])->label('Mail transport');
?>
<?php
echo $form->field($model, 'emailConfig[host]')->label('Mail server');
?>
<?php
echo $form->field($model, 'emailConfig[username]')->label('Mail username');
?>
<?php
echo $form->field($model, 'emailConfig[password]')->label('Mail password');
?>
<?php
echo $form->field($model, 'emailConfig[port]')->label('Mail server port');
示例10: getRoutes
/**
* Получить маршруты
* @param array $addressIds координаты адресов
* @return Route
*/
public static function getRoutes(array $addressIds)
{
$keyCache = Helper::hashData($addressIds);
if ($data = CacheData::get($keyCache)) {
return $data;
}
$response = GoogleMapsDirectionsAPI::getRoutesByIds($addressIds, true);
if (!$response) {
return [];
}
$routes = [];
foreach ($response->routes as $route) {
$routes = array_merge($routes, self::prepareLegs($route->legs, $route->summary));
}
self::prepareSafetyLevel($routes);
CacheData::set($keyCache, $routes);
return $routes;
}
示例11: jQuery
<div class="row">
<div class="col-md-4">
<?php
echo TreeWidget::widget(['treeDataRoute' => ['getTree'], 'doubleClickAction' => ContextMenuHelper::actionUrl(['index', 'returnUrl' => Helper::getReturnUrl()], ['parent_id' => 'id']), 'contextMenuItems' => ['show' => ['label' => 'Show products in category', 'icon' => 'fa fa-folder-open', 'action' => ContextMenuHelper::actionUrl(['index'], ['parent_id' => 'id'])], 'createProduct' => ['label' => 'Create product in this category', 'icon' => 'fa fa-plus-circle', 'action' => ContextMenuHelper::actionUrl(['edit', 'returnUrl' => Helper::getReturnUrl()], ['parent_id' => 'id'])], 'edit' => ['label' => 'Edit category', 'icon' => 'fa fa-pencil', 'action' => ContextMenuHelper::actionUrl(['/shop/backend-category/edit', 'returnUrl' => Helper::getReturnUrl()])], 'create' => ['label' => 'Create category', 'icon' => 'fa fa-plus-circle', 'action' => ContextMenuHelper::actionUrl(['/shop/backend-category/edit', 'returnUrl' => Helper::getReturnUrl()], ['parent_id' => 'id'])], 'delete' => ['label' => 'Delete', 'icon' => 'fa fa-trash-o', 'action' => new \yii\web\JsExpression("function(node) {\n jQuery('#delete-category-confirmation')\n .attr('data-url', '/backend/category/delete?id=' + jQuery(node.reference[0]).data('id'))\n .attr('data-items', '')\n .modal('show');\n return true;\n }")]]]);
?>
</div>
<div class="col-md-8" id="jstree-more">
<?php
echo DynaGrid::widget(['options' => ['id' => 'Product-grid'], 'columns' => [['class' => \kartik\grid\CheckboxColumn::className(), 'options' => ['width' => '10px']], ['class' => 'yii\\grid\\DataColumn', 'attribute' => 'id'], ['class' => 'yii\\grid\\DataColumn', 'attribute' => 'name'], 'slug', ['class' => \kartik\grid\EditableColumn::className(), 'attribute' => 'active', 'editableOptions' => ['data' => [0 => Yii::t('app', 'Inactive'), 1 => Yii::t('app', 'Active')], 'inputType' => 'dropDownList', 'placement' => 'left', 'formOptions' => ['action' => 'update-editable']], 'filter' => [0 => Yii::t('app', 'Inactive'), 1 => Yii::t('app', 'Active')], 'format' => 'raw', 'value' => function (Product $model) {
if ($model === null || $model->active === null) {
return null;
}
if ($model->active === 1) {
$label_class = 'label-success';
$value = 'Active';
} else {
$value = 'Inactive';
$label_class = 'label-default';
}
return \yii\helpers\Html::tag('span', Yii::t('app', $value), ['class' => "label {$label_class}"]);
}], ['class' => 'kartik\\grid\\EditableColumn', 'attribute' => 'price', 'editableOptions' => ['inputType' => \kartik\editable\Editable::INPUT_TEXT, 'formOptions' => ['action' => 'update-editable']]], ['class' => 'kartik\\grid\\EditableColumn', 'attribute' => 'old_price', 'editableOptions' => ['inputType' => \kartik\editable\Editable::INPUT_TEXT, 'formOptions' => ['action' => 'update-editable']]], ['attribute' => 'currency_id', 'class' => \kartik\grid\EditableColumn::className(), 'editableOptions' => ['data' => [0 => '-'] + \app\components\Helper::getModelMap(\app\modules\shop\models\Currency::className(), 'id', 'name'), 'inputType' => 'dropDownList', 'placement' => 'left', 'formOptions' => ['action' => 'update-editable']], 'filter' => \app\components\Helper::getModelMap(\app\modules\shop\models\Currency::className(), 'id', 'name'), 'format' => 'raw', 'value' => function ($model) {
if ($model === null || $model->currency === null || $model->currency_id === 0) {
return null;
}
return \yii\helpers\Html::tag('div', $model->currency->name, ['class' => $model->currency->name]);
}], ['class' => 'kartik\\grid\\EditableColumn', 'attribute' => 'sku', 'editableOptions' => ['inputType' => \kartik\editable\Editable::INPUT_TEXT, 'formOptions' => ['action' => 'update-editable'], 'placement' => 'left']], 'date_modified', ['class' => 'app\\backend\\components\\ActionColumn', 'buttons' => [['url' => '@product', 'icon' => 'eye', 'class' => 'btn-info', 'label' => Yii::t('app', 'Preview'), 'appendReturnUrl' => false, 'url_append' => '', 'attrs' => ['model', 'mainCategory.category_group_id'], 'keyParam' => null], ['url' => 'edit', 'icon' => 'pencil', 'class' => 'btn-primary', 'label' => Yii::t('app', 'Edit')], ['url' => 'clone', 'icon' => 'copy', 'class' => 'btn-success', 'label' => Yii::t('app', 'Clone')], ['url' => 'delete', 'icon' => 'trash-o', 'class' => 'btn-danger', 'label' => Yii::t('app', 'Delete'), 'options' => ['data-action' => 'delete']]]]], 'theme' => 'panel-default', 'gridOptions' => ['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'hover' => true, 'panel' => ['heading' => '<h3 class="panel-title">' . $this->title . '</h3>', 'after' => $this->blocks['add-button']]]]);
?>
</div>
</div>
示例12: function
return ['class' => 'danger'];
}
return [];
}], 'columns' => [['attribute' => 'id'], ['attribute' => 'user_username', 'label' => Yii::t('app', 'User'), 'value' => function ($model, $key, $index, $column) {
if ($model === null || $model->user === null) {
return null;
}
return $model->user->username;
}], 'start_date', 'end_date', ['attribute' => 'order_stage_id', 'filter' => Helper::getModelMap(\app\modules\shop\models\OrderStage::className(), 'id', 'name_short'), 'value' => function ($model, $key, $index, $column) {
if ($model === null || $model->stage === null) {
return null;
}
return $model->stage->name_short;
}], ['attribute' => 'shipping_option_id', 'filter' => Helper::getModelMap(\app\modules\shop\models\ShippingOption::className(), 'id', 'name'), 'value' => function ($model, $key, $index, $column) {
if ($model === null || $model->shippingOption === null) {
return null;
}
return $model->shippingOption->name;
}], ['attribute' => 'payment_type_id', 'filter' => Helper::getModelMap(\app\modules\shop\models\PaymentType::className(), 'id', 'name'), 'value' => function ($model, $key, $index, $column) {
if ($model === null || $model->paymentType === null) {
return null;
}
return $model->paymentType->name;
}], 'items_count', 'total_price', ['class' => 'app\\backend\\components\\ActionColumn', 'buttons' => function ($model, $key, $index, $parent) {
$result = [['url' => '/shop/backend-order/view', 'icon' => 'eye', 'class' => 'btn-info', 'label' => Yii::t('app', 'View')]];
return $result;
}]]]);
?>
</div>
</div>
示例13:
?>
</th>
<td>
<?php
echo $orderIsImmutable ? Html::encode($model->stage->name_short) : Editable::widget(['attribute' => 'order_stage_id', 'data' => \app\components\Helper::getModelMap(\app\modules\shop\models\OrderStage::className(), 'id', 'name_short'), 'displayValue' => $model->stage !== null ? Html::tag('span', $model->stage->name_short) : Html::tag('em', Yii::t('yii', '(not set)')), 'formOptions' => ['action' => ['update-stage', 'id' => $model->id]], 'inputType' => Editable::INPUT_DROPDOWN_LIST, 'model' => $model]);
?>
</td>
</tr>
<tr>
<th><?php
echo $model->getAttributeLabel('payment_type_id');
?>
</th>
<td>
<?php
echo $orderIsImmutable ? null !== $model->paymentType ? Html::encode($model->paymentType->name) : Html::tag('em', Yii::t('yii', '(not set)')) : Editable::widget(['attribute' => 'payment_type_id', 'data' => \app\components\Helper::getModelMap(\app\modules\shop\models\PaymentType::className(), 'id', 'name'), 'displayValue' => $model->paymentType !== null ? Html::tag('span', $model->paymentType->name) : Html::tag('em', Yii::t('yii', '(not set)')), 'formOptions' => ['action' => ['update-payment-type', 'id' => $model->id]], 'inputType' => Editable::INPUT_DROPDOWN_LIST, 'model' => $model]);
?>
</td>
</tr>
<?php
foreach ($model->abstractModel->attributes as $name => $attribute) {
?>
<tr>
<th><?php
echo $model->abstractModel->getAttributeLabel($name);
?>
</th>
<td>
<button data-toggle="modal" data-target="#custom-fields-modal" class="kv-editable-value kv-editable-link">
<?php
echo !empty($attribute) ? Html::encode($attribute) : Html::tag('em', Yii::t('yii', '(not set)'));
示例14: function
* @var \app\models\Form $searchModel
*/
use kartik\dynagrid\DynaGrid;
use kartik\helpers\Html;
$this->title = Yii::t('app', 'Currencies');
$this->params['breadcrumbs'][] = $this->title;
?>
<?php
echo app\widgets\Alert::widget(['id' => 'alert']);
$this->beginBlock('add-button');
echo \yii\helpers\Html::a(\kartik\icons\Icon::show('plus') . ' ' . Yii::t('app', 'Add'), ['edit', 'returnUrl' => \app\backend\components\Helper::getReturnUrl()], ['class' => 'btn btn-success']);
echo \app\backend\widgets\RemoveAllButton::widget(['url' => 'remove-all', 'gridSelector' => '.grid-view', 'htmlOptions' => ['class' => 'btn btn-danger pull-right']]);
$this->endBlock();
?>
<div class="row">
<div class="col-md-12">
<?php
echo DynaGrid::widget(['options' => ['id' => 'currencies-grid'], 'columns' => [['class' => \app\backend\columns\CheckboxColumn::className()], 'id', 'name', 'iso_code', 'convert_nominal', 'convert_rate', ['attribute' => 'currency_rate_provider_id', 'class' => \kartik\grid\EditableColumn::className(), 'editableOptions' => ['data' => [0 => '-'] + \app\components\Helper::getModelMap(\app\modules\shop\models\CurrencyRateProvider::className(), 'id', 'name'), 'inputType' => 'dropDownList', 'placement' => 'left', 'formOptions' => ['action' => 'update-editable']], 'filter' => \app\components\Helper::getModelMap(\app\modules\shop\models\CurrencyRateProvider::className(), 'id', 'name'), 'format' => 'raw', 'value' => function ($model, $key, $index, $column) {
if ($model === null || $model->rateProvider === null) {
return null;
}
return Html::tag('div', $model->rateProvider->name, ['class' => $model->rateProvider->name]);
}], ['class' => \app\backend\components\ActionColumn::className()]], 'theme' => 'panel-default', 'gridOptions' => ['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'hover' => true, 'panel' => ['heading' => $this->render('_tabs', ['currencies' => true]), 'after' => $this->blocks['add-button']]]]);
?>
</div>
</div>
示例15: actionMakeSlug
public function actionMakeSlug($word)
{
\Yii::$app->response->format = Response::FORMAT_JSON;
return Helper::createSlug($word);
}