I'm working with CakePHP 3(beta 2) version recently launched. I need to integrate Facebook Login using PHP SDKs and I'm not clear with importing vendor files in this version.
In CakePHP 2x, I had used
App::import('Vendor', 'Facebook', array('file' => 'Facebook' . DS . 'src'. DS. 'facebook.php'));
So I need to reproduce the same in CakePHP 3x(I'm not using composer).
Any reference for this?
Well you will have to load it yourself if composer is not an option. You can always use the very basic require method and create a new instance of the vendor class yourself. Reference: http://book.cakephp.org/3.0/en/core-libraries/app.html#loading-vendor-files
Use:
//The following line should do the same like App::import() in the older version of cakePHP
require_once(ROOT . 'vendor' . DS . 'Facebook' . DS . 'src' . DS . 'facebook.php');
$facebookApi = new facebook();
In cakephp3 , to add a new vendor library you can follow below steps :
Place library folder under your_project/vendor/
include library file using require_once(ROOT . DS . 'vendor' . DS . "my_library_folder" . DS . "my_library_base_class.php")
,this includes the library code file in our code.
Include class name in top of Controller like :
namespace App\Controller;
use MyLibraryBaseClass;
,
this imports the library code file in our namespace to be used.
create object of loaded class as
$my_obj= new MyLibraryBaseClass();
the answer provided by Ayman B. does not look like doing the job as expected in the question after i tried it myself , for the following reasons :
the vendor folder in cakephp3 is not located in src folder under APP namespace , it is moved to the ROOT folder , by doing you will not be able to load your Facebook class as expected , try it yourself and you will see the result ...
By loading a vendor file this is does not automatically load the class name itself , if your vendor lib does not follows the follwing rule as PSR-0 rule :
\VENDOR\PACKAGE\TEST.CLASS.PHP and inside the test.class.php there is not a class definition that must be called or imported in your script with a defined namespace keyword in the begining of this script as follows : namespace
then the code above will not work
To correct the answer you have to do some several steps as follows :
1 - Define in bootstrap.php a new cakephp constant like so :
define('VENDOR',ROOT . DS . 'vendor' .DS); as VENDOR constante is removed in cakephp 3.x you can define it yourself
2 - After that , you have to specify the vendor name , the package name and the class name in a vendor constante like :
define('_',; and then you can do $facebookApi = new \\();
this is will work for you as expected in the question
If you have issues try to get back to me , i will show you an example of use as described here ...
I also had the same problem with CakePHP 3.0.
Do the installation as instructed using Composer.
Then You have to properly load the plugin in your controller with the use statement. Like this:
use Ghunti\HighchartsPHP\Highchart;
If you're using the plugin in most of the pages, instead of loading in each Controller, you can add the same line in your bootstrap.php file, right below the other use statements.
That will solve the problem of using the plugin.
As of CakePhp 3.x, the recommended code standard is to use require_once without the brackets"()".
require_once(ROOT.'Folder'.DIRECTORY_SEPARATOR.'requiredfile.ph');
becomes
require_once ROOT.'Folder'.DIRECTORY_SEPARATOR.'requiredfile.ph';
https://book.cakephp.org/3.0/en/contributing/cakephp-coding-conventions.html
Hope that helps someone in the future.
Related
I am working on a drupal7 site.
In Dev, I have enabled and configured simplesamlphp_auth module.
I used features and strongarm to export the configuration to code.
The downloaded feature contain:
myfeature_sso.features.defaultconfig.inc
myfeature_sso.info
myfeature_sso.module
The .inc file contains the configuration values I had put in (admin/config/people/simplesamlphp_auth) correctly
Now, in a few places, I want to replace the hard coded values with variables that change based on the environment. I set the variables at the top of .inc file using variable_get $office_ou = variable_get('office_ou', NULL); ...and . A quick example is $base_url below:
$strongarm = new stdClass();
$strongarm->disabled = FALSE;
$strongarm->api_version = 1;
$strongarm->name = 'simplesamlphp_auth_logoutgotourl';
$strongarm->value = $base_url ;
$export['simplesamlphp_auth_logoutgotourl'] = $strongarm;
When I DPM these variables, they display correct values.
But on a fresh install when I enable myfeature_sso module the value of variables are missing.
missing value from $base_url variable
Can you please point me in the right direction?
Thank you.
I found the answer:
when in features ui, do not add fields relevant to simplesamle to the defaultconfig section. if you have any there remove them.
add fields relevant to simplesaml to storongarm section
export the feature
in your_feature_name.strongarm.inc add any additional php code to function your_feature_name_strongarm()
done
On the same project i'm using phpExcel to generate excel files just fine.
PHPExcel files location:
C:\wamp\www\circulo\app\Vendor\PHPExcel\ (this folder contains PHPExcel.php along with PHPExcel files folder)
Also on the same project, i'm using dompdf alone to generate pdf file just fine (not via PHPExcel). I've just liked a lot how PHPExcel allows excel file construction so i'd like to create pdfs via PHPExcel as well.
dompdf files location:
C:\wamp\www\circulo\app\Vendor\dompdf\
The path seems correct via debugger => C:\wamp\www\circulo\app\Vendor\dompdf\dompdf.php
This is my code to get a pdf file:
I get error:
[PHPExcel_Writer_Exception] Unable to load PDF Rendering library
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
require_once APP . DS . 'Vendor' . DS . 'PHPExcel' . DS . 'PHPExcel.php';
$rendererName = PHPExcel_Settings::PDF_RENDERER_MPDF;
$rendererLibrary = 'dompdf.php';
$rendererLibraryPath = APP . 'Vendor' . DS . 'dompdf' . DS .$rendererLibrary;
Debugger::log($rendererLibraryPath);
if (!PHPExcel_Settings::setPdfRenderer( $rendererName, $rendererLibraryPath )) { die( 'Please set the $rendererName and $rendererLibraryPath values' . PHP_EOL . ' as appropriate for your directory structure' . $rendererLibraryPath ); }
$objPHPExcel = new PHPExcel;
$objWriter = new PHPExcel_Writer_PDF($objPHPExcel);
//$objWriter->save("emptyPdfJustYet.pdf");
Tried their demo 21pdf.php to same results.
Can you help? Thanks a lot!!
When I print the error to log, I realize it is trying to load the dompdf_config.inc.php from an invalid location. See below.
C:\wamp\www\myapp\app\Vendor\dompdf\dompdf.php/dompdf_config.inc.php\n
Rather than altering the class files of PHPExcel, it's wise to change the configuration in your view. Ignoring the $rendererLibrary completely in the $rendererLibraryPath fixed my issue. I think the PHPExcel know how to pick dompdf.php file. Try below code let us know if it doesn't work.
And you are providing wrong render constant too, changed PDF_RENDERER_MPDF to PDF_RENDERER_DOMPDF.
$rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF;
$rendererLibrary = 'dompdf.php';
$rendererLibraryPath = APP . 'Vendor' . DS . 'dompdf';
And for create writer object, I tried
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');
I need help !
I am trying to export products from admin panel but I am getting Error while exporting products and customers.
"Invalid Entity Model"
I have tried One solution from this link :
"Invalid entity model" error while exporting csv file for products
But it didn't work for me , so please can anybody know how to resolved this.
I am trying this by admin panel default import/export function .
Please help me ! I need to solved this error.
Thanks In advance !
This worked for me:
Open abstract class /app/code/core/Mage/ImportExport/Model/Export/Adapter/Abstract.php(63) and replace line number 60:
$destination = tempnam(sys_get_temp_dir(), 'importexport_');
to
$destination = tempnam(Mage::getBaseDir() . '/**vars**/tmp/' , 'importexport_');
For some reason var was not working so i had to use vars
I think this is can be a permission issue. Check the permission to the var/ folder
I have a library in my project.When I want to use this with this code:
require('../Plugin/Utils/DateTimeUtil.php');
it says no such file exists. my cakephp 1s 2.3 what should I do?
The Routing in cakephp is different from pure php.I had something like this.At first you should find the path Plugin folder with this code
$pluginPath = App::path('Plugin');
Then It returns an array which contains the plugin folder's path in 0 index.So you should the returned value like blow:
require($pluginPath[0] . 'Utils' . DS . 'DateTimeUtil.php');
You can use slash instead of DS. DS is DIRECTORY_SEPRATOR.
I uploaded xml file in my cakephp in img/files directory
app->webroot->files->Myfile.xml
and I want to call it from my controller like this
$file = "/files/Myfile.xml";
I am not sure is this the correct path from the controller ot not
of course controller is in app->controllers->my_controller
thanks
Use one of the CakePHP Core Configuration Constants.
WWW_ROOT for example:
$file = WWW_ROOT . "files/MyFiles.xml";