php yii-helpers-BaseUrl类(方法)实例源码

下面列出了php yii-helpers-BaseUrl 类(方法)源码代码实例,从而了解它的用法。

作者:huylv-hus    项目:w   
/**
  * @inheritdoc
  */
 public function beforeAction()
 {
     $current_route = $this->getModules()[0]->requestedRoute;
     if (!Yii::$app->request->isAjax && !in_array($current_route, Yii::$app->params['route_keep_cookie'])) {
         utilities::deleteCookie('cus_info');
         //Delete coolkie cus_info
     }
     $session = \Yii::$app->session;
     if (!$session->get('login_info')) {
         $this->redirect(BaseUrl::base(true) . '/login');
         return false;
     }
     if ($login_info = $session->get('login_info') and $login_info['expired'] < time()) {
         $session->remove('login_info');
         unset($session['login_info']);
     }
     if (!$session->get('login_info')) {
         $this->redirect(BaseUrl::base(true) . '/timeout');
         return false;
     }
     if ($loginInfo = $session->get('login_info')) {
         $login_info['expired'] = time() + Yii::$app->params['timeOutLogin'];
         $session->set('login_info', $login_info);
     }
     return true;
 }

作者:chaimvai    项目:linet   
public function actionRestore($id = null)
 {
     $model = new FormBackupFile();
     $comp = $this->loadModel($this->company);
     if (isset($_POST['FormBackupFile'])) {
         $bkup = Company::getFilePath() . "tmp.zip";
         $model->file = $_POST['FormBackupFile']['file'];
         $model->file = \yii\web\UploadedFile::getInstance($model, 'file');
         if ($model->file->saveAs($bkup)) {
             $comp->restore($bkup);
             return $this->redirect(\yii\helpers\BaseUrl::base() . '/settings/dashboard');
         }
     }
     if ($id != null) {
         $file = Files::findOne($id);
         if ($file != null) {
             $comp->restore($file->getFullFilePath());
             $this->redirect(\yii\helpers\BaseUrl::base() . '/settings/dashboard');
         } else {
             throw new \yii\web\HttpException(500, 'The backup file does not exist.');
         }
     }
     //read file
     //if DROP TABLE IF EXISTS `
     //if CREATE TABLE `
     //INSERT INTO `
     return $this->render('backupRestore', array('model' => $model));
 }

作者:chaimvai    项目:linet   
public function init()
 {
     //$accHist = new AccHist('search');
     //$accHist->dt=today 00:00:00 > now > today 23:59:59
     $this->content = \app\widgets\GridView::widget(array('id' => 'acchist-grid', 'dataProvider' => $this->search(), 'layout' => '{items}{pager}', 'panel' => false, 'columns' => array(array('attribute' => 'account_id', 'value' => function ($data) {
         return \yii\helpers\Html::a(\yii\helpers\Html::encode(isset($data->account) ? $data->account->name : $data->account_id), \yii\helpers\BaseUrl::base() . ("/accounts/view/" . $data->account_id));
     }, 'format' => 'raw'), 'dt', array('attribute' => 'details', 'format' => 'raw', 'value' => function ($data) {
         return $data->brief();
     }))), true);
     //parent::init();
 }

作者:chaimvai    项目:linet   
public function init()
 {
     //$docs->=status=?? open??
     $this->content = \app\widgets\GridView::widget(array('id' => 'docs-grid', 'dataProvider' => $this->search(), 'layout' => '{items}{pager}', 'panel' => false, 'columns' => array(array('attribute' => 'doctype', 'value' => function ($data) {
         return \yii\helpers\html::a(\yii\helpers\html::encode((isset($data->docType) ? Yii::t("app", $data->docType->name) : "") . " #" . $data->docnum), \yii\helpers\BaseUrl::base() . ("/docs/view/" . $data->id));
     }, 'format' => 'raw'), array('attribute' => 'account_id', 'value' => function ($data) {
         return \yii\helpers\html::a(yii\helpers\html::encode($data->company), \yii\helpers\BaseUrl::base() . ("/accounts/transaction/" . $data->account_id));
     }, 'format' => 'raw'), 'total', array('attribute' => 'status', 'value' => function ($data) {
         return isset($data->docStatus) ? $data->docStatus->name : "";
     }))), true);
     //parent::init();
 }

