Yii2 show image in backend from frontend - settting alias - php

In my project I used an image cropper widget. I setup the widget, that it save in frontend/web/upload. But in backend I save the images to frontend too.
This is working perfect. Then i want to show the image on the backend, if its exist. And i want to reach the frontend.
Thats why i want to set my own aliases in params-local.php file.
But I using vhosts to my webpages and I want to set Aliases to them.
In Yii2 documentation i found an article from aliases, but it wont help me. I mean i tried to use but it wont work.
I tried this:
return [
'aliases' => [
'#front' => 'http://front.mypage.dev',
'#back' => 'http://back.mypage.dev',
],
];
And I also tried this aswell:
Yii::setAlias('#front', 'http://front.mypage.dev');
Yii::setAlias('#back', 'http://back.mypage.dev');
But when i try to echo Yii::getAlias('#front'); it sais
Invalid Parameter – yii\base\InvalidParamException
Invalid path alias: #front
Maybe someone has a solution for this?
Thanks a lot.

Add in backend/config/params.php like:
return [
'front' => 'http://front.mypage.dev',
'back' => 'http://back.mypage.dev',
];
and use it from:
Yii::$app->params['front']
Yii::$app->params['back']
Let me know your thought.

Try this:
Yii::setAlias('#front', 'http://front.mypage.dev');
Yii::setAlias('#back', 'http://back.mypage.dev');
echo Yii::getAlias('#front');
echo Yii::getAlias('#back');
echo Yii::getAlias('#frontend/path/to/file');
echo Yii::getAlias('#backend/path/to/file');
Yii2 Playground
setting-aliases-in-yii2-within-the-app-config-file

Related

PHP and Protobuf FieldMasks for Google API

I found the documentation just fine, but for the life of me I can't figure out how to set up the FieldMasks in PHP to update a CloudSchedulerClient.
The command should be like this:
$client->updateJob($job, $updateMask); but no matter what I set the $updateMask variable to, my code keeps saying Expect Google\Protobuf\FieldMask. If for instance I wanted to update the description of a cron job to "test", 'description' => 'test', how should I go about that?
If you share some code, that would be helpful.
The error suggests that you are not providing the proper type. Your code should look something like this:
use Google\Protobuf\FieldMask;
$updateMask = new FieldMask([
'paths' => ['description']
]);
$client->updateJob($job, $updateMask);

The best way to edit slider images and links

