I'm trying to install dompdf using composer, I followed the instructions from Installing DOMPDF with Composer
So far I've
In composer.json
...
"require": {
...
"dompdf/dompdf": "~0.6.1"
},
"autoload": {
....
run composer update
in autoload.php already have require __DIR__.'/../vendor/autoload.php';
In vendor/dompdf/dompdf/dompdf_config.inc.php
changed def("DOMPDF_ENABLE_AUTOLOAD", true); to def("DOMPDF_ENABLE_AUTOLOAD", false);
My controller code
```
use Dompdf\Adapter\CPDF;
use Dompdf\Dompdf;
use Dompdf\Exception;
require_once "vendor/dompdf/dompdf/dompdf_config.inc.php";
class ArticleController extends BaseController {
...
public function downloadPdf(){
$dompdf = new Dompdf();
$dompdf->loadHtml('hello world');
$dompdf->render();
$dompdf->output();
}
}
"post" route for ArticleController#downloadPdf
so now when I try to download pdf, if gives me error:
exception 'Symfony\Component\Debug\Exception\FatalErrorException' with
message 'Class 'Dompdf\Dompdf' not found'
have I missed any setup step or doing something wrong?
I don't think that you want use the dompdf 0.6 family. In the 0.6 version all the classes are in global space. But since your code is ready to the 0.7, change it to
"dompdf/dompdf": "~0.7"
and run composer update.
This issue at dompdf github page helped me to solve this error
The latest stable (0.6.1) does not support namespaces and so would not need the use statement in your code. The upcoming release (0.7.0) does include namespace support.
So, I just removed
use Dompdf\Adapter\CPDF;
use Dompdf\Dompdf;
use Dompdf\Exception;
and used new DOMPDF(); instead of new Dompdf(); as with version 0.6.* namespace will not work.
Open file config.php
application/config/config.php
Then Change
$config['composer_autoload'] = "FALSE";
To
$config['composer_autoload'] = "vendor/autoload.php";
Related
I'm trying to use Doctrine MongoDB ODM 2.0 beta on a project with the Yii2 framework, with composer version 1.8.4 and PHP 7.2, but I keep getting the error Fatal error: Uncaught Error: Call to a member function add() on boolean where the code runs $loader->add('Documents', __DIR__);
bootstrap.php file (in DIR/bootstrap.php):
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\ODM\MongoDB\Configuration;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
if ( ! file_exists($file = 'C:/path/to/vendor/autoload.php')) {
throw new RuntimeException('Install dependencies to run this script.');
}
$loader = require_once $file;
$loader->add('Documents', __DIR__);
AnnotationRegistry::registerLoader([$loader, 'loadClass']);
$config = new Configuration();
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Proxies');
$config->setHydratorDir(__DIR__ . '/Hydrators');
$config->setHydratorNamespace('Hydrators');
$config->setDefaultDB('fsa');
$config->setMetadataDriverImpl(AnnotationDriver::create(__DIR__ . '/Documents'));
$dm = DocumentManager::create(null, $config);
I already tried looking at How to properly Autoload Doctrine ODM annotations? and Laravel & Couchdb-ODM - The annotation "#Doctrine\ODM\CouchDB\Mapping\Annotations\Document" does not exist, or could not be auto-loaded and a host of other threads I can't quite recall for help, but I couldn't figure out a solution.
I also tried commenting out the lines below
if ( ! file_exists($file = 'C:/path/to/vendor/autoload.php')) {
throw new RuntimeException('Install dependencies to run this script.');
}
$loader = require_once $file;
$loader->add('Documents', __DIR__);
AnnotationRegistry::registerLoader([$loader, 'loadClass']);
and ran composer dump-autoload and on command line it returned Generated autoload files containing 544 classes, but then I got the problem
[Semantical Error] The annotation "#Doctrine\ODM\MongoDB\Mapping\Annotations\Document" in class Documents\Message does not exist, or could not be auto-loaded.
So the annotations are not auto-loading, and I have no idea how to fix that.
In the model I have:
<?php
namespace Documents;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use \Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
/** #ODM\Document */
class Message
{
/** #ODM\Id */
private $id;
/** #ODM\Field(type="int") */
private $sender_id;
...
I also posted a thread on github at https://github.com/doctrine/mongodb-odm/issues/1976. One commenter stated that "By default, the composer autoload file returns the autoloader in question, which seems to not be the case for you." How can I fix that? The only information I can find online is to put (inside composer.json) the lines:
"autoload": {
"psr-4": {
"Class\\": "src/"
}
},
but then what class should I be loading?
I'm very confused and being pretty new to all these tools (mongodb, yii2, etc.) doesn't help at all. I'm not sure what other information would be helpful else I would post it.
Thanks in advance.
So turns out that the problem (as was mentioned in https://github.com/doctrine/mongodb-odm/issues/1976) was that autoload.php was required twice - once in bootstrap.php and once in web/index.php (of the framework). After the require line in index.php was removed, everything worked fine.
I want to use the tFPDF class and load it with composer-autoload. Since I could not find an official tFPDF composer repo, I simply downloaded the zip file and extracted it in the folder vendor/tfpdf.
Next I added the psr-4 to the composer.json file:
"autoload": {
"psr-4": {
"App\\": "app/",
"tFPDF\\": "vendor/tFPDF"
},
I also added in the tfpdf.php the namespace
<?php
namespace tFPDF;
define('tFPDF_VERSION','1.25');
class tFPDF
{
Finally I produced a new autoload file:
composer dump-autoload
When I now try to create a PDF like this:
$pdf = new \tFPDF\tfpdf();
$pdf->AddPage();
// Add a Unicode font (uses UTF-8)
$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true);
Then the last line will rise an error:
Cannot access private property tFPDF\TTFontFile::$charWidths
Why is that and how can I fix it?
There is now a package https://github.com/Setasign/tfpdf (released in September 2018, a couple of month after the question was asked here)
Install with composer like this:
composer require setasign/tfpdf
you can either use it like this:
namespace your\namespace;
class Document extends \tFPDF
or like this:
$pdf = new \tFPDF();
I got difficult to include composer autoload in Class file, it not working on require_once('../vendor/autoload.php');
require_once('phpmailer/PHPMailerAutoload.php');
require_once('../vendor/autoload.php');
class Test {
function X()
{ ... }
}
What is the proper way to load multiple include files in a class?
If you (correctly) use composer you need do add only the vendor autoload file. Then add the other dependency via composer vendor library or add custom path (composer do the rest for you).
As example, more simply:
start in an empty directory
launch the command:
php composer.phar init
Add the dependency of the library in the composer.json files (if you don't add it in the init process) with the command (suggested by the packagist site)
composer require phpmailer/phpmailer
Then your class should be like:
require_once('../vendor/autoload.php');
class Test {
function X()
{ ... }
}
Hope this help
I think you want something like this
class Loader
{
public function __construct()
{
require_once('phpmailer/PHPMailerAutoload.php');
require_once('../vendor/autoload.php');
}
}
$loader = new Loader();
just add some function as you want
tell me if this help you ... goodluck
Hello guys i have problem with autoloading my class with composer. On Linux all work perfect, but now my boss change env and set Windows. All this work on linux but windows show newbie fatal error:
Fatal error: Class 'AbstractController' not found in
D:\xampp\htdocs\ikacFw\frontController.php on line 7
Common to see my composer.json and stucture for better picture on problem.
Stucture is :
frontController.php
-- vendor
----- Doctrine
----- Ikac
--------- Components
---------- Mvc
------------- Controller
Am trying to load all data from vendor directory.
Composer.json
{
"autoload": {
"psr-0": {
"vendor": ""
}
}
}
Also new component i add manual. Like this :
$loader = require_once 'vendor/autoload.php';
$loader->add('vendor', "Ikac");
Okay next when i try to call :
<?php
require_once 'vendor/autoload.php';
use Ikac\Mvc\Controller;
$a = new AbstractController();
I get error "not found".
My class AbstractController contain defined namespace but dont work again. Like test i do this:
<?php
//vendor/Ikac/Mvc/Controller/AbstractController.php
namespace Ikac\Mvc\Controller;
class AbstractController {
function __construct() {
echo __CLASS__;
}
}
?>
I do from cmd composer dump-autoload, install, but dont work. All this perfect work on linux but here wont. Any idea how to fix this or where i do mistake.
Thanks guys!
SLOVED:
{
"autoload": {
"psr-0": {
"": "vendor/"
}
}
}
Well you should do
<?php
require_once 'vendor/autoload.php';
use Ikac\Mvc\Controller\AbstractController;
$a = new AbstractController();
Your autoloading declaration is wrong.
You will NEVER ever need to include the vendor folder in any autoloading. The vendor folder will contain the autoloading for both all dependencies, and - if configured - for your own classes as well.
You can use Composer to create autoloading for your own classes. Just include the correct info. But from your current info I cannot deduct what would be correct.
I added to my project FOSUserBundle, on localhost it's works fine. But on web server I get
Fatal error: Class 'FOS\UserBundle\FOSUserBundle' not found in
/home/zone24/domains/zone24.linuxpl.info/public_html/worldclock/app/AppKernel.php on line 22
I can't cache:clear because I get this same message.
My autoload.php
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = require __DIR__.'/../vendor/autoload.php';
// intl
if (!function_exists('intl_get_error_code')) {
require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
$loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
}
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
return $loader;
The line from AppKernel.php who make mistake
new FOS\UserBundle\FOSUserBundle(),
Folderfriendsofsymfony in /vendor has 775 permisions
Are you using APC ? If yes, restart apache to clear its cache.
If that does not help, you can always force the autoloader to register a specific namespace with $loader->add(), but you should not have to do that. FOS works fine for me without adding that.