作者:chaimvai    项目:linet   
public function init()
 {
     //$docs = new Docs('search');
     $this->content = \app\widgets\GridView::widget(array('id' => 'sales-grid', 'dataProvider' => $this->search(), 'layout' => '{items}{pager}', 'panel' => false, 'columns' => array(array('attribute' => 'account_id', 'value' => function ($data) {
         return \yii\helpers\html::a(\yii\helpers\html::encode($data->company), \yii\helpers\BaseUrl::base() . ("/accounts/view/" . $data->account_id));
     }, 'format' => 'raw'), array('attribute' => 'docnum', 'value' => function ($data) {
         return \yii\helpers\html::a(\yii\helpers\html::encode($data->total), \yii\helpers\BaseUrl::base() . ("/docs/view/" . $data->id));
     }, 'format' => 'raw'), array('attribute' => 'due_date', 'value' => function ($data) {
         return $data->due_date;
     }))), true);
     //parent::init();
 }

作者:suposta    项目:yii2-listgroup-men   
protected function renderMenu()
 {
     $html = [];
     $html[] = '<div class="list-group">';
     foreach ($this->items as $item) {
         if (BaseUrl::current() == $item['url']) {
             $html[] = $this->renderActiveItem($item);
         } else {
             $html[] = $this->renderItem($item);
         }
     }
     $html[] = '</div>';
     return implode($html);
 }

作者:huylv-hus    项目:w   
/**
  * @inheritdoc
  */
 public function beforeAction()
 {
     $session = \Yii::$app->session;
     if (!$session->get('login_admin_info')) {
         Yii::$app->response->redirect(BaseUrl::base(true) . '/operator/login');
         return false;
     }
     if ($login_info = $session->get('login_admin_info') and $login_info['expired'] < time()) {
         $session->remove('login_admin_info');
         unset($session['login_admin_info']);
     }
     if ($loginInfo = $session->get('login_admin_info')) {
         $login_info['expired'] = time() + Yii::$app->params['timeOutLogin'];
         $session->set('login_admin_info', $login_info);
     }
     return true;
 }

作者:jarrus9    项目:yii2-multilan   
public function actionSet($lang)
 {
     if (!Yii::$app->user->isGuest) {
         Yii::$app->user->identity->scenario = 'language';
         Yii::$app->user->identity->lang = $lang;
         Yii::$app->user->identity->save();
     }
     Yii::$app->session->set('lang', $lang);
     $redirectUrl = Yii::$app->request->get('redirect', false);
     if (!$redirectUrl) {
         $redirectUrl = Yii::$app->request->referrer;
     }
     if (!$redirectUrl) {
         $redirectUrl = \yii\helpers\BaseUrl::home(true);
     }
     return $this->redirect($redirectUrl);
 }