I have a slider in the index page, which has 3 pictures and this pictures has links. What is the best way to change pictures and links: make db table sliders:
id
pic
link
and work with it, or make in config->settings.php something like this:
<?php
return [
'new_products_count' => 6,
'popular_products_count' => 6,
'paginate' => 20,
'admin_paginate' => 10,
'slider'=>[
1=>['img'=>'1.jpg','link'=>'www1'],
2=>['img'=>'2.jpg','link'=>'www2'],
3=>['img'=>'3.jpg','link'=>'www3']
]
];
and work with it like this:
Config::set('settings.slider[1]['img']=>'newimg.jpg')
Config::set('settings.slider[1]['link']=>'newWWW')
?
Would be safer to keep in the database for a couple of reasons.
1- If you cache your configuration, it may sometimes behave like a buggy application. I mean after changing an image and coming back, you may see the previous image displaying again. Because what you change at runtime is not persisted. Try to update a config option, e.g:
config(['database.connections.sqlite.driver' => 'fake']);
Then go check the file. tadaaa... the file didn't change.
2- You database is unlimited. YOu can add an infinite number of images (links) with much more options. Of course, you can also pass options to config() but using Eloquent or Query builder is more flexible.

Yii url manager for modules

I'm using Yii 1.1.15, and am trying to shorted my url's for a module i have. Right now the url are like this
url/alerts/alerts/admin
url/alerts/alerts/create
i'd like to change it to
url/alerts/admin
url/alerts/create
I have this, but doesn't work
'<action:(create|admin)>' => 'alerts/<action>',
Try this :
'alerts/<action:(create|admin)>' => 'alerts/alerts/<action>',

jason lewis basset did not show icons well in laravel 4

I have a problem with rendering css+html of the bootstrap theme in laravel 4. I by a admin template, and web browser show me something like that . I use jasonlewis basset to generate admin template. How to fix this?
I use this in app\config\packages\jasonlewis\basset\config.php:
'collections' => array(
'public' => function($collection)
{
$collection->directory('assets/css', function($collection)
{
$collection->add('bootstrap.min.css');
$collection->add('jquery-ui-1.10.3.custom.css');
$collection->add('fullcalendar.css');
$collection->add('chosen.css');
$collection->add('select2.css');
$collection->add('jquery.cleditor.css');
$collection->add('jquery.noty.css');
$collection->add('noty_theme_default.css');
$collection->add('elfinder.min.css');
$collection->add('elfinder.theme.css');
$collection->add('uploadify.css');
$collection->add('jquery.gritter.css');
$collection->add('font-awesome.min.css');
$collection->add('font-awesome-ie7.min.css');
$collection->add('glyphicons.css');
$collection->add('halflings.css');
$collection->add('dropzone.css');
$collection->add('xcharts.min.css');
$collection->add('jquery.easy-pie-chart.css');
$collection->add('icheck/all.css');
$collection->add('bootstrap-editable.css');
$collection->add('lato300.css');
$collection->add('lato.css');
$collection->add('kausha.css');
$collection->add('style.min.css');
$collection->add('retina.min.css');
})->apply('UriRewriteFilter')->apply('CssMin');
$collection->directory('assets/js', function($collection)
{
$collection->add('html5.js');
$collection->add('respond.min.js');
$collection->add('jquery-2.0.3.min.js');
})->apply('JsMin');
},
'admin' => function($collection)
{
$collection->directory('assets/css', function($collection)
{
$collection->add('bootstrap.min.css');
$collection->add('jquery-ui-1.10.3.custom.css');
$collection->add('fullcalendar.css');
$collection->add('chosen.css');
$collection->add('select2.css');
$collection->add('jquery.cleditor.css');
$collection->add('jquery.noty.css');
$collection->add('noty_theme_default.css');
$collection->add('elfinder.min.css');
$collection->add('elfinder.theme.css');
$collection->add('uploadify.css');
$collection->add('jquery.gritter.css');
$collection->add('font-awesome.min.css');
$collection->add('font-awesome-ie7.min.css');
$collection->add('glyphicons.css');
$collection->add('halflings.css');
$collection->add('dropzone.css');
$collection->add('xcharts.min.css');
$collection->add('jquery.easy-pie-chart.css');
$collection->add('icheck/all.css');
$collection->add('bootstrap-editable.css');
$collection->add('lato300.css');
$collection->add('lato.css');
$collection->add('kausha.css');
$collection->add('style.min.css');
$collection->add('retina.min.css');
})->apply('UriRewriteFilter')->apply('CssMin');
$collection->directory('assets/js', function($collection)
{
$collection->add('html5.js');
$collection->add('respond.min.js');
$collection->add('jquery-2.0.3.min.js');
//$collection->requireDirectory('../../../vendor/twbs/bootstrap/js');
$collection->add('jquery-migrate-1.2.1.min.js');
$collection->add('bootstrap.min.js');
$collection->add('jquery-ui-1.10.3.custom.min.js');
$collection->add('jquery.ui.touch-punch.min.js');
$collection->add('jquery.sparkline.min.js');
$collection->add('fullcalendar.min.js');
$collection->add('excanvas.min.js');
$collection->add('jquery.flot.min.js');
$collection->add('jquery.flot.pie.min.js');
$collection->add('jquery.flot.stack.min.js');
$collection->add('jquery.flot.resize.min.js');
$collection->add('jquery.flot.time.min.js');
$collection->add('jquery.autosize.min.js');
$collection->add('jquery.placeholder.min.js');
$collection->add('moment.min.js');
$collection->add('daterangepicker.min.js');
$collection->add('jquery.easy-pie-chart.min.js');
$collection->add('jquery.dataTables.min.js');
$collection->add('dataTables.bootstrap.min.js');
$collection->add('custom.min.js');
$collection->add('core.min.js');
$collection->add('pages/index.js');
})->apply('JsMin');
}
You sure do have a lot of assets. This is happening either because the path to you're glyphicons is wrong - bear in mind that when basset compiles (or even when it doesnt compile) your css it will move it to a different directory. Unfortunately you havent included this section of the config so I dont know where you have told it to move the files to. If you have a relative path to the glyphicon assets this may be the source of the issue.
You could verify if this is the issue by setting all your assets to raw (this will force them to be loaded from their existing location:
e.g.
$collection->add('bootstrap.min.css')->raw();
Additionally I have had some issues in the past with getting font-awesome to play nicely. I suggest you take this out of the equation whilst you work out whats gone wrong - in fact I would comment out as many assets as possible to isolate the issue.
As a final point - Why are you using the css? One of the wonderful things about bootstrap is that it's written in less, one of the wonderful things about basset is it can pre-compile less... I'll let you fill in the gaps

SugarCRM - How to set the default homepage for all users

I am using SugarCRM Version 5.2.0k (Build 5837). I would like to be able to set a default home page (with dashlets I've created myself) that will be the same for all users, can anyone advice on best way to do this?
Thanks in advance for your help
I'd like to know how to do this too... see here for some ideas, but it's clear that it's not a supported feature.
I wonder if you can write a module that installs a hook for post user creation (assuming that this hook is provided) and then populate the appropriate part of the user preferences table when the hook is invoked. Of course, your module will probably break with each upgrade of SurgarCRM, so this might be more trouble than it i worth.
Edit:
I had a look at the Dash Manager module that is referenced in the thread I linked to above. It's approach is to copy the preferences of the admin user to all other users when the administrator clicks a link in the admin page. So, the admin user is used as a sort of template for other users. Rudimentary solution, but not a bad start - using a template user and treating the preferences (as stored in the DB table) as opaque seems like the way to go.
It's quite easy to do it.
I have done it in SugarCRM 6.5.23.
Here I have mentioned steps to do it:
Just copy sugarcrm_root/modules/Home/index.php and paste it in SugarCRM_root/custom/modules/Home/index.php.
Now you can customize it's behavior as you want.
You can remove default dashlets and add your own dashlets by creating one file at SugarCRM_root/custom/modules/Home/dashlets.php and add this code in it:
<?php
unset($defaultDashlets);
$defaultDashlets = array(
'CustomDashlet' => 'ModuleName',
'UpcomingAppointmentsDashlet' => 'Meetings', //Example
);
Once you do this thing still you have 3 dashlets left in your hook code you can remove it if it's needed code for that hook is like this:
$dashlets[create_guid()] = array(
'className' => 'iFrameDashlet',
'module' => 'Home',
'forceColumn' => 0,
'fileLocation' => $dashletsFiles['iFrameDashlet']['file'],
'options' => array('titleLabel' => 'LBL_DASHLET_DISCOVER_SUGAR_PRO',
'url' => '...',
'height' => 315,
));
Hope this will help you. :)

Categories