本文整理汇总了PHP中Yii::getAlias方法的典型用法代码示例。如果您正苦于以下问题:PHP Yii::getAlias方法的具体用法?PHP Yii::getAlias怎么用?PHP Yii::getAlias使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Yii
的用法示例。
在下文中一共展示了Yii::getAlias方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* @inheritdoc
*/
public function run()
{
$jsOptions = ['clientOptions' => $this->clientOptions];
$this->options['id'] = 'input-id';
if ($this->hasModel()) {
echo Html::activeInput('file', $this->model, $this->attribute, $this->options);
echo Html::img('#', ['id' => 'cropper-box']);
echo Html::button('Crop', ['id' => 'cropImage']);
$input_name = Html::getInputName($this->model, $this->attribute);
$input_id = Html::getInputId($this->model, $this->attribute);
echo Html::hiddenInput($input_name . '[file]', '', ['id' => $input_id . '_image']);
$jsOptions['model'] = $this->model;
$jsOptions['attribute'] = $this->attribute;
} else {
echo Html::fileInput($this->name, $this->value, $this->options);
echo Html::img('#', ['id' => 'cropper-box']);
echo Html::button('Crop', ['id' => 'cropImage']);
}
if ($this->uploadUrl) {
$this->uploadUrl = \Yii::getAlias($this->uploadUrl);
}
$jsOptions['uploadUrl'] = $this->uploadUrl;
$jsOptions['uploadCroppedUrl'] = $this->uploadCroppedUrl;
$jsOptions['changeUrl'] = $this->changeUrl;
$jsOptions['name'] = $this->name;
$jsOptions['aspectRatio'] = $this->aspectRatio;
$this->registerPlugin($jsOptions);
}
示例2: actionDuiHuan
public function actionDuiHuan()
{
$post = \Yii::$app->request->post();
$user = \Yii::$app->user->identity;
$dzUser = (new DzHelper())->getDzUserByUsername($user->username);
$data = [];
$bbsUrl = \Yii::getAlias('@bbsUrl');
$model = ShopProduct::findOne($post['dataId']);
//实体物品
if ($post['dataType'] == ShopCategory::findOne(['slug' => 'shi-ti-wu-pin'])->id) {
return $this->redirect(['shi-wu-order', 'slug' => $model->slug]);
}
//判断积分
if ($model->jifen > $dzUser['credits']) {
$data['msg'] = '<i class="glyphicon glyphicon-ok"></i> 您当前的积分为 : ' . $dzUser['credits'];
$data['msg'] .= '<br>';
$data['msg'] .= '<i class="glyphicon glyphicon-ok"></i> 很遗憾您的积分不够兑换该礼品';
$data['msg'] .= '<br>';
$data['msg'] .= "<a href={$bbsUrl} target='_blank'>[去论坛赚积分]</a>";
return json_encode($data);
} else {
//实体物品
if ($post['dataType'] == ShopCategory::findOne(['slug' => 'shi-ti-wu-pin'])->id) {
return $this->redirect(['shi-wu-order', 'slug' => $model->slug]);
}
//虚拟物品
if ($post['dataType'] == ShopCategory::findOne(['slug' => 'xu-ni-wu-pin'])->id) {
}
}
$data['msg'] = '<i class="glyphicon glyphicon-ok"></i> 系统异常,请稍后在试!';
return json_encode($data);
}
示例3: actionUpload
/**
* 上传图片的操作
* @author gaoqing
* 2016年1月28日
* @return array 上传成功后,返回图片的相关信息
*/
public function actionUpload()
{
\Yii::$app->response->format = Response::FORMAT_JSON;
//设置上传目录
$path = $this->temp;
if (!empty($_FILES)) {
//得到上传的临时文件流
$tempFile = $_FILES['Filedata']['tmp_name'];
//允许的文件后缀
$fileTypes = array('jpg', 'jpeg', 'gif', 'png');
//得到文件原名
$fileName = iconv("UTF-8", "GB2312", $_FILES["Filedata"]["name"]);
$fileParts = pathinfo($_FILES['Filedata']['name']);
//最后保存服务器地址
$frontend = \Yii::getAlias("@frontend");
$fullpath = $frontend . DIRECTORY_SEPARATOR . "web" . DIRECTORY_SEPARATOR . $path;
if (!file_exists($fullpath) || !is_dir($fullpath)) {
mkdir($fullpath, 0777);
}
$name = strstr($fileName, ".", true);
$name = md5($name);
$suffix = strstr($fileName, ".");
$fileName = $name . $suffix;
$domain = \Yii::getAlias("@jb_domain");
if (move_uploaded_file($tempFile, $path . $fileName)) {
return ['path' => $path, 'name' => $name, 'suffix' => $suffix, 'fileName' => $fileName, 'domain' => $domain];
}
}
}
示例4: actionUpload
public function actionUpload()
{
// @todo Update code
// http://webtips.krajee.com/ajax-based-file-uploads-using-fileinput-plugin/
if (Yii::$app->request->isPost) {
$post = Yii::$app->request->post();
$gallery = Gallery::findOne(Yii::$app->session->get('gallery.gallery-id'));
$form = new ImageUploadForm();
$images = UploadedFile::getInstances($form, 'images');
foreach ($images as $k => $image) {
$_model = new ImageUploadForm();
$_model->image = $image;
if ($_model->validate()) {
$path = \Yii::getAlias('@uploadsBasePath') . "/img/{$_model->image->baseName}.{$_model->image->extension}";
$_model->image->saveAs($path);
// Attach image to model
$gallery->attachImage($path);
} else {
foreach ($_model->getErrors('image') as $error) {
$gallery->addError('image', $error);
}
}
}
if ($form->hasErrors('image')) {
// @todo Translate
$response['message'] = count($form->getErrors('image')) . ' of ' . count($images) . ' images not uploaded';
} else {
$response['message'] = Yii::t('app', '{n, plural, =1{Image} other{# images}} successfully uploaded', ['n' => count($images)]);
}
Yii::$app->response->format = Response::FORMAT_JSON;
return $response;
}
}
示例5: init
public function init()
{
$this->basePath = $_SERVER['DOCUMENT_ROOT'] . \Yii::getAlias('@web') . '/ueditor';
//设置资源所处的目录
$this->baseUrl = Yii::getAlias('@web') . '/ueditor';
//echo $this->baseUrl; die;
}
示例6: bootstrap
/**
* Bootstrap method to be called during application bootstrap stage.
*
* @param Application $app the application currently running
*/
public function bootstrap($app)
{
/**
* @var Module $gii
*/
\Yii::setAlias('@carono', '@vendor/carono/yii2-components');
if ($app instanceof \yii\console\Application) {
$commands = ['city' => 'CityController', 'currency' => 'CurrencyController', 'dumper' => 'DumperController', 'carono' => 'CaronoController'];
foreach ($commands as $name => $command) {
$name = file_exists(\Yii::getAlias("@app/commands/{$command}.php")) ? "carono" . ucfirst($name) : $name;
$app->controllerMap[$name] = 'carono\\components\\commands\\' . $command;
}
if (!isset($app->controllerMap['giix'])) {
if (($gii = $app->getModule('gii')) && isset($gii->generators["giiant-model"])) {
if (!isset($gii->generators["giiant-model"]["templates"])) {
if (is_array($gii->generators["giiant-model"])) {
$gii->generators["giiant-model"]["templates"] = [];
} else {
$gii->generators["giiant-model"] = ["class" => 'schmunk42\\giiant\\generators\\model\\Generator', "templates" => []];
}
}
$template = '@vendor/carono/yii2-components/templates/giiant-model';
$gii->generators["giiant-model"]["templates"]["caronoModel"] = $template;
$app->controllerMap['giix'] = 'carono\\components\\commands\\GiixController';
}
}
}
}
示例7: getSxGeo
/**
* @return SxGeo
*/
public function getSxGeo()
{
if ($this->_sxGeo === null) {
$this->_sxGeo = new SxGeo(\Yii::getAlias($this->database), $this->accessMode);
}
return $this->_sxGeo;
}
示例8: init
public function init()
{
parent::init();
$this->layoutPath = \Yii::getAlias('@app/moduls/admin/views/layouts/');
$this->layout = 'admin';
// custom initialization code goes here
}
示例9: init
public function init()
{
parent::init();
if (!file_exists(\Yii::getAlias('@bower/history.js/scripts/bundled/html5/native.history.js'))) {
throw new InvalidConfigException('You must include `bower-asset/history.js` package in your composer.json configuration file.');
}
}
示例10: init
/**
* @inheritdoc
*/
public function init()
{
parent::init();
$this->uploadDir = !empty(\Yii::$app->getModule('core')->fileUploadPath) ? \Yii::$app->getModule('core')->fileUploadPath : $this->uploadDir;
$this->uploadDir = FileHelper::normalizePath(\Yii::getAlias($this->uploadDir));
$this->additionalRenderData['uploadDir'] = $this->uploadDir;
}
示例11: send
/**
* Send email.
*
* @param bool $isTest
*
* @return bool
*
* @throws ObjectException
* @throws InvalidParamException
* @throws TransportException
*/
public function send($isTest = false)
{
$massmail = MassMail::findByObjectId($this->object_id);
if ($massmail && $massmail->is_send) {
throw new ObjectException('Email has been already sent.');
}
if (!$massmail) {
$massmail = new MassMail();
$massmail->object_id = $this->object_id;
$massmail->subject = $this->title;
$massmail->to = $this->email;
$massmail->message = file_get_contents(Yii::getAlias('@runtime/massmail/blank_email.html'));
$massmail->created_at = time();
}
if (!$massmail->save()) {
throw new ObjectException('Model save errors: ' . $this->getErrors($massmail));
}
$massmail->is_send = (new TransportMassMail($massmail))->send($isTest);
if (!$massmail->is_send) {
throw new ObjectException('Email not send, see logs.');
}
if ($massmail->is_send) {
$massmail->sent_at = time();
}
$massmail->save();
return true;
}
示例12: actionStart
/**
* Start cron tasks
* @param string $taskCommand
* @throws \yii\base\InvalidConfigException
*/
public function actionStart($taskCommand = null)
{
/**
* @var $cron Crontab
*/
$cron = $this->module->get($this->module->nameComponent);
$cron->eraseJobs();
$common_params = $this->module->params;
if (!empty($this->module->tasks)) {
if ($taskCommand && isset($this->module->tasks[$taskCommand])) {
$task = $this->module->tasks[$taskCommand];
$params = ArrayHelper::merge(ArrayHelper::getValue($task, 'params', []), $common_params);
$cron->addApplicationJob(\Yii::getAlias('@app') . '/../yii', $task['command'], $params, ArrayHelper::getValue($task, 'min'), ArrayHelper::getValue($task, 'hour'), ArrayHelper::getValue($task, 'day'), ArrayHelper::getValue($task, 'month'), ArrayHelper::getValue($task, 'dayofweek'), $this->module->cronGroup);
} else {
foreach ($this->module->tasks as $commandName => $task) {
$params = ArrayHelper::merge(ArrayHelper::getValue($task, 'params', []), $common_params);
$cron->addApplicationJob(\Yii::getAlias('@app') . '/../yii', $task['command'], $params, ArrayHelper::getValue($task, 'min'), ArrayHelper::getValue($task, 'hour'), ArrayHelper::getValue($task, 'day'), ArrayHelper::getValue($task, 'month'), ArrayHelper::getValue($task, 'dayofweek'), $this->module->cronGroup);
}
}
$cron->saveCronFile();
// save to my_crontab cronfile
$cron->saveToCrontab();
// adds all my_crontab jobs to system (replacing previous my_crontab jobs)
echo $this->ansiFormat('Cron Tasks started.' . PHP_EOL, Console::FG_GREEN);
} else {
echo $this->ansiFormat('Cron do not have Tasks.' . PHP_EOL, Console::FG_GREEN);
}
}
示例13: attach
public function attach($owner)
{
//ok
parent::attach($owner);
if (!is_array($this->attributes) || empty($this->attributes)) {
throw new InvalidParamException('Invalid or empty attributes array.');
} else {
foreach ($this->attributes as $attribute => $config) {
if (!isset($config['path']) || empty($config['path'])) {
throw new InvalidParamException('Path must be set for all attributes.');
}
if (!isset($config['temp_path']) || empty($config['temp_path'])) {
throw new InvalidParamException('Temporary path must be set for all attributes.');
}
if (!isset($config['url']) || empty($config['url'])) {
$config['url'] = $this->publish($config['path']);
}
$this->attributes[$attribute]['path'] = FileHelper::normalizePath(Yii::getAlias($config['path'])) . DIRECTORY_SEPARATOR;
$this->attributes[$attribute]['temp_path'] = FileHelper::normalizePath(Yii::getAlias($config['temp_path'])) . DIRECTORY_SEPARATOR;
$this->attributes[$attribute]['url'] = rtrim($config['url'], '/') . '/';
$validator = Validator::createValidator('string', $this->owner, $attribute);
$this->owner->validators[] = $validator;
unset($validator);
}
}
}
示例14: up
public function up()
{
$data = (include Yii::getAlias('@common') . '/data/test-adverts.php');
$i = 0;
while ($i++ !== 3) {
foreach ($data as $one) {
$advert = new Advert();
$advert->detachBehavior('timestamp');
$advert->setAttributes($one);
$advert->user_id = rand(1, 50);
$advert->created_at = time() - 3600 * 24 * rand(1, 31) - 3600 * rand(1, 24) + rand(1, 3600);
$advert->updated_at = $advert->created_at;
$advert->term_at = $advert->created_at + 3600 * 24 * rand(1, 31);
if ($advert->save()) {
echo "Advert for user №{$advert->user_id} created\n";
} else {
print_r($advert->getErrors());
}
}
}
foreach (User::find()->all() as $user) {
$profile = new Profile();
$profile->user_id = $user->id;
$profile->name = $user->username;
if ($profile->save()) {
echo "Profile of \"{$user->username}\" created\n";
} else {
print_r($profile->getErrors());
}
}
}
示例15: actionIndex
public function actionIndex()
{
$file = UploadedFile::getInstanceByName('imgFile');
$basePath = dirname(\Yii::getAlias('@common'));
$date = date("Y{$this->separator}m", time());
$uploadPath = "../uploads/Attachment/{$date}";
if (!is_dir($basePath . "/" . $uploadPath)) {
FileHelper::createDirectory($basePath . "/" . $uploadPath);
}
if (preg_match('/(\\.[\\S\\s]+)$/', $file->name, $match)) {
$filename = md5(uniqid(rand())) . $match[1];
} else {
$filename = $file->name;
}
$uploadData = ['type' => $file->type, 'name' => $filename, 'size' => $file->size, 'path' => "/" . $uploadPath, 'module' => null, 'controller' => null, 'action' => null, 'user_id' => \Yii::$app->user->isGuest ? 0 : \Yii::$app->user->identity->id];
$module = \Yii::$app->controller->module;
Upload::$db = $module->db;
$model = new Upload();
$model->setAttributes($uploadData);
$model->validate();
if ($model->save() && $file->saveAs($basePath . '/' . $uploadPath . '/' . $filename)) {
return Json::encode(array('error' => 0, 'url' => "/" . $uploadPath . '/' . $filename, 'id' => $model->id, 'name' => $file->name));
} else {
return Json::encode(array('error' => 1, 'msg' => Json::encode($model->getErrors())));
}
}