作者:huylv-hus    项目:w   
/**
  * list order
  * @return string
  */
 public function actionIndex()
 {
     $all = new utilities();
     $branch = $all->getAllBranch();
     $data['all_ss'] = $branch['all_ss'];
     $obj = new Sdptd03denpyo();
     $obj_job = new Sdptm01sagyo();
     $filters = Yii::$app->request->get();
     $query_string = empty($filters) ? '' : '?' . http_build_query($filters);
     Yii::$app->session->set('url_list_workslip', BaseUrl::base() . '/list-workslip' . $query_string);
     if (empty($filters)) {
         $filters['start_time'] = date('Ymd');
         $filters['end_time'] = date('Ymd');
     }
     $data['filters'] = $filters;
     /*
      * Get login info
      * */
     $login_info = Yii::$app->session->get('login_info');
     if (isset($login_info['M50_SS_CD']) && $login_info['M50_SS_CD'] != '') {
         $data['filters']['m50_ss_cd'] = $login_info['M50_SS_CD'];
     }
     $count = $obj->countDataSearch($data['filters']);
     $data['pagination'] = new Pagination(['totalCount' => $count, 'defaultPageSize' => Yii::$app->params['defaultPageSize']]);
     $data['page'] = $filters = Yii::$app->request->get('page');
     $data['filters']['limit'] = $data['pagination']->limit;
     $data['filters']['offset'] = $data['pagination']->offset;
     $data['list'] = $obj->getDataSearch($data['filters']);
     if (empty($data['list'])) {
         Yii::$app->session->setFlash('empty', '入力条件に該当する作業伝票が存在しません');
     }
     $data['job'] = [];
     $all_job = $obj_job->getData();
     foreach ($all_job as $k => $v) {
         $data['job'][''] = '';
         $data['job'][$v['M01_SAGYO_NO']] = $v['M01_SAGYO_NAMEN'];
     }
     $data['status'] = Yii::$app->params['status'];
     Yii::$app->params['titlePage'] = '作業伝票一覧';
     Yii::$app->view->title = '情報検索';
     return $this->render('index', $data);
 }

作者:chaimvai    项目:linet   
/**
  * Display the widget
  * @see CWidget::run()
  */
 public function run()
 {
     //style="width:'.($this->width-$this->titlewidth-28).'px;"
     if ($this->content == '') {
         $this->content = ob_get_clean();
     }
     $helper = new \app\models\Help();
     $this->help = $helper->getHelp(str_replace(\yii\helpers\BaseUrl::base(), "", \Yii::$app->request->url));
     if ($this->help) {
         //' . \Yii::t("app", 'Help') . '
         $this->help = '<a class="btn btn-default" href="' . $this->help . '" target="_blank"><i class="glyphicon glyphicon-question-sign"></i></a>';
     } else {
         $this->help = '';
     }
     if ($this->collapse) {
         $this->collapse = '<a href="javascript:;" class="btn btn-default btn-xs collapse-box"  data-toggle="collapse">
                       <i class="fa fa-minus"></i>
                     </a> ';
         $this->collapse = '';
     } else {
         $this->collapse = '';
     }
     if ($this->height) {
         $this->height = 'style="height:' . $this->height . 'px"';
     } else {
         $this->height = '';
     }
     if ($this->fullscreen) {
         $this->fullscreen = '<a href="javascript:;" class="btn btn-default btn-xs full-box">
                       <i class="fa fa-expand"></i>
                     </a> ';
         $this->fullscreen = '';
     } else {
         $this->fullscreen = '';
     }
     //echo $this->getViewPath();
     //    exit;
     //CWidget::render();
     return $this->render("MiniForm", ["class" => $this->class, "logo" => $this->logo, "header" => $this->header, "help" => $this->help, "collapse" => $this->collapse, "fullscreen" => $this->fullscreen, "height" => $this->height, "content" => $this->content]);
     //$newform = '';
     //echo $newform;
 }

作者:huylv-hus    项目:w   
/**
  * action import
  * @return \yii\web\Response
  */
 public function actionImport()
 {
     $request = Yii::$app->request;
     if ($request->isPost && isset($_FILES['commodity'])) {
         $obj = new Sdptm05com();
         if (substr($_FILES['commodity']['name'], -4) == '.csv') {
             $file = utilities::convertUtf8($_FILES['commodity']['tmp_name']);
             $result = $obj->saveImport($file);
             $error = $result['error'];
         } else {
             $error[] = 'CSVのフォーマットが正しくありません';
         }
         if (empty($error) && $result['insert']) {
             Yii::$app->session->setFlash('success', 'success');
         } else {
             Yii::$app->session->setFlash('error', $error);
         }
         return $this->redirect(BaseUrl::base(true) . '/update-commodity');
     }
 }

