LARAVEL DOMPDF Wrapper for Laravel 5 - laravel-5.1

I performed the following steps and have an error
step 1
Insert en composer.json
"barryvdh/laravel-dompdf": "0.6.*"
step 2
install
php composer update
step 3
add config/app.php
'providers' => [....
Barryvdh\DomPDF\ServiceProvider::class,
'aliases' => [....
'PDF' => Barryvdh\DomPDF\Facade::class,
step 4
routes.php
Route::resource('pdf', 'PdfController');
step 5 create controller from php artisan make:controller PhpController
insert code:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class PdfController extends Controller
{
public function Index() {
$pdf = App::make('dompdf.wrapper');
$pdf->loadHTML('<h1>Test</h1>');
return $pdf->stream();
}}
step 5 ERROR
call url localhost/public/pdf
FatalThrowableError in PdfController.php line 16:
Fatal error: Class 'App\Http\Controllers\App' not found
line 22 ....
$pdf = App::make('dompdf.wrapper');
Thank you! for your comments.

You'll have to use the App Facade
use Illuminate\Support\Facades\App;

Try to use this code
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App;

You forgot to prefix the App namespace with \. The correct way to call that function would be as follows:
$pdf = \App::make('dompdf.wrapper');

Related

tcpdf on Lumen Class 'PDF' not found

I created a new project with Lumen 5.4.7 and I added the TCPDF library from elibyy/tcpdf-laravel version 5.4.2 (with Lumen support):
composer require elibyy/tcpdf-laravel "5.4.2"
I enabled the Facades and Service Provider in bootstrap/app.php with
$app->withFacades();
$app->register(Elibyy\TCPDF\ServiceProvider::class);
And I created a basic Controller:
<?php
namespace App\Http\Controllers;
use \PDF;
class PdfController extends Controller
{
/**
* Create a test PDF file.
*
* #return void
*/
public function createTestPdf()
{
PDF::SetTitle('Hello World');
PDF::AddPage();
PDF::Write(0, 'Hello World');
PDF::Output('hello_world.pdf');
echo "Fatto!";
}
}
with a basic route:
$app->get('pdf', 'PdfController#createTestPdf');
But when I try to access to /pdf I get the following error:
Fatal error: Class 'PDF' not found in /Users/m/Documents/Projects/lumen-pdf/app/Http/Controllers/PdfController.php on line 15
(1/1) FatalErrorException
Class 'PDF' not found
in PdfController.php (line 15)
at Application->handleShutdown()
in RegistersExceptionHandlers.php (line 54)
at Application->Laravel\Lumen\Concerns\{closure}()
Could you help me please?
I solved my problem.
One line was missing into bootstrap/app.php to add a new class_alias for Elibyy\TCPDF\Facades\TCPDF to PDF:
class_alias('Elibyy\TCPDF\Facades\TCPDF', 'PDF');
Thanks!

laravel route and controller not working

Laravel 5.1
//////////////////////////////////////////////////////
My Route://
Route::resource('/books', 'BookController#index');
////////////////////////////////////////////////////////
My BookController//
<?php
namespace App\Http\Controller;
use App\Book;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class BookController extends Controller {
/**
* Display a listing of the resource.
*
* #return Response
*/
public function index()
{
$books=Book::all();
return view('books.index',compact('books'));
}
}
/////////////////////////////////////////////////////////
My Url:
http://localhost:8000/books
/////////////////////////////////////////////////////////
My Browser show this error//
Whoops, looks like something went wrong.
1/1 ReflectionException in
C:\xampp\htdocs\bookstore\vendor\laravel\framework\src\Illuminate\Container\Container.php
line 737:
Class App\Http\Controllers\BookController does not exist
Notice the error says Class App\Http\Controllers\BookController does not exist. That doesn't match your namespace set in the BookController class.
It's looking for your class in the "App\Http\Controllers" location with an "s". Your namespace says "App\Http\Controller" (without the "s"). Fix your namespace and it should work.
You are using a resourceful route and you don't need to specify the method.Also the / before the books is not needed.
Your route should be like this:
Route::resource('books', 'BookController');

Zend framework 2: class_exists('mPDF') returns true yet new mPDF() fails

I want to use mPDF in a controller as follows (test scenario):
function indexAction() {
require_once('libraries/mpdf/mpdf.php');
var_dump(class_exists('mPDF')); //prints true
$mpdf = new mPDF(); //fails with 'class not found in Application/Controller (current namespace)
}
The class mPDF is declared inside the mpdf.php file and i've checked if the file gets loaded and it does.
To solve this you have to add \ infront of the class name to reset namespace
function indexAction() {
require_once('libraries/mpdf/mpdf.php');
var_dump(class_exists('mPDF')); //prints true
$mpdf = new \mPDF(); //fails with 'class not found in Application/Controller (current namespace)
}
error message is the clue to this
//fails with 'class not found in Application/Controller (current namespace)
I however dont know why the class_exist returns true. It did not do that when i had my class in autoload_classmap.php but when i require_once i got the same problem.
also if you dont want to require_once the php file in the function you can add it to class mapp file at the root of the module
<?php
// Generated by ZF2's ./bin/classmap_generator.php
return array(
'mPDF' => __DIR__ . 'path/to/file/mpdf.php',
);
I do this with PHPMailer

Zend Framework 2 ClassMapAutoloader error

I am very new to Zend Framework 2 and am using the book “Web Development with Zend Framework 2” by Michael Romer as my guide. I’m at the end of chapter 5 and the subject of the ClassMapAutoloader is presented. The conclusion of the discussion is that my Helloworld module now has the file and directory structure of ->
Module.php
autoload_classmap.php
autoload_function.php
autoload_register.php
config/
module.config.php
public/
images/
css/
js/
src/
Helloworld/
Controller/
IndexController.php
views/
Helloworld/
Index/
index.phtml
As far as I can tell the files of interest that setup Classmap autoloading are Module.php, autoload_classmap.php, autoload_function.php, autoload_register.php. The contents of these files are
Module.php ->
<?php
namespace Helloworld;
Class Module {
public function getAutoloaderConfig() {
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php'
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__
)
)
);
}
public function getConfig() {
return include __DIR__ . '/config/module.config.php';
}
}
autoload_function.php ->
<?php
return function ($class) {
static $classmap = null;
if ($classmap === null) {
$classmap = include __DIR_ . '/autoload_classmap.php';
}
if (!isset($classmap[$class])) {
return false;
}
return include_once $classmap[$class];
};
autoload_register.php ->
<?php
spl_autoload_register(include __DIR__ . '/autoload_function.php');
autoload_classmap.php ->
<?php
//require_once 'autoload_register.php';
return array();
This all works when I have that blank array return in autoload_classmap.php BUT in the book the example has require_once 'autoload_register.php';. When I uncomment that line I get the following error ->
The error is -> [Tue Jun 18 16:29:20 2013] [error] [client 199.82.163.121] PHP Fatal error: Uncaught exception 'Zend\Loader\Exception\InvalidArgumentException' with message 'Map file provided does not return a map. Map file: "/var/www/ZendApp/module/Helloworld/autoload_classmap.php"' in /var/www/ZendApp/vendor/zendframework/zendframework/library/Zend/Loader/ClassMapAutoloader.php:88\nStack trace:\n#0 /var/www/ZendApp/vendor/zendframework/zendframework/library/Zend/Loader/ClassMapAutoloader.php(117): Zend\Loader\ClassMapAutoloader->registerAutoloadMap('/var/www/ZendAp...')\n#1 /var/www/ZendApp/vendor/zendframework/zendframework/library/Zend/Loader/ClassMapAutoloader.php(60): Zend\Loader\ClassMapAutoloader->registerAutoloadMaps(Array)\n#2 /var/www/ZendApp/vendor/zendframework/zendframework/library/Zend/Loader/ClassMapAutoloader.php(46): Zend\Loader\ClassMapAutoloader->setOptions(Array)\n#3 /var/www/ZendApp/vendor/zendframework/zendframework/library/Zend/Loader/AutoloaderFactory.php(100): Zend\Loader\ClassMapAutoloader->__construct(Array)\n#4 /var/www/ZendApp/vendor/zendframework/zendframework/library/Zend/M in /var/www/ZendApp/vendor/zendframework/zendframework/library/Zend/Loader/ClassMapAutoloader.php on line 88
I know that returning the blank array causes the getAutoloaderConfig() in the Module class of Module.php to default to the StandardAutoloader and thus it works but Why? I’d really like to get the ClassMapAutoloader to do its thing in this example. How do I get this to work? Thanks in advance for your reply.
James Eastman
There is no such thing as requiring the autoloader register function in the classmap file. That is not even in the books.
You can generate the autoloader classmap with the classmap generator provided within Zend Framework 2. You can generate the autoload_classmap.php file so it is populated with all the php classes in your module.
Usage:
$ cd module/MyModule
$ ../../vendor/zendframework/zendframework/bin/classmap_generator.php -w
This works in the case you loaded Zend Framework 2 with composer, which loads the library in the vendor/ directory.
in Module.php after name add the two lines of code!
namespace Helloworld;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;

How to use a Component with Admin Generator?

I know we can use components with the admin generator (thanks to ~ symbol).
However, in the components.class.php, how to call the auto-generated class ?
At this moment, I'm using this :
require_once dirname(__FILE__).'/../lib/commissionGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/commissionGeneratorHelper.class.php';
class commissionComponents extends autoCommissionComponents
{
}
But I obtain this error :
Fatal error: Class 'autoCommissionComponents' not found in /home/site/liguelorraine/apps/saSecureLigueLorraine/modules/commission/actions/components.class.php on line 7
There are no automatically generated component classes. Just extends sfComponents as usual.

Resources