How to USE Setasign/FPDI In laravel 5 Project - laravel

How to USE Setasign/FPDI In laravel 5 Project
How to Set App.php?
I user composer download it and don't know how to use it

Install with composer as described:
https://github.com/Setasign/FPDI
Then...
$pdf = new \FPDF('portrait','mm', 'A4');
If you need Fpdi:
$pdf = new \setasign\Fpdi\Fpdi();

Related

How to solve Error500 Http\Kernel::class on Laravel 5

Hi I have to install finished project created by laravel5 on my client'cloud (CentOS). Everything work find on my windows local host. But I got error500 on real server.
Some error clue:
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture());
$response->send();
$kernel->terminate($request, $response);
This phpmyadmin screen sent from my client
Note that this is cloud server that is not my own. So I can not install composer / run command or install other libraries. Thank you for all answer.
You have to change the vendor and bootstrap folder path in index.php on your current structure
change these two lines from index.php
require __DIR__.'/../vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
to
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';

Class 'GuzzleHttp\Client' not found on Laravel production shared server

I'm trying to retrieve data from an API using Guzzle. I followed the steps in Guzzle website, installed it using composer, added the route and the code in a controller.
I tried these two options:
$client = new Client([
// Base URI is used with relative requests
'base_uri' => 'https://jsonplaceholder.typicode.com/',
// You can set any number of default request options.
'timeout' => 2.0,
]);
and...
$client = new \GuzzleHttp\Client([
// Base URI is used with relative requests
'base_uri' => 'https://jsonplaceholder.typicode.com/',
// You can set any number of default request options.
'timeout' => 2.0,
]);
When running I got the error...
Class 'GuzzleHttp\Client' not found.
I have tried:
require( dirname( __FILE__ ) . '/../../../vendor/autoload.php');
use GuzzleHttp\Client;
In composer.json:
"require": {
"guzzlehttp/guzzle": "^6.3",
...
},
Also...
composer update
composer dump-autoload
php artisan config:clear
The project is on shared hosting; I noticed that there was no Guzzle folder inside the /vendor folder, so I uploaded via FTP. But still the same error.
I've tried everything I found in the forum on this topic; I'm running out of ideas, please any advice would be appreciated.
Thanks in advance for your valuable help.
If you can't run composer on shared hosting, you should upload also /vendor/composer directory (after local $ composer require guzzlehttp/guzzle).

How to install package spatie pdf to img in laravel 5.5?

I already install GhostScript and imagick and it's working well in php artisan, now when i install this package Spatie/pdf-to-image it does not have service provider and alias in installation steps. Can you guys help me how to install this package and make it work?
Not Working:
Working in php artisan:
I also try this one and doesn't work:
$pdf = new Spatie\PdfToImage\Pdf('public/test/test.pdf');
$pdf = new \Spatie\PdfToImage\Pdf('public/test/test.pdf');
Here's my composer:
Try again with:
$pdf = new \Spatie\PdfToImage\Pdf('public/test/test.pdf');
Previous error was caused because of wrong namespace. It's better to add Spatie\PdfToImage\Pdf to use section at the top of document and then in code just write $pdf = new Pdf('path/to/pdf');
You first run this command on CMD :
composer require spatie/pdf-to-image
After add this lines in your controller
use Spatie\PdfToImage\Pdf;
$pdf = new Pdf($pathToPdf);
$pdf->saveImage($pathToWhereImageShouldBeStored);

Lumen with Dingo API routes not defined

Have a fresh install of Lumen 5.2 and new install of Dingo 1.0.*#dev
I have installed the service provided in bootstrap/app.php
Also setup .env file eg
API_VERSION=v1
API_PREFIX=api
API_SUBTYPE=app
API_DEBUG=true
In the Http/routes.php I have added a test route eg
$api = app('Dingo\Api\Routing\Router');
$api->version('v1', ['namespace' => 'App\Http\Controllers\V1'], function ($api) {
$api->get('example', 'ExampleController#test');
});
This route is not working plus in command line if I try php artisan api:routes
I get error
[Symfony\Component\Console\Exception\CommandNotFoundException]
Command "api:routes" is not defined.
Did you mean this?
api:docs
Have I missed something? Also using HTTP Basic if it helps?
In Dingo Documentation -> Creating API Endpoints section you can find this sentence:
"If you're using Laravel 5.1 you can see the registered routes using Artisan.
$ php artisan api:routes
"
If you also run
$ php artisan list
only api:docs is available - api:routes is missing.
That means that this command do not work in Lumen.
composer requires jakubkratina/lumen-dingo-route-list
Add the following code in app/Console/Kernel.php:
protected $commands = [
\JK\Dingo\Api\Console\Commands\RouteListCommand::class
];
By default, as shown in docs, lumen don't ship with api:routes. But you can use lumen-dingo-route-list from jakubkratina. It will add route:list to your artisan.
By the way, I'd to do some adjustments to get it working:
First, include the backlash into the registration
protected $commands = [
\JK\Dingo\Api\Console\Commands\RouteListCommand::class
];
And last, edit vendor/jakubkratina/lumen-dingo-route-list/src/RouteListCommand.php and add this code:
public function handle()
{
return $this->fire();
}