作者:chaimvai    项目:linet   
public function init()
 {
     date_default_timezone_set('Asia/Tel_Aviv');
     if (!\Yii::$app->user->isGuest) {
         \app\helpers\Linet3Helper::SetTheme();
         date_default_timezone_set(\Yii::$app->user->getParam('timezone'));
         \Yii::$app->language = Yii::$app->user->getParam('language');
     }
     if (Yii::$app->params['newInstall']) {
         if ($this->id != 'install') {
             //print "'".Yii::$app->controller->id."'";
             $this->redirect(\yii\helpers\BaseUrl::base() . '/install/index');
             Yii::$app->end();
         }
     } else {
         //include('upgrade.php');
     }
     //Yii::app()->clientScript->registerScriptFile($baseUrl.'/js/yourscript.js');
     return parent::init();
 }

作者:huylv-hus    项目:w   
public function actionIndex()
 {
     $data['post'] = \Yii::$app->request->post();
     if (isset($data['post']['D01_SS_CD'])) {
         $branch = utilities::getAllBranch();
         $ss = $branch['all_ss'];
         $address = $branch['ss_address'];
         $tel = $branch['ss_tel'];
         $obj_job = new Sdptm01sagyo();
         $job[''] = '';
         $all_job = $obj_job->getData();
         foreach ($all_job as $k => $v) {
             $job[$v['M01_SAGYO_NO']] = $v['M01_SAGYO_NAMEN'];
         }
         $data['ss'] = isset($ss[$data['post']['D01_SS_CD']]) ? $ss[$data['post']['D01_SS_CD']] : '';
         $data['address'] = isset($address[$data['post']['D01_SS_CD']]) ? $address[$data['post']['D01_SS_CD']] : '';
         $data['tel'] = isset($tel[$data['post']['D01_SS_CD']]) ? $tel[$data['post']['D01_SS_CD']] : '';
         foreach ($data['post']['LIST_NAME'] as $k => $v) {
             $data['post']['M05_COM_NAMEN' . $k] = $v;
         }
         $data['job'] = $job;
         $data['status'] = \Yii::$app->params['status'];
         $tanto = explode('[]', $data['post']['D03_TANTO_MEI_D03_TANTO_SEI']);
         if (!empty($tanto[0]) && !empty($tanto[1])) {
             $data['post']['tanto'] = $tanto[0] . $tanto[1];
         }
         $kakunin = explode('[]', $data['post']['D03_KAKUNIN_MEI_D03_KAKUNIN_SEI']);
         if (!empty($kakunin[0]) && !empty($kakunin[1])) {
             $data['post']['kakunin'] = $kakunin[0] . $kakunin[1];
         }
         $data['post']['ss_user'] = $this->getssUser($data['post']['D01_SS_CD']);
         $data['ss_user'] = $data['post']['M08_NAME_MEI_M08_NAME_SEI'] ? $data['post']['ss_user'][$data['post']['M08_NAME_MEI_M08_NAME_SEI']] : '';
         $this->layout = '@app/views/layouts/print';
         \Yii::$app->view->title = '作業確認書';
         \Yii::$app->params['titlePage'] = '作業確認書';
         return $this->render('index', $data);
     }
     return $this->redirect(BaseUrl::base(true) . '/regist-workslip');
 }

作者:agungsuprayitn    项目:sm   
public function actionLogin()
 {
     $model = new Users();
     // $username = "multitenance";
     // $password = "multitenance";
     $username = $_POST['username'];
     $password = $this->encrypt($_POST['password']);
     $detail_login = $model->find()->where(['FIELD3' => $username, 'FIELD4' => $password])->all();
     if ($detail_login) {
         $session = Yii::$app->session;
         foreach ($detail_login as $row) {
             $session->set('nama', $row['FIELD2']);
             $session->set('handphone', $row['FIELD6']);
             $session->set('email', $row['FIELD7']);
             $session->set('level', $row['FIELD8']);
             $session->set('company', $row['FIELD9']);
         }
         // $this->redirect(''.BaseUrl::base().'/dashboard/',302);
         echo BaseUrl::base() . "/dashboard";
     } else {
         echo "error";
     }
 }

