I am trying to implement Facebook SDK for PHP with Yii 2. I am totally new to this and doing this in my config file:
'facebook' => [
'class' => 'frontend/components/Facebook/Facebook'
]
The 'Facebook' folder is placed inside components folder, inside frontend. I am trying to include it like this:
use Facebook/Facebook;
But it doesn't work. How can I do it right? Any help regarding this?
In Facebook class you should have namespace:
namespace frontend\components\facebook;
And then use this like:
use frontend\components\Facebook\Facebook;
If u defined it in components in config just use it like:
\Yii::$app->facebook
it you are doing social login yii2-eauth is best for every type of social login....
check git code here
Checkout demo here
Related
I use PHP Symfony for my backend. I need to download cloudinary data into my EC2 instance using the cloudinary url of a single file or folder. For that, i wanted to create a PHP script to do that.
I use cloudinary_php package (https://packagist.org/packages/cloudinary/cloudinary_php). I use the upload functionality to store my data, but it doesn't seem to have a download method.
I wanted to know if this is possible, with cloudinary_php or with another pachage ?
Thanks for your help!
In your Symfony's project root folder, you should have the file composer.json. Then add following entry that looks like this:
{
"require": {
"cloudinary/cloudinary_php": "^2"
}
}
Then make sure to install the dependencies. Follow this composer doc. After that, you can now then plug in your API key and Secret then instantiate a Cloudinary object:
require 'vendor/autoload.php';
use Cloudinary\Configuration\Configuration;
use Cloudinary\Api\Upload\UploadApi;
// configure globally via a JSON object
Configuration::instance([
'cloud' => [
'cloud_name' => 'your-cloud-name-here',
'api_key' => 'xxxxxxxx',
'api_secret' => 'xxxxxxxxxx'
],
'url' => [
'secure' => true
]
]);
//Instanstiate and generate an archive
$cloudinary = (new UploadApi());
$response = $cloudinary->createZip([
'tags' => 'jeep', // Change this base on your use case
'resource_type' => 'image' // Change this base on your use case
]);
//Check the response object
print_r($response);
//Make your own implementation here to download the archive.
The response object above should have the secure_url key where you can directly download the generated archive link. Visit the documentation here for more info. There are also lots of optional parameters you can pass and you should choose what works best for you. You should also consider Symfony's security best practices when referencing sensitive information. For general Cloudinary PHP SDK integration, visit this.
I was using your plugin these days trying to implement a googlemap on my site. I followed all installation steps and set a variety of variables. I am on laravel 5.4.
I stuck in this error: "Google maps API key is required.". Even I try to hard set the API in your core function, then it throws another error says "region is required". seems like the config file cannot be reached. I also tried to fix the file permissions, but unfortunately that's not the issue. Do you have any ideas about this? This is part of my controller file
use Cornford\Googlmapper\Mapper;
use Cornford\Googlmapper\Facades\MapperFacade;
use Illuminate\Support\Facades\Route;
public function index(Mapper $mapper)
{
............
$firstMapItem = reset($mapArrays);
$mapper->map(
$firstMapItem->latitude, $firstMapItem->longitude,
[
'zoom' => 10,
'markers' => ['title' => 'My Location', 'animation' => 'DROP'],
'clusters' => ['size' => 10, 'center' => true, 'zoom' => 20]
]
);
// Add information window for each address
foreach ($mapArrays as $mapArray) {
$mapper->marker($mapArray->latitude, $mapArray->longitude);
}
}
Route
Route::get( '/map', 'MapController#index');
view
<div style="width: 100%; height: auto;">
{!! Mapper::render() !!}
</div>
BTW, I already changed the API value there, my problem is this API value has not been referenced. But if I move the Mapper function from the controller to the Route file, everything is fine. But if I do what I did as above, the API value from the googlmapper.php file isn't referenced.
Finally, make it works. Not because of the API issue, the API has been correctly placed.
change
use Cornford\Googlmapper\Mapper;
to
use Mapper;
Very simply Facades things I think.
credit to #zubinkadva on GitHub. Also the package author #bradcornford also mentioned
"however for reference you can also use the following:
use Cornford\Googlmapper\Facades\MapperFacade as Mapper;
"
From the package docs:
You also need to set your Google API Key into the GOOGLE_API_KEY environment variable.
So, get the API key first here.
Then add this line in the .env file in Laravel project root:
GOOGLE_API_KEY=your_real_api_key_here
As Docs said you have to add this
GOOGLE_API_KEY="your google api key here"
in your .env file in the root of your project to get this key you have to go in Google Console
Good day.
I've just started learning ZF2, replicated the Album example step-by-step, and then decided to make it a bit more interesting by adding user registration, and then make the two work together in some way, so i added a new 'Auth' module.
So, when i only had one module in the module list (aside from the Application module) in application.config.php, it was all fine, but when i added the Auth module to the list like so:
'modules' => array('Application', 'Album','Auth',)
i got the following error when trying to access any views from the album module which was working absolutely fine prior to this change:
Zend\View\Renderer\PhpRenderer::render: Unable to render template "album/album/index"; resolver could not resolve to a file
But when i changed the order in which the modules are presented in this array like so:
'modules' => array('Application', 'Auth','Album',)
not a single view (and it has only one) from the Auth module could be rendered, while the Album module was fine.
Zend\View\Renderer\PhpRenderer::render: Unable to render template "auth/user/index"; resolver could not resolve to a file
Both of these views exist at these locations, but the renderer doesn't see them for some reason.
You can see the project's contents here.
Thank you for any tips in advance.
Looks like you copy pasted the the view manager config for Auth module.config.php.
This should be auth rather than album for your templates to work correctly.
'view_manager' => array(
'template_path_stack' => array(
'auth' => __DIR__ . '/../view',
),
),
I'm writing an application in cakephp 3.
I want to have global variables that can be read from everywhere, even in layouts and views.
how can I save these parameters?
you can write configuration like this in your core.php :
Configure::write('Company', [
'name' => 'Pizza, Inc.',
'slogan' => 'Pizza for your body and soul'
]);
and when you can read it like this:
Configure::read('Company.name');
Configure::read('Company.slogan');
Configure::read('Company');
if you don't like to write new parameters in core.php. you can write it in another file and load it into core.php.
further tutorials are in http://book.cakephp.org/3.0/en/development/configuration.html
I am new to yii2, but I have been using Yii 1.x for quite a long time. I am using advanced template of Yii2 and implementing custom theme for the backend. I am using https://github.com/mithun12000/adminUI theme for the backend. I have set up my theme as follows:
install theme using composer
added theme support in backend/config/main.php as follows:
'view'=>[
'theme'=>[
'pathMap'=>['#app/views'=>'#webroot/themes/admin/views'],
'baseUrl'=>'#web/themes/admin'
]
],
Changed namespace app\assets; into namespace backend\assets; in backend/assets/AppAsset.php
I created my theme in web folder as backend/web/themes/admin and put my views there.
In my controller, to use the theme I just created, I put the following code:
$this->getView()->theme = Yii::createObject([
'class' => '\yii\base\Theme',
'pathMap' => ['#backend/views' => '#webroot/themes/admin/views'],
'baseUrl' => '#web/themes/admin',
]);
The login screen works fine. But if I have any widget, suppose Gridview, then I get namespace error. The error I get is:
Unknown Class – yii\base\UnknownClassException
Unable to find 'app\assets\AppAsset' in file: D:\projects\bmjobs\site\backend/assets/AppAsset.php. Namespace missing?
If I change the namespace in AppAsset.php to app\assets, then I get the following error:
PHP Fatal Error – yii\base\ErrorException
Call to a member function checkAccess() on a non-object
I am not sure where I went wrong. Can anybody please help me out with this?
Thanks in advance.
you may change your pathMap in backend/config/main.php
'pathMap' => ['#app/views' => '#app/themes/admin/views'],