How can convert view page into a pdf in Yii - pdf

How can convert view page into a pdf in Yii from controller.
in main.php i added this code
'ePdf' => array(
'class' => 'ext.yii-pdf.EYiiPdf',
'params' => array(
'mpdf' => array(
'librarySourcePath' => 'application.vendors.mpdf.*',
'constants' => array(
'_MPDF_TEMP_PATH' => Yii::getPathOfAlias('application.runtime'),
),
'class'=>'mpdf', // the literal class filename to be loaded from the vendors folder
),
'HTML2PDF' => array(
'librarySourcePath' => 'application.vendors.html2pdf.*',
'classFile' => 'html2pdf.class.php', // For adding to Yii::$classMap
)
),
),
Controller Code is
$mPDF1 = Yii::app()->ePdf->mpdf('', 'A5');
$mPDF1->WriteHTML($this->renderPartial('printformat', array(), true));
$mPDF1->Output();
Error : include(mpdf.php) [function.include]: failed to open stream: No such file or directory

The Error says, you have to include mpdf.php before using it.
You are using YiiPdf Bundle with html2pdf and mpdf.
First download Yii Pdf from here and include in extension as protected/extensions/yii-pdf (ext.yii-pdf as in 'class' => 'ext.yii-pdf.EYiiPdf',). This means your extension folder contains yii-pdf as directory.
Then, download mpdf from here. and place it in vendors as protected/vendors/mpdf as in
'librarySourcePath' => 'application.vendors.mpdf.*',
All explanation is here.

Related

drupal generate fpdf files

I create website based on drupal 7 with module to generate pdf - i use fpdf library.
I dont know how I can make form to send some data to node where i have php code for generate pdf.
Also i still get error message:
FPDF error: Some data has already been output, can't send PDF file (output started at Z:\xampp\htdocs\domain\includes\common.inc:2748)
where i found:
ob_flush();
when i try change it to
ob_clean()
all nodes generate pdf :/
You can try use other module which is a simple - pdf_using_mpdf
With this module you can get PDF of some node calling www.YOUR_SITE.DOMAIN/node/NID_ID/pdf - where NID_ID is the id of node what you want to render as PDF.
Or also you can use hook_menu() if you need render as PDF only some fields of your node - add your item like
$items['%node/create_pdf'] = array(
'title' => '',
'description' => '',
'page callback' => 'custom_callback_create_pdf',
'page arguments' => array(1),
'access callback' => 'node_access',
'type' => MENU_CALLBACK,
);
Define you callback like
function custom_callback_create_pdf($node) {
// Check if current node has needed field.
if (isset($node->field_my_custom_field_of_node)) {
// Render only field 'field_my_custom_field_of_node';
$view = node_view($node);
$output = render($view['field_my_custom_field_of_node']);
return pdf_using_mpdf_api($output, $node->title);
}
else {
return pdf_using_mpdf_api("<html><body>Current page do not required field.</body></html>", $node->title);
}
}
and print button for download:
$pdf_button = l(t('Download as PDF'), 'node/' . $node->nid . '/create_pdf', array(
'attributes' => array(
'target' => '_blank',
'class' => array('render_as_pdf'),
),
));
echo '<p>' . $pdf_button . '</p>';

yii-user extension gives an invalid alias error