作者:chaimvai    项目:linet   
/**
  * Display the widget
  * @see CWidget::run()
  */
 public function run()
 {
     //style="width:'.($this->width-$this->titlewidth-28).'px;"
     $arr = explode('\\', get_class($this->model));
     $name = array_pop($arr);
     $id = $name . "_" . $this->attribute;
     $ids = $this->attribute . "_ids";
     //if (!($this->model->hasAttribute($this->attribute)))
     //if (!($this->model->{$this->attribute}))
     //throw new CHttpException(500, Yii::t('app', 'Did not set attr or model for refnum'));
     //Yii::$app->end();
     //$baseUrl = Yii::$app->request->baseUrl;
     $text = '';
     //if(function_exists(getRef())){
     //$this->model->getRef();
     if ($this->model->Docs !== null) {
         foreach ($this->model->Docs as $doc) {
             //echo \yii\helpers\Html::link($doc->docType->name . " #" . $doc->docnum, array('docs/view', "id" => $doc->id)) . "<br />";
             $text .= "<a href='" . \yii\helpers\BaseUrl::base() . "docs/view/{$doc->id}" . "' >" . $doc->docType->name . ' #' . $doc->docnum . "</a><br />";
         }
     }
     // }
     return $this->render("Refnum", ["name" => $name, "id" => $id, "ids" => $ids, "value" => $this->model->{$ids}, "text" => $text, "label" => $this->model->getAttributeLabel($this->attribute)]);
 }

作者:kaihatsush    项目:kpimo   
switch ($model->entry_status) {
        case MasterValueUtils::MV_FIN_ENTRY_TYPE_SIMPLE:
            $urlEdit = BaseUrl::toRoute(['payment/update', 'id' => $entryId]);
            $arrBtns[] = StringUtils::format('<li><a href="{0}">{1}</a></li>', [$urlEdit, $lblEdit]);
            $urlView = BaseUrl::toRoute(['payment/view', 'id' => $entryId]);
            $arrBtns[] = StringUtils::format('<li><a href="{0}">{1}</a></li>', [$urlView, $lblView]);
            $urlCopy = BaseUrl::toRoute(['payment/copy', 'id' => $entryId]);
            $arrBtns[] = StringUtils::format('<li><a href="{0}">{1}</a></li>', [$urlCopy, $lblCopy]);
            break;
        case MasterValueUtils::MV_FIN_ENTRY_TYPE_DEPOSIT:
        case MasterValueUtils::MV_FIN_ENTRY_TYPE_INTEREST_DEPOSIT:
            $urlEdit = BaseUrl::toRoute(['deposit/update', 'id' => $timeDepositTranId]);
            $arrBtns[] = StringUtils::format('<li><a href="{0}">{1}</a></li>', [$urlEdit, $lblEdit]);
            $urlView = BaseUrl::toRoute(['deposit/view', 'id' => $timeDepositTranId]);
            $arrBtns[] = StringUtils::format('<li><a href="{0}">{1}</a></li>', [$urlView, $lblView]);
            $urlCopy = BaseUrl::toRoute(['deposit/copy', 'id' => $timeDepositTranId]);
            $arrBtns[] = StringUtils::format('<li><a href="{0}">{1}</a></li>', [$urlCopy, $lblCopy]);
            break;
        default:
            break;
    }
    $html = '<div class="btn-group">';
    $html .= Html::a($lblEdit, [$urlEdit], ['class' => 'btn btn-' . $btnClass]);
    $html .= '<button type="button" class="btn btn-' . $btnClass . ' dropdown-toggle" data-toggle="dropdown">';
    $html .= '<span class="caret"></span><span class="sr-only">Toggle Dropdown</span>';
    $html .= '</button>';
    $html .= '<ul class="dropdown-menu" role="menu">';
    $html .= implode('', $arrBtns);
    $html .= '</ul></div>';
    return $html;
}]]]);

