Fatal error: Class 'mPDF' not found in myproject/vendor/kartik-v/yii2-mpdf/Pdf.php on line 281 - yii2

I have used kartik pdf extension to print my report in pdf format.Things are going well in my local computer but when i put my codes in server error appears like this:
Fatal error: Class 'mPDF' not found in myproject/vendor/kartik-v/yii2-mpdf/Pdf.php on line 281
In server i have uploaded yii2-mpdf folder inside kartik-v folder and also mpdf folder.
My code of controller for pdf print:
use kartik\mpdf\Pdf;
public function actionPearlFinancialReport()
{
$pdf = new Pdf([
//'mode' => Pdf::MODE_CORE,
'mode' => Pdf::MODE_UTF8,
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => Pdf::DEST_BROWSER,
'content' => $this->renderPartial('_financial_report', ['model' => $model,'parameter'=>$parameter]),
'cssFile' => '#vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
'cssInline'=> '.kv-heading-1{font-size:15px;text-align:center;}',
'options' => ['title' => 'Pearl Financial Report'],
'methods' => [
'SetHeader'=>['Pearl Financial Report'],
'SetFooter'=>['{PAGENO}'],
]
]);
$response = Yii::$app->response;
$response->format = \yii\web\Response::FORMAT_RAW;
$headers = Yii::$app->response->headers;
$headers->add('Content-Type', 'application/pdf');
}
What to do?

Try this
'cssFile' => '#vendor/kartik-v/yii2-mpdf/src/assets/kv-mpdf-bootstrap.min.css',

Try to register this extension with composer:
For example my work directory is c:\xampp\htdocs\my-project
In a command prompt -> cd c:\xampp\htdocs\my-project
And register with this command:
C:\xampp\htdocs\my-project>php c:\xampp\htdocs\composer.phar require kartik-v/yii2-mpdf "dev-master"
I always register kartik's extensions with this metod, I hope want to be useful for you too.

Related

Multiple Paths for img and css in CakePHP 3.4

