Using Googlemaps in Yii2? - google-maps

How do I use Googlemaps in Yii2 ?
I am not able to follow the Usage placed in http://www.yiiframework.com/extension/yii2-google-maps-library
Installation has been done, but I am getting error
Class 'dosamigos\google\maps\LatLng' not found
Could anyone provide a tutorial/examples where Yii uses Google Maps ?

Normally the use directive for third party extensione start with vendor
could be you must add the vendor to the use where you use these class.
try using
use vendor\dosamigos\google\maps\LatLng;
use vendor\dosamigos\google\maps\services\DirectionsWayPoint;
use vendor\dosamigos\google\maps\services\TravelMode;
use vendor\dosamigos\google\maps\overlays\PolylineOptions;
use vendor\dosamigos\google\maps\services\DirectionsRenderer;
use vendor\dosamigos\google\maps\services\DirectionsService;
use vendor\dosamigos\google\maps\overlays\InfoWindow;
use vendor\dosamigos\google\maps\overlays\Marker;
use vendor\dosamigos\google\maps\Map;
use vendor\dosamigos\google\maps\services\DirectionsRequest;
use vendor\dosamigos\google\maps\overlays\Polygon;
use vendor\dosamigos\google\maps\layers\BicyclingLayer;

Related

operator-sdk does not accept cluster-scoped keyword

I am using operator-sdk version v0.11.0. But when I try to create new project using --cluster-scope option it does not recognize that option and fails with unknown option cluster-scope. I am new to operators. Any idea what am I missing.
Unfortunately, --cluster-scope option is removed now, refer here for more details. But don't worry you can adjust cluster scope through this configuration, Operator SDK: Operator Scope
. I hope it help you. Thanks.

How do I make an Storyblok-API call with multiple parameters incl. "filter_by"?

So far I have seen, the API allows me to add certain parameters to my calls such as filter_by and sort_by.
This works well for me, but I would like to know how do I use multiple parameters at the same time and using the filter_by parameter.
Currently, I am working with the Silex-Boilerplate, which offers me this function:
options('{"sort_by":"name:asc","is_startpage":false}')
I have tried to pass this JSON as options-parameter:
'{"filter_by":"{"component":"reference"}", "sort_by":"name:asc"}'
But it doesn't seem to work. Are there any suggestions about how the JSON could look like?
Thanks in advance!
As I can see you're already using the options Twig helper which is the right way to go.
options('{"sort_by":"name:asc","is_startpage":false}')
you can use the filter_by parameter directly using this syntax:
options('{"sort_by":"name:asc","filter_by[component]":"reference"}')
Also this syntax would be possible:
getStories('starts_with', 1, 10, 'name:ASC', options('{"filter_by":{"component":"reference"}}'))
this will be mapped directly for the API call by our PHP Client Library. Those requests are also cached in your Silex Boilerplate without any extra effort.

How to have class loaded without using "use" but call it as if I used it

I have studied these 2 sources, but none of those works for me.
http://www.yiiframework.com/doc-2.0/guide-concept-autoloading.html
Yii2 - How do I AutoLoad a custom class?
I have created custom helper class which I want to include in every model, controller and view in my application. I am using Yii2 advanced app version 2.0.11, IDE I am using is PHPStorm
QUESTION:
What I want to achieve is to not use use keyword at the beggining of every class but still be able to simply call AppHelper::myMethod() in models, controllers and views.
How is that possible?
Closest I got it working was using this solution https://stackoverflow.com/a/35160997/5395463
All other solutions did not work for me. I am getting errors like:
PHP Fatal Error – yii\base\ErrorException
Class 'frontend\controllers\AppHelper' not found
when I simply dont include use commons\commands\AppHelper;
or when not using namespace as they suggest there with other settings:
Fatal error: Uncaught exception 'yii\base\UnknownClassException'
with message 'Unable to find 'common\commands\AppHelper'
in file: C:\xampp\htdocs\domain.com\web\common/commands/AppHelper.php.
Namespace missing?' in ...
SOLUTION:
Thanks for your responses, I got it working finaly. https://stackoverflow.com/a/42330631/5395463 solution works best for me.
So I removed namespace from that class, but left it in common\commands folder, added require to frontend/web/index.php and backend/web/index.php files (not sure if I should add it to yii file in root too, I didnt, so far it is working good anyways), and changed calls of class from AppHelper::myMethod() to \AppHelper::myMethod() looks like eveything is working now.
In Yii2 You can use an explicit way adding \ to full namespaced name
\frontend\controllers\AppHelper
so you can sue your method
\frontend\controllers\AppHelper::yourMethod();
Solution for not lazy coders:
create component with your class so you can use it like \Yii::$app->my_component
if even this is too much and your IDE is better than Windows Notepad prepare macro that will print this for you
Solution for lazy coders:
Save your class in single PHP file without namespace.
Modify you entry script to include this class - i.e. for Basic Project Template it's /web/index.php; add there
require(__DIR__ . '/path/to/MyClass.php');
For Advanced Project Template modify it properly.
Now you can use your class by calling it like \MyClass (yes, \ is required and yes, your IDE probably will modify it anyway to MyClass with use MyClass; added at the beginning.

Adding 3rd party custom library in Yii2

I have a tax library avalara. How can I add it using Yii2. I have tried in putting in Vendor folder.
used
require "/vendor/avalara/avalara.php"
it does include the file does wasn't able to call the functions inside it.
I have used the avalara library. Extract the file and put the AvaTax and autoload foler in vendor.
Add the a class file in model directory.
$base_path = str_replace("frontend", "", \Yii::$app->basePath);
require_once $base_path . 'vendor/avalara/vendor/autoload.php';
use Yii;
use AvaTax\Address;
use AvaTax\DetailLevel;
use AvaTax\GetTaxRequest;
use AvaTax\Line;
use AvaTax\TaxServiceSoap;
use AvaTax\ATConfig;
use AvaTax\CancelTaxRequest;
After that create custom functions and use them in controller.

When to encode as HTML in Grails

I often see Grails sample code where the programmer has called a method called encodeAsHTML(). I figure I should probably use this in my Grails applications (for security reasons, I assume?), but I was wondering when I should use this method. What objects/properties/etc. are candidates for the encodeAsHTML() method?
Thank you!
Use encodeAsHTML() (or encodeAsJavaScript, etc) for everything that you've got from user. For every string that could be modified by user (got from input form, from request parameter, from external API call, etc)
See also:
https://en.wikipedia.org/wiki/Cross-site_scripting
https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet
https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
I am not sure when this was introduced to Grails, but if in Config.groovy you set grails.views.default.codec="html" then encodeAsHTML() is called whenever you use ${} in GSPs.
Source: http://alwaysthecritic.typepad.com/atc/2010/06/grails-gsp-html-escaping-confusion.html