作者:kaihatsush    项目:kpimo   
Pjax::begin();
echo GridView::widget(['layout' => '{summary}<div class="table-responsive">{items}</div>{pager}', 'options' => ['class' => 'grid-view col-xs-12'], 'tableOptions' => ['class' => 'table table-bordered'], 'showFooter' => true, 'pager' => ['options' => ['class' => 'pagination pagination-bottom'], 'maxButtonCount' => 6], 'dataProvider' => new ActiveDataProvider(['query' => $dataQuery, 'pagination' => ['pagesize' => 10]]), 'columns' => [['label' => Yii::t('fin.grid', 'Ref'), 'headerOptions' => ['style' => 'text-align: center'], 'contentOptions' => ['style' => 'vertical-align: middle; text-align: center'], 'format' => 'raw', 'value' => function ($model, $key, $index, $column) {
    $pagination = $column->grid->dataProvider->pagination;
    $html = $pagination->page * $pagination->pageSize + $index + 1;
    $html .= '<br/>' . str_pad($model->id, 6, '0', STR_PAD_LEFT);
    return $html;
}], ['label' => Yii::t('fin.grid', 'Status'), 'headerOptions' => ['style' => 'text-align: center'], 'contentOptions' => ['style' => 'vertical-align: middle; text-align: center'], 'format' => 'raw', 'value' => function ($model) use($arrCustomerStatus) {
    $status = isset($arrCustomerStatus[$model->status]) ? $arrCustomerStatus[$model->status] : '';
    $html = '<span>' . $status . '</span>';
    $lblView = Yii::t('button', 'View');
    $lblEdit = Yii::t('button', 'Edit');
    $arrBtns = [];
    $entryId = $model->id;
    $urlEdit = BaseUrl::toRoute(['customer/update', 'id' => $entryId]);
    $arrBtns[] = StringUtils::format('<li><a href="{0}">{1}</a></li>', [$urlEdit, $lblEdit]);
    $urlView = BaseUrl::toRoute(['customer/view', 'id' => $entryId]);
    $arrBtns[] = StringUtils::format('<li><a href="{0}">{1}</a></li>', [$urlView, $lblView]);
    $html .= '<br/><div class="btn-group">';
    $html .= Html::a($lblEdit, [$urlEdit], ['class' => 'btn btn-xs btn-info']);
    $html .= '<button type="button" class="btn btn-xs btn-info dropdown-toggle" data-toggle="dropdown">';
    $html .= '<span class="caret"></span><span class="sr-only">Toggle Dropdown</span>';
    $html .= '</button>';
    $html .= '<ul class="dropdown-menu" role="menu">';
    $html .= implode('', $arrBtns);
    $html .= '</ul></div>';
    return $html;
}], ['label' => Yii::t('fin.grid', 'Balance'), 'headerOptions' => ['style' => 'text-align: center'], 'footerOptions' => ['style' => 'vertical-align: middle; text-align: right'], 'contentOptions' => ['style' => 'vertical-align: middle; text-align: right'], 'format' => 'raw', 'value' => function ($model) {
    $labelClass = $model->balance < 0 ? 'label-danger' : 'label-info';
    $labelValue = NumberUtils::format(abs($model->balance));
    return StringUtils::format('{2}<br/><span class="label {0} pull-right">{1}</span>', [$labelClass, $labelValue, $model->name]);
}, 'footer' => NumberUtils::getIncDecNumber($sumCustomerValue['balance'], ['template' => '<span class="label pull-right {color}">{number}</span>', 'incColor' => 'label-info', 'decColor' => 'label-danger'])]]]);