i'm new to yii and downloaded this extension
https://github.com/mishamx/yii-user
i've uploaded all the necessary files into the protected/ folder
but i keep getting this error. what am i missing?
Alias "user.UserModule" is invalid. Make sure it points to an existing PHP file and the file is readable.
/Applications/XAMPP/xamppfiles/htdocs/dev2/framework/YiiBase.php(322)
i edited my config/main/php which now looks like this
<?php
// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');
// Define a path alias for the Bootstrap extension as it's used internally.
// In this example we assume that you unzipped the extension under protected/extensions.
Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../extensions/bootstrap');
// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'my site',
'theme'=>'bootstrap', // requires you to copy the theme under your themes directory
// preloading 'log' component
'preload'=>array('log'),
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
'application.modules.user.models.*',
'application.modules.user.components.*',
),
'modules'=>array(
// uncomment the following to enable the Gii tool
'gii'=>array(
'class' => 'system.gii.GiiModule',
'password' => 'gii', //Enter Your Password Here
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters' => array('127.0.0.1','::1'),
'generatorPaths' => array('bootstrap.gii'),
),
'user'=>array(
# encrypting method (php hash function)
'hash' => 'md5',
# send activation email
'sendActivationMail' => true,
# allow access for non-activated users
'loginNotActiv' => false,
# activate user on registration (only sendActivationMail = false)
'activeAfterRegister' => false,
# automatically login from registration
'autoLogin' => true,
# registration path
'registrationUrl' => array('/user/registration'),
# recovery password path
'recoveryUrl' => array('/user/recovery'),
# login form path
'loginUrl' => array('/user/login'),
# page after login
'returnUrl' => array('/user/profile'),
# page after logout
'returnLogoutUrl' => array('/user/login'),
),
),
// application components
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
'class' => 'WebUser',
),
'bootstrap' => array(
'class' => 'bootstrap.components.Bootstrap',
),
// uncomment the following to enable URLs in path-format
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
/*'db'=>array(
'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
),*/
// uncomment the following to use a MySQL database
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=DBNAME',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'tablePrefix' => 'tbl_',
),
'errorHandler'=>array(
// use 'site/error' action to display errors
'errorAction'=>'site/error',
),
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
),
// uncomment the following to show log messages on web pages
/*
array(
'class'=>'CWebLogRoute',
),
*/
),
),
),
// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
'params'=>array(
// this is used in contact page
'adminEmail'=>'admin#******.com',
),
);
?>
and this is my config/console.php file
<?php
// This is the configuration for yiic console application.
// Any writable CConsoleApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'My Console Application',
// preloading 'log' component
'preload'=>array('log'),
// application components
'components'=>array(
// uncomment the following to use a MySQL database
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=*****',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'tablePrefix' => 'tbl_',
),
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
),
),
),
),
'modules'=>array(
'user'=>array(
# encrypting method (php hash function)
'hash' => 'md5',
# send activation email
'sendActivationMail' => true,
# allow access for non-activated users
'loginNotActiv' => false,
# activate user on registration (only sendActivationMail = false)
'activeAfterRegister' => false,
# automatically login from registration
'autoLogin' => true,
# registration path
'registrationUrl' => array('/user/registration'),
# recovery password path
'recoveryUrl' => array('/user/recovery'),
# login form path
'loginUrl' => array('/user/login'),
# page after login
'returnUrl' => array('/user/profile'),
# page after logout
'returnLogoutUrl' => array('/user/login'),
),
)
);
if you are working with a linux enviroment, it's possible that your files do not have enough previlage to run files under users module directory.
try this to know if the problem is from here
chmod -R 777 /protected/modules/user/
not sure which version of yii-user you are using, but first download the latest version from here and follow the setting changes from that page too.
make sure you unzip all the files into protected/modules/user (NOTE: the modules and user folder doesn't exist so you will have to make one)
once done, insert items into zii.widgets.CMenu array (protected/views/layouts/main.php)
array('url'=>Yii::app()->getModule('user')->loginUrl, 'label'=>Yii::app()->getModule('user')->t("Login"), 'visible'=>Yii::app()->user->isGuest),
array('url'=>Yii::app()->getModule('user')->registrationUrl, 'label'=>Yii::app()->getModule('user')->t("Register"), 'visible'=>Yii::app()->user->isGuest),
array('url'=>Yii::app()->getModule('user')->profileUrl, 'label'=>Yii::app()->getModule('user')->t("Profile"), 'visible'=>!Yii::app()->user->isGuest),
array('url'=>Yii::app()->getModule('user')->logoutUrl, 'label'=>Yii::app()->getModule('user')->t("Logout").' ('.Yii::app()->user->name.')', 'visible'=>!Yii::app()->user->isGuest),
I don't know why, but I had also same issue after I loaded last version of yiibooster 4.0.1 version my issue solved by changing all "bootstrap" aliases with "booster" in all part of my application.
As example
'bootstrap' => array(
'class' => 'ext.yiibooster.components.Bootstrap',
),
with
'booster' => [
'class' => 'ext.yiibooster.components.Booster',
],
Also don't forget to use filter methods in all actions:
public function filters(){
return [
'accessControl',
'postOnly + delete',
['booster.filters.BoosterFilter - delete'],
];
}

YII - define extracted bootstrap in config file

i'm new in Yii. and i'm using this LINK.
i'm extracted bootstrap on /blog/protected/extensions directory and define array into config/main.php like this:
//BOOT STRAP
'clientScript' => array(
'scriptMap' => array(
'jquery.js'=>false,
'jquery.min.js'=>false,
'core.css'=>false,
'styles.css'=>false,
'pager.css'=>false,
'default.css'=>false,
),
'packages'=>array(
'jquery'=>array(
'baseUrl'=>'bootstrap/',
'js'=>array('js/jquery.js'=>true /* SET AS DEFAULT*/ ),
),
'bootstrap'=>array(
'baseUrl'=>'bootstrap/',
'js'=>array('js/bootstrap.min.js',
'js/bootstrap-transition.js',
'js/bootstrap-alert.js',
'js/bootstrap-modal.js',
'js/bootstrap-dropdown.js',
'js/bootstrap-tab.js',
'js/bootstrap-tooltip.js',
'js/bootstrap-popover.js',
'js/bootstrap-button.js',
'js/bootstrap-collapse.js',
'js/bootstrap-carousel.js',
'js/bootstrap-typeahead.js',
'js/bootstrap-affix.js',
'js/holder.js',
'js/prettify.js',
'js/application.js',
),
'css'=>array(
'css/bootstrap.min.css',
'css/custom.css',
'css/bootstrap-responsive.min.css',
),
'depends'=>array('jquery'),
),
),
),
//BOOT STRAP
how to change 'baseUrl'=>'bootstrap/' to correct path of extension? this path does not work:
'baseUrl'=>'/protected/extensions/bootstrap/',
If you are new, learn about extensions.
Than download ready yii extension for bootstrap: Yii-Bootstrap or Yii-Booster.
You don't have to define any js package, bootstrap extension will do it for you.
Here is sample config part for yii-booster, which i use (actually for yii-bootstrap it should be same):
'components' => array(
// ... other components
'bootstrap' => array(
'class' => 'ext.bootstrap.components.Bootstrap',
'coreCss' => true,
'responsiveCss' => true,
'yiiCss' => true,
),
),
// .. other components
And thats it! Bootstrap will work.

ZendDeveloperTools module not displaying a toolbar in ZF2 beta5

I'm trying to install the ZendDeveloperTools modules for ZF2 beta5. Here are the steps I followed so far:
-Successfully installed ZendSkeletonApplication.
-Downloaded the module into my ./vendor directory.
-Enabled the module in ./config/application.config.php:
<?php
return array(
'modules' => array(
'Application',
'ZendDeveloperTools', // Added this line
),
'module_listener_options' => array(
'config_glob_paths' => array(
'config/autoload/{,*.}{global,local}.php',
),
'module_paths' => array(
'./module',
'./vendor',
),
),
);
-Copied ./vendor/ZendDeveloperTools/config/zenddevelopertools.local.php.dist to ./config/autoload/zenddevelopertools.local.php.
-Edited zenddevelopertools.local.php as follows:
<?php
return array(
'zdt' => array(
'profiler' => array(
'enabled' => true,
'strict' => true,
'verbose' => true,
'flush_early' => false,
'cache_dir' => 'data/cache',
'collectors' => array(),
'verbose_listeners' => array('application' => array(
'ZDT_TimeCollectorListener' => true,
'ZDT_MemoryCollectorListener' => true,
))
),
'toolbar' => array(
'enabled' => true,
'auto_hide' => false,
'position' => 'bottom',
'version_check' => false,
'entries' => array(),
),
),
);
-Added define('REQUEST_MICROTIME', microtime(true)); in my ./public/index.php
-Replaced my ./composer.json with the one provided in the ZendDeveloperTools module.
-Removed the , at the end of line 29 which was causing problems (shouldn't be there):
-Ran a composer update :
$ php composer.phar update
Updating dependencies
- Updating zendframework/zendframework (dev-master)
Checking out 9f4dd7f13c8e34362340072d0e2d13efe15e4b1f
Writing lock file
Generating autoload files
-Added error_reporting(E_ALL); ini_set('display_errors', '1'); to ./public/index.php to catch potential errors
When I access my application I don't get any errors (I get the skeleton application home page) but the zend developer toolbar isn't show up
What am I missing to make use of and display the zend developer toolbar?
It was a stupid mistake, I had placed zenddevelopertools.local.php into ./config and not ./config/autoload. Above instructions are correct. Here is what the toolbar looks like for those who are curious:
Worked for me, but one change I had to make for my app was rename the config from:
zenddevelopertools.local.php
to:
zenddevelopertools.local.config.php
Also, I installed BjyProfiler, which "just worked" with my Doctrine2 setup (nice!). The only caveat was that I had to add the default SM factory config so it would stop throwing errors:
'service_manager' => array(
'factories' => array(
/**
* This default Db factory is required so that ZDT
* doesn't throw exceptions, even though we don't use it
*/
'Zend\Db\Adapter\Adapter' => function ($sm) use ($dbParams) {
$adapter = new BjyProfiler\Db\Adapter\ProfilingAdapter(array(
'driver' => 'pdo',
'dsn' => 'mysql:dbname=skunk;host=hunk',
'database' => 'bunk',
'username' => 'junk',
'password' => 'punk',
'hostname' => 'lunk',
));
$adapter->setProfiler(new BjyProfiler\Db\Profiler\Profiler);
$adapter->injectProfilingStatementPrototype();
return $adapter;
},
),
),
See the screenshot:

How can i do multiple file upload using Drupal 7 Form API?

I'd like to upload multiple files using Form API.
'#type' => 'file' provides upload only one file.
$form['picture_upload'] = array(
'#type' => 'file',
'#title' => t(''),
'#size' => 50,
'#description' => t(''),
'#weight' => 5,
);
How can i provide multiple upload?
Aside from putting the form element in a for loop, I would suggest (for now) using the plupload form element.
http://drupal.org/project/plupload
Then:
$form['picture_upload'] = array(
'#type' => 'plupload',
'#title' => t(''),
'#size' => 50,
'#description' => t(''),
'#weight' => 5,
);
This is similar to a issue I had: Drupal 7 retain file upload
You can use managed_file element type instead of file
here's the drupal documentation: http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/7#managed_file