Integrating Doctrine with CodeIgniter

I have successfully installed the latest version of CodeIgniter and have basic MVC pattern working. The problem that I've noticed is that CI doesn't naturally allow for prepared statements when it comes to queries. So, I decided to download Doctrine 1 from GitHub. I'm very new to Doctrine and needed some help integrating it with CI so I followed this tutorial.
In one of my controllers, I have
$this->load->library('doctrine');
$this->em = $this->doctrine->em;
But, when I go to load the view in my browser, I'm greeted with an error reading
Message: require_once(/Applications/MAMP/htdocs/CodeIgniter/application/libraries/Doctrine/Common/ClassLoader.php): failed to open stream: No such file or directory
Upon further inspection of the Doctrine download from GitHub, there doesn't even seem to be a folder titled "common" anywhere in there. I'm very new to CI and especially Doctrine. Does anyone have some advice that can help me get this working? Also, is it possible to use the MySQLi driver instead of the PDO one with Doctrine?
Downloading the Doctrine ORM straight from GitHub doesn't include the other dependencies. These are managed by Composer. If you look inside the composer.json file you can see these dependencies. If you want to install them manually, they are:
doctrine/common
doctrine/inflector
doctrine/cache
doctrine/collections
doctrine/lexer
doctrine/annotations
doctrine/dbal
symfony/console
I believe that's all of them. You will have to merge these files in their appropriate directories as they follow PSR-0 standards for the autoloading of classes.
Alternatively, install Doctrine 2 with Composer with the following composer.json file and any other dependencies will be installed automatically. Then integrate with CodeIgniter.
{
"minimum-stability": "stable",
"require": {
"doctrine/orm": "2.3.*"
}
}
Edit the index.php file of your CodeIgniter app by adding a single line to include the autoloader file before requiring the CodeIgniter core.
require_once BASEPATH.'../vendor/autoload.php';
require_once BASEPATH.'core/CodeIgniter.php';
Also if installing with Composer, use this edited version of the bootstrap as the contents of application/libraries/Doctrine.php, which is what worked for me
<?php
use Doctrine\Common\ClassLoader,
Doctrine\ORM\Tools\Setup,
Doctrine\ORM\EntityManager;
class Doctrine
{
public $em;
public function __construct()
{
// Load the database configuration from CodeIgniter
require APPPATH . 'config/database.php';
$connection_options = array(
'driver' => 'pdo_mysql',
'user' => $db['default']['username'],
'password' => $db['default']['password'],
'host' => $db['default']['hostname'],
'dbname' => $db['default']['database'],
'charset' => $db['default']['char_set'],
'driverOptions' => array(
'charset' => $db['default']['char_set'],
),
);
// With this configuration, your model files need to be in application/models/Entity
// e.g. Creating a new Entity\User loads the class from application/models/Entity/User.php
$models_namespace = 'Entity';
$models_path = APPPATH . 'models';
$proxies_dir = APPPATH . 'models/Proxies';
$metadata_paths = array(APPPATH . 'models');
// Set $dev_mode to TRUE to disable caching while you develop
$config = Setup::createAnnotationMetadataConfiguration($metadata_paths, $dev_mode = true, $proxies_dir);
$this->em = EntityManager::create($connection_options, $config);
$loader = new ClassLoader($models_namespace, $models_path);
$loader->register();
}
}
Note: Version 3 of CodeIgniter when released, will be installable with Composer, but version 2 is not.
For those looking for a tutorial to integrate Doctrine 2 with CodeIgniter, this question and others answers are outdated (for CI 2).
This is a new tutorial for CI 3 I made and I checked is working:
How to install Doctrine 2 in CodeIgniter 3
I repeat it here.
Install Doctrine
Doctrine 2 ORM’s documentation - Installation and Configuration
Doctrine can be installed with Composer.
Define the following requirement in your composer.json file:
{
"require": {
"doctrine/orm": "*"
}
}
Then call composer install from your command line.
Integrating with CodeIgniter
Doctrine 2 ORM’s documentation - Integrating with CodeIgniter
Here are the steps:
Add a php file to your system/application/libraries folder called Doctrine.php. This is going to be your wrapper/bootstrap for the D2 entity manager.
Put the Doctrine folder (the one that contains Common, DBAL, and ORM) inside the third_party folder.
If you want, open your config/autoload.php file and autoload your Doctrine library: $autoload[‘libraries’] = array(‘doctrine’);
Creating your Doctrine CodeIgniter library
Now, here is what your Doctrine.php file should look like. Customize it to your needs.
<?php
/**
* Doctrine 2.4 bootstrap
*
*/
use Doctrine\Common\ClassLoader,
Doctrine\ORM\Configuration,
Doctrine\ORM\EntityManager,
Doctrine\Common\Cache\ArrayCache,
Doctrine\DBAL\Logging\EchoSQLLogger;
class Doctrine {
public $em = null;
public function __construct()
{
// load database configuration from CodeIgniter
require_once APPPATH.'config/database.php';
// include Doctrine's ClassLoader class
require_once APPPATH.'third_party/Doctrine/Common/ClassLoader.php';
// load the Doctrine classes
$doctrineClassLoader = new ClassLoader('Doctrine', APPPATH.'third_party');
$doctrineClassLoader->register();
// load the entities
$entityClassLoader = new ClassLoader('Entities', APPPATH.'models');
$entityClassLoader->register();
// load the proxy entities
$proxiesClassLoader = new ClassLoader('Proxies', APPPATH.'models/proxies');
$proxiesClassLoader->register();
// load Symfony2 classes
// this is necessary for YAML mapping files and for Command Line Interface (cli-doctrine.php)
$symfonyClassLoader = new ClassLoader('Symfony', APPPATH.'third_party/Doctrine');
$symfonyClassLoader->register();
// Set up the configuration
$config = new Configuration;
// Set up caches
if(ENVIRONMENT == 'development') // set environment in index.php
// set up simple array caching for development mode
$cache = new \Doctrine\Common\Cache\ArrayCache;
else
// set up caching with APC for production mode
$cache = new \Doctrine\Common\Cache\ApcCache;
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
// set up annotation driver
$driver = new \Doctrine\ORM\Mapping\Driver\PHPDriver(APPPATH.'models/Mappings');
$config->setMetadataDriverImpl($driver);
// Proxy configuration
$config->setProxyDir(APPPATH.'/models/Proxies');
$config->setProxyNamespace('Proxies');
// Set up logger
$logger = new EchoSQLLogger;
$config->setSQLLogger($logger);
$config->setAutoGenerateProxyClasses( TRUE ); // only for development
// Database connection information
$connectionOptions = array(
'driver' => 'pdo_mysql',
'user' => $db['default']['username'],
'password' => $db['default']['password'],
'host' => $db['default']['hostname'],
'dbname' => $db['default']['database']
);
// Create EntityManager, and store it for use in our CodeIgniter controllers
$this->em = EntityManager::create($connectionOptions, $config);
}
}
Setting up the Command Line Tool
Doctrine ships with a number of command line tools that are very helpful during development.
Check if these lines exists in the Doctrine.php file, to load Symfony classes for using the Command line tools (and for YAML mapping files):
$symfonyClassLoader = new ClassLoader('Symfony', APPPATH.'third_party/Doctrine');
$symfonyClassLoader->register();
You need to register your applications EntityManager to the console tool to make use of the tasks by creating a cli-doctrine.php file in the application directory with the following content:
<?php
/**
* Doctrine CLI bootstrap for CodeIgniter
*
*/
define('APPPATH', dirname(__FILE__) . '/');
define('BASEPATH', APPPATH . '/../system/');
define('ENVIRONMENT', 'development');
require APPPATH.'libraries/Doctrine.php';
$doctrine = new Doctrine;
$em = $doctrine->em;
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
));
\Doctrine\ORM\Tools\Console\ConsoleRunner::run($helperSet);
?>
Now run this script through the PHP command-line and should see a list of commands available to you.
php cli-doctrine.php
Generate mapping classes from database:
php cli-doctrine.php orm:convert-mapping --from-database annotation models/Entities
if you get this error:
Fatal error: Call to undefined function Doctrine\Common\Cache\apc_fetch()
install the APC extension for PHP:
sudo apt-get install php-apc
sudo /etc/init.d/apache2 restart
For production mode you'll want to use a real caching system like APC, get rid of EchoSqlLogger, and turn off autoGenerateProxyClasses in Doctrine.php
Find the link for the doctrine integration in CI
https://github.com/mitul69/codeigniter-doctrine-integration
Please note that code igniter 2 has a little difference in its code organization. In code igniter 2 it is better to put the Doctrine folder in application/third_party folder, instead of application/libraries folder (or else it will not work!).
You can read more about it here
I had the same problem when I tried to follow this tutorial from doctrine user guide
http://doctrine-orm.readthedocs.org/en/latest/cookbook/integrating-with-codeigniter.html
This problem happens when I tried to install via composer so then I went to this web site
http://www.doctrine-project.org/downloads/ and do manually download the DoctrineORM-2.3.3-full.tar.gz version and the error was gone.
The original poster's problem seems to be an issue with autoloading. I was presented with a similar issue when trying to set up CodeIgniter and Doctrine with Composer. In CodeIgniter 3, you can enable the use of composer autoloading, which should allow you to load all Doctrine files correctly. You must point your Composer vendor dir to application/vendor for this to work. You can also do it in older versions, but then you have to include the Composer autoload file manually in your Doctrine library file for CodeIgniter.
If you want more information: I wrote a blog post describing exactly how to do it. http://blog.beheist.com/integrating-codeigniter-and-doctrine-2-orm-with-composer/
you can use this
via composer :
composer create-project rbz/codeigniter your-project
via git :
git clone https://github.com/dandisy/cihmvctwig.git

Resources