作者:Liv102    项目:cm   
/**
  *
  * Загрузить файл в хранилище, добавить в базу, вернуть модель StorageFile
  *
  * @param UploadedFile|string|File $file    объект UploadedFile или File или rootPath до файла локально или http:// путь к файлу (TODO:: доделать)
  * @param array $data                       данные для сохранения в базу
  * @param null $clusterId                   идентификатор кластера по умолчанию будет выбран первый из конфигурации
  * @return StorageFile
  * @throws Exception
  */
 public function upload($file, $data = [], $clusterId = null)
 {
     //Для начала всегда загружаем файл во временную диррикторию
     $tmpdir = Dir::runtimeTmp();
     $tmpfile = $tmpdir->newFile();
     if ($file instanceof UploadedFile) {
         $extension = File::object($file->name)->getExtension();
         $tmpfile->setExtension($extension);
         if (!$file->saveAs($tmpfile->getPath())) {
             throw new Exception("Файл не загружен во временную диррикторию");
         }
     } else {
         if ($file instanceof File || is_string($file) && BaseUrl::isRelative($file)) {
             $file = File::object($file);
             $tmpfile->setExtension($file->getExtension());
             $tmpfile = $file->move($tmpfile);
         } else {
             if (is_string($file) && !BaseUrl::isRelative($file)) {
                 $curl_session = curl_init($file);
                 if (!$curl_session) {
                     throw new Exception("Неверная ссылка");
                 }
                 curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
                 curl_setopt($curl_session, CURLOPT_BINARYTRANSFER, true);
                 $file_content = curl_exec($curl_session);
                 curl_close($curl_session);
                 if (!$file_content) {
                     throw new Exception("Не удалось скачать файл");
                 }
                 $extension = pathinfo($file, PATHINFO_EXTENSION);
                 $pos = strpos($extension, "?");
                 if ($pos === false) {
                 } else {
                     $extension = substr($extension, 0, $pos);
                 }
                 if ($extension) {
                     $tmpfile->setExtension($extension);
                 }
                 $is_file_saved = file_put_contents($tmpfile, $file_content);
                 if (!$is_file_saved) {
                     throw new Exception("Не удалось сохранить файл");
                 }
                 //Если в ссылке нет расширения
                 if (!$extension) {
                     $tmpfile = new File($tmpfile->getPath());
                     try {
                         $mimeType = FileHelper::getMimeType($tmpfile->getPath(), null, false);
                     } catch (InvalidConfigException $e) {
                         throw new Exception("Не удалось пределить расширение файла: " . $e->getMessage());
                     }
                     if (!$mimeType) {
                         throw new Exception("Не удалось пределить расширение файла");
                     }
                     $extensions = FileHelper::getExtensionsByMimeType($mimeType);
                     if ($extensions) {
                         if (in_array("jpg", $extensions)) {
                             $extension = 'jpg';
                         } else {
                             if (in_array("png", $extensions)) {
                                 $extension = 'png';
                             } else {
                                 $extension = $extensions[0];
                             }
                         }
                         $newFile = new File($tmpfile->getPath());
                         $newFile->setExtension($extension);
                         $tmpfile = $tmpfile->copy($newFile);
                     }
                 }
             } else {
                 throw new Exception("Файл должен быть определен как \\yii\\web\\UploadedFile или \\skeeks\\sx\\File или string");
             }
         }
     }
     $data["type"] = $tmpfile->getType();
     $data["mime_type"] = $tmpfile->getMimeType();
     $data["size"] = $tmpfile->size()->getBytes();
     $data["extension"] = $tmpfile->getExtension();
     //Елси это изображение
     if ($tmpfile->getType() == 'image') {
         if (extension_loaded('gd')) {
             list($width, $height, $type, $attr) = getimagesize($tmpfile->toString());
             $data["image_height"] = $height;
             $data["image_width"] = $width;
         }
     }
     if ($cluster = $this->getCluster($clusterId)) {
         if ($newFileSrc = $cluster->upload($tmpfile)) {
             $data = array_merge($data, ["src" => $cluster->getPublicSrc($newFileSrc), "cluster_id" => $cluster->getId(), "cluster_file" => $newFileSrc]);
         }
//.........这里部分代码省略.........

作者:brunofunn    项目:ago   
}
?>

            <div class="form-group">
                <label>Status</label>
                <p><span class="event <?php 
echo Yii::$app->AgobUtils->cssStatus($model->status, $model->d_ter);
?>
"></span><?php 
echo Yii::$app->params['status'][$model->status];
?>
</p>
            </div>

            <form action="<?php 
echo \yii\helpers\BaseUrl::current();
?>
" method="POST">
                <?php 
if (Yii::$app->user->can('Administrador')) {
    ?>
                    <div class="form-group">
                        <label>Observação</label>
                        <textarea name="Eventos[status_observacao]" class="form-control" rows="5"><?php 
    echo $model->status_observacao;
    ?>
</textarea>
                    </div>
                    <?php 
    if (Yii::$app->user->can('Administrador')) {
        ?>

作者:damiandenni    项目:yii2-knockout-lis   
/**
  * @param string $id The id of the widget
  * @param \yii\data\BaseDataProvider $dataProvider The dataprovider for the widget
  * @param \Closure $filter The filter to manipulate the data.
  * @return array The data required to create the list and pagination.
  */
 protected static function getData($id, $dataProvider, $filter)
 {
     $data = ['id' => $id];
     $data['count'] = $dataProvider->getCount();
     if (($pagination = $dataProvider->getPagination()) !== false) {
         $data['totalCount'] = $dataProvider->getTotalCount();
         $data['begin'] = $pagination->getPage() * $pagination->pageSize + 1;
         $data['end'] = $data['begin'] + $data['count'] - 1;
         if ($data['begin'] > $data['end']) {
             $data['begin'] = $data['end'];
         }
         $data['page'] = $pagination->getPage() + 1;
         $data['pageCount'] = $pagination->pageCount;
     } else {
         $data['totalCount'] = $dataProvider->getTotalCount();
         $data['pageCount'] = 1;
         $data['page'] = 1;
         $data['begin'] = $data['page'] = $data['pageCount'] = 1;
         $data['end'] = $data['totalCount'] = $data['count'];
     }
     $pagination = $dataProvider->getPagination();
     if ($pagination !== false) {
         $data['pageParam'] = $pagination->pageParam;
         $data['pageSizeParam'] = $pagination->pageSizeParam;
         $data['pageSizeLimit'] = $pagination->pageSizeLimit;
         $data['pageLinks'] = $pagination->getLinks();
         $currentPage = $pagination->getPage();
         $pageCount = $pagination->getPageCount();
         $maxButtonCount = 10;
         $beginPage = max(0, $currentPage - (int) ($maxButtonCount / 2));
         if (($endPage = $beginPage + $maxButtonCount - 1) >= $pageCount) {
             $endPage = $pageCount - 1;
             $beginPage = max(0, $endPage - $maxButtonCount + 1);
         }
         for ($i = $beginPage; $i <= $endPage; $i++) {
             $data['pages'][] = ['pageNo' => $i + 1, 'pageUrl' => $pagination->createUrl($i)];
         }
     }
     $sort = $dataProvider->getSort();
     if (!($sort === false || empty($sort->attributes) || $dataProvider->getCount() <= 0)) {
         $attributes = array_keys($sort->attributes);
         $data['sort'] = [];
         foreach ($attributes as $name) {
             $data['sort'][] = ['name' => $name, 'link' => $sort->createUrl($name)];
         }
     }
     $models = $dataProvider->getModels();
     if ($models) {
         $data['labels'] = $models[0]->attributeLabels();
     }
     $controller = Yii::$app->controller->id;
     foreach ($models as $key => $model) {
         $data['items'][$key] = $filter ? $filter($model) : $model->attributes;
         $data['items'][$key]['actions'] = ['viewUrl' => BaseUrl::toRoute(["{$controller}/view", 'id' => $model->primaryKey]), 'viewTitle' => Yii::t('app', 'View'), 'updateUrl' => BaseUrl::toRoute(["{$controller}/update", 'id' => $model->primaryKey]), 'updateTitle' => Yii::t('app', 'Update'), 'deleteUrl' => BaseUrl::toRoute(["{$controller}/delete", 'id' => $model->primaryKey]), 'deleteTitle' => Yii::t('app', 'Delete')];
     }
     return $data;
 }


问题


面经


文章

微信
公众号

扫码关注公众号