I am running multiple cake apps which share one core/baseapp.
The basic structure is:
www/myapp1
www/myapp2
www/myapp3
www/baseapp
In each 'myapp' inside app.php I point the path for templates and plugins to the myapp and baseapp so that if no file is found in myapp the one from baseapp is used:
'App' => [
'imageBaseUrl' => 'img/',
'cssBaseUrl' => 'css/',
'jsBaseUrl' => 'js/',
'paths' => [
'plugins' => [ROOT.DS .'modules'.DS, BASEROOT . DS . 'modules' . DS],
'templates' => [APP . 'Template' . DS, BASEROOT.'/src/Template'.DS ],
],
],
(i include classes from baseapp inside composer.json which is probably not relevant for this question)
That works pretty well.
Question:
How can I make it include img, css and js in the same manner?
I want to have to folders where cake should search for the files for every app.
'App' => [ 'imageBaseUrl' => ['img/', BASEROOT. DS . 'webroot/img/']
does not work.
My Solution: In the folder webroot I made a link to BASEROOT (with the name 'baseroot') and then I made the File src/View/UrlHelper
class UrlHelper extends CakeUrlHelper{
public function webroot($file){
//code
if (file_exists(\Cake\Core\Configure::read('App.wwwRoot') . $file)) {
$webPath = $this->request->getAttribute('webroot') . $asset[0];
}else{
$webPath = $this->request->getAttribute('webroot').'baseroot'.DS.$asset[0];
}
//more code
}
}

Class Swift_Transport_Esmtp_Auth_CramMd5Authenticator does not exist

I can't seem to send an email with laravel 5.4 on after setting the right configurations in config/mail.php. I'm using smtp driver here is summary of my files.
Here is the config/mail.php
<?php
return [
'driver'=>env('MAIL_DRIVER', 'smtp'),
'host'=>env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'info#afecamworld.org'),
'name' => env('MAIL_FROM_NAME', 'National President'),
],
'encryption' => env('MAIL_ENCRYPTION', 'ssl'),
'username' => env('MAIL_USERNAME', 'my-gmail-email'),
'password' => env('MAIL_PASSWORD', 'my-gmail-password'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
This is the SendActivationEmail class
<?php
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class SendActivationEmail extends Notification {
use Queueable;
protected $token;
public function __construct($token) {
$this->token = $token;
}
public function via($notifiable){
return ['mail', 'database'];
}
public function toMail($notifiable) {
return (new MailMessage)->subject('Activation Your Account')->greeting('Hello!')->line('You need to activate your email before you can login.')->action('Activate Email', route('activate_account', ['token' => $this->token]))->line('Thank you for joining our Online Community!');
}
}
?>
This is the top part of the error
(1/1) ReflectionException
Class Swift_Transport_Esmtp_Auth_CramMd5Authenticator does not exist
in DependencyContainer.php (line 309)
I will be grateful for any help to resolve this error on dreamhost, thanks.
The best way to resolve this problem is to delete the files in the vendor folder and redo composer install and composer update, that's how I fixed my problem

yii2 stripe include error (class not found)

Yii2 Framework.
Installed Stripe (https://github.com/stripe/stripe-php) by composer:
composer require stripe/stripe-php
And inserted to the view:
\Stripe\Stripe::setApiKey('sk_test_...');
$myCard = array(
'number' => '4242424242424242',
'exp_month' => 8,
'exp_year' => 2018
);
$charge = \Stripe\Charge::create(array(
'card' => $myCard,
'amount' => 2000,
'currency' => 'usd'
));
echo $charge;
And now framework can't find Class:
Error
Class 'Stripe\Stripe' not found
What should I do next?
Did you correctly include Composer's autoload file?
You should have a require statement similar to this near the beginning of your code:
require_once('vendor/autoload.php');
cf. Stripe's PHP library's README file and Composer's documentation.

Yii2 kartik-datecontrol extension

I installed the above extension via composer and follow the documentation for every step; in my :
view : use kartik\datecontrol\DateControl;// <?=$form->field($model, 'dated')->widget(DateControl::classname(), [
'type'=>DateControl::FORMAT_DATE,
'ajaxConversion'=>false,
'options' => ['pluginOptions' => ['autoclose' => true ],'class'=>'col-xs-12 form-control input-sm']])?>
Web.php - Module configuration :
use \kartik\datecontrol\Module;
'datecontrol' => [
'class' => 'kartik\datecontrol\Module',
// format settings for displaying each date attribute (ICU format example)
'displaySettings' => [
Module::FORMAT_DATE => 'php:dd-m-Y',
Module::FORMAT_TIME => 'php:H:i:s',
Module::FORMAT_DATETIME => 'php:Y-m-d H:i:s',
],
// format settings for saving each date attribute (PHP format example)
'saveSettings' => [
Module::FORMAT_DATE => 'php:Y-m-d',
Module::FORMAT_TIME => 'php:H:i:s',
Module::FORMAT_DATETIME => 'php:Y-m-d H:i:s',
],
// set your display timezone
// 'displayTimezone' => 'Asia/Kolkata',
// set your timezone for date saved to db
// 'saveTimezone' => 'UTC',
// automatically use kartik\widgets for each of the above formats
'autoWidget' => true,
// default settings for each widget from kartik\widgets used when autoWidget is true
'autoWidgetSettings' => [
Module::FORMAT_DATE => ['type'=>2, 'pluginOptions'=>['autoclose'=>true]], // example
Module::FORMAT_DATETIME => [], // setup if needed
Module::FORMAT_TIME => [], // setup if needed
],
// custom widget settings that will be used to render the date input instead of kartik\widgets,
// this will be used when autoWidget is set to false at module or widget level.
'widgetSettings' => [
Module::FORMAT_DATE => [
'class' => 'yii\jui\DatePicker', // example
'options' => [
'dateFormat' => 'php:d-M-Y',
'options' => ['class'=>'form-control'],
]
]
]
// other settings
]
When I run the view I got the following error message :
{"name":"Invalid Configuration","message":"The class
'\kartik\date\DatePicker' was not found and is required for
DateControl 'date' format.\n\nPlease ensure you have installed one of
'yii2-widgets' OR 'yii2-widget-datepicker' extensions. To install, you
can run this console command from your application root:\n\nphp
composer.phar require kartik-v/yii2-widgets: \"#dev\"\n\n--- OR
---\n\nphp composer.phar require kartik-v/yii2-widget-datepicker: \"#dev\"","code":0,"type":"yii\base\InvalidConfigException","file":"C:\wamp\www\pub\vendor\kartik-v\yii2-krajee-base\Config.php","line":118,"stack-trace":["#0
C:\wamp\www\pub\vendor\kartik-v\yii2-krajee-base\Config.php(195):
kartik\base\Config::checkDependency('\\kartik\\date\\Da...',
Array, 'for DateControl...')","#1
C:\wamp\www\pub\vendor\kartik-v\yii2-datecontrol\DateControl.php(215):
kartik\base\Config::validateInputWidget('\\kartik\\date\\Da...',
'for DateControl...')","#2
C:\wamp\www\pub\vendor\kartik-v\yii2-datecontrol\DateControl.php(154):
kartik\datecontrol\DateControl->initConfig()","#3
C:\wamp\www\pub\vendor\yiisoft\yii2\base\Object.php(107):
kartik\datecontrol\DateControl->init()","#4 [internal function]:
yii\base\Object->__construct(Array)","#5
C:\wamp\www\pub\vendor\yiisoft\yii2\di\Container.php(372):
ReflectionClass->newInstanceArgs(Array)","#6
C:\wamp\www\pub\vendor\yiisoft\yii2\di\Container.php(151):
yii\di\Container->build('kartik\\datecont...', Array, Array)","#7
C:\wamp\www\pub\vendor\yiisoft\yii2\BaseYii.php(344):
yii\di\Container->get('kartik\\datecont...', Array, Array)","#8
C:\wamp\www\pub\vendor\yiisoft\yii2\base\Widget.php(97):
yii\BaseYii::createObject(Array)","#9
C:\wamp\www\pub\vendor\yiisoft\yii2\widgets\ActiveField.php(665):
yii\base\Widget::widget(Array)","#10
C:\wamp\www\pub\views\activite\schedules.php(49):
yii\widgets\ActiveField->widget('kartik\\datecont...',
Array)","#11
C:\wamp\www\pub\vendor\yiisoft\yii2\base\View.php(325):
require('C:\\wamp\\www\\pub...')","#12
C:\wamp\www\pub\vendor\yiisoft\yii2\base\View.php(247):
yii\base\View->renderPhpFile('C:\\wamp\\www\\pub...',
Array)","#13
C:\wamp\www\pub\vendor\yiisoft\yii2\base\View.php(149):
yii\base\View->renderFile('C:\\wamp\\www\\pub...', Array,
Object(app\controllers\ActiviteController))","#14
C:\wamp\www\pub\vendor\yiisoft\yii2\base\Controller.php(371):
yii\base\View->render('schedules', Array,
Object(app\controllers\ActiviteController))","#15
C:\wamp\www\pub\controllers\ActiviteController.php(407):
yii\base\Controller->render('schedules', Array)","#16 [internal
function]:
app\controllers\ActiviteController->actionAddsch('4')","#17
C:\wamp\www\pub\vendor\yiisoft\yii2\base\InlineAction.php(55):
call_user_func_array(Array, Array)","#18
C:\wamp\www\pub\vendor\yiisoft\yii2\base\Controller.php(151):
yii\base\InlineAction->runWithParams(Array)","#19
C:\wamp\www\pub\vendor\yiisoft\yii2\base\Module.php(455):
yii\base\Controller->runAction('addsch', Array)","#20
C:\wamp\www\pub\vendor\yiisoft\yii2\web\Application.php(84):
yii\base\Module->runAction('activite/addsch', Array)","#21
C:\wamp\www\pub\vendor\yiisoft\yii2\base\Application.php(375):
yii\web\Application->handleRequest(Object(yii\web\Request))","#22
C:\wamp\www\pub\web\index.php(12):
yii\base\Application->run()","#23 {main}"]}
Try installing the following widgets:
yii2-widget-datepicker
yii2-widget-datetimepicker
or better, install the kartik widgets using composer:
php composer.phar require kartik-v/yii2-widgets "*"
that will install the following widgets:
yii2-krajee-base
yii2-widget-activeform
yii2-widget-affix
yii2-widget-alert
yii2-widget-colorinput
yii2-widget-datepicker
yii2-widget-datetimepicker
yii2-widget-depdrop
yii2-widget-fileinput
yii2-widget-growl
yii2-widget-rangeinput
yii2-widget-rating
yii2-widget-select2
yii2-widget-sidenav
yii2-widget-spinner
yii2-widget-switchinput
yii2-widget-timepicker
yii2-widget-touchspin
yii2-widget-typeahead

Custom paths in Zend Framework 2 configuration

Hello Stack Overflow Community
I am having some problems with my custom paths in my zend framework 2 module.
I've added following code to my module.config.php :
// custom configuration
'custom' => array(
'paths' => array(
'pickUpDir' => '/var/www/beam/public/in/',
'errorDir' => '/var/www/beam/public/error/',
'temporaryDir' => '/var/www/beam/module/Beam/temp/',
'archiveDir' => '/var/www/beam/module/Beam/archive/'
)
),
Now this works fine on my virtual developement server but i want it to work universaly, meaning if i put my Zend Framework application on a live server which has a different folder structure it should still work.
Is there a way to declare relative paths or something like that ?
Many thankx in advance
The magic constant __DIR__ will return the current directory which should be /..../Yourmodel/config/.
From there on you could just do:
'custom' => array(
'paths' => array(
'pickUpDir' => __DIR__ . '/../../public/in/',
'errorDir' => __DIR__ . '/../../public/error/',
//etc
)
),
Alternatively to cptnk's answer (which is also working), you can also use the get_cwd() function that will return you the root of your webapp, so that you can write stg like
'custom' => array(
'paths' => array(
'pickUpDir' => get_cwd() . '/public/in/',
'errorDir' => get_cwd() . '/public/error/',
//etc
)
)
as ZF2 defines the current working directory as root of your project.