This is my view page that i want to download as pdf. My view link: http://localhost/myproject/Applicant/1
I want to put a download PDF button at the right top of that page, When i click on it, The user profile should be downloaded in PDF. Im new to yii so not sure how to do it, But by searching on google, i found some extensions.
yii-pdf
mpdf1
by following these above extensions, I put those extensions in my protected/extension folder. Then Here is my main/config file..
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'class' => 'WebUser',
'allowAutoLogin'=>true,
'returnUrl'=>'/site/index#login',
'loginUrl'=>array('/Applicant/login'),
),
'ePdf' => array(
'class' => 'ext.yii-pdf.EYiiPdf',
'params' => array(
'mpdf' => array(
'librarySourcePath' => 'application.extensions.mpdf.*',
'constants' => array(
'_MPDF_TEMP_PATH' => Yii::getPathOfAlias('application.runtime'),
),
'class'=>'mpdf', // the literal class filename to be loaded from the vendors folder
/*'defaultParams' => array( // More info: http://mpdf1.com/manual/index.php?tid=184
'mode' => '', // This parameter specifies the mode of the new document.
'format' => 'A4', // format A4, A5, ...
'default_font_size' => 0, // Sets the default document font size in points (pt)
'default_font' => '', // Sets the default font-family for the new document.
'mgl' => 15, // margin_left. Sets the page margins for the new document.
'mgr' => 15, // margin_right
'mgt' => 16, // margin_top
'mgb' => 16, // margin_bottom
'mgh' => 9, // margin_header
'mgf' => 9, // margin_footer
'orientation' => 'P', // landscape or portrait orientation
)*/
),
),
),
I have created this action in ApplicantController
public function actionPDF()
{
$mPDF1 = Yii::app()->ePdf->mpdf();
$mPDF1->WriteHTML($this->render('UserProfileView',true));
$mPDF1->Output();
}
What should i do next? how to get the button on that view file which is link to controller action to download file.
You need to submit your form to an action.
for example, in your view:
<?php echo CHtml::button('Button Text', array('submit' => array('controller/action'))); ?>
In here the button will call the action in controller and execute what need to be done in that action.
EDITED
If I'm right, you are rendering protected/views/applicant/view.php so you can add in the sidebar the link to you action:
<?php
/* #var $this ApplicantController */
/* #var $model Applicant*/
$this->breadcrumbs=array(
'Applicant'=>array('index'),
$model->id,
);
$this->menu=array(
array('label'=>'List Applicant', 'url'=>array('index')),
array('label'=>'Create Applicant', 'url'=>array('create')),
array('label'=>'Create PDF', 'url'=>array('PDF')),
Don't forget adding to rules in your ApplicantController.php:
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view','PDF'),
'users'=>array('*'),
Related
I'm trying to add a new field to Admin Preferences - a textarea field with tinymce. I've added code to AdminPreferencesController.php:
$this->fields_options['contact'] = array(
'title' => $this->l('Contact'),
'icon' => 'icon-cogs',
'submit' => array('title' => $this->l('Save')),
);
$this->fields_options['contact']['fields']['PS_CONTACT_ADDITIONAL_INFO'] = array(
'type' => 'textarea',
'label' => $this->l('Short description'),
'name' => 'short_description',
'lang' => true,
'cols' => 60,
'rows' => 10,
'autoload_rte' => 'rte',
'col' => 6,
);
But tinymce doesnt' appear and when I'm using HTML tags after saving they disappear. Presta strips all HTML tags.
How to allow HTML tags on this field and enable tinymce?
It seems that you can't just add it in a regular way. But you can implement it in a next way.
First of all, use field type textareaLang instead of textarea and add a parameter 'validation' => 'isCleanHtml' to this field
$this->fields_options['contact']['fields']['PS_CONTACT_ADDITIONAL_INFO'] = array(
'type' => 'textareaLang',
'label' => $this->l('Short description'),
'name' => 'short_description',
'lang' => true,
'cols' => 60,
'rows' => 10,
'col' => 6,
'validation' => 'isCleanHtml'
);
Create your own script to initialize your editor. I created a script tinymce.init.js and put it to js/admin/ folder
$(document).ready(function(){
ad = ''; // this is defenition of the external plugin path. I didn't fint how it can impact on script if it's empty but by default it it the path to your admin folder
iso = iso_user;
var config = {
selector: '.textarea-autosize'
};
tinySetup(config);
});
Then include tinymce script and your own to this controller AdminPreferencesController.php
public function setMedia()
{
$this->context->controller->addJquery();
$this->context->controller->addJS(
array(
_PS_JS_DIR_.'admin/tinymce.init.js',
_PS_JS_DIR_.'tiny_mce/tiny_mce.js',
_PS_JS_DIR_.'admin/tinymce.inc.js'
)
);
parent::setMedia();
}
It should implement your requirements. But don't forget that now you should call your configuration field in multilingual scope. So, add a language id to Configuration::get() like
Configuration::get('PS_CONTACT_ADDITIONAL_INFO, $id_lang)
whenever you use it.
P.S. Bear in mind that the best solution for your goal is to create a simple module which will handle this. And far more, it is recommended way.
Hello I'm new to yii so currently don't know how to properly use this Html2pdf & yii-pdf extension in yii to get the pdf..
What i actually want.. I have a page called http://localhost/site/Users/Results.. which is showing the list of users..So If i click on user one, it will open a new page called http://localhost/site/Applicant/1
& for user two, it will be
http://localhost/site/Applicant/2
So on these pages there is all the information of users. I want to put a download PDF button on this page, If user clicks on it, He will be able to download all his information in PDF. There can be many users. Everyuser will be able to download all his information in pdf.
I got the html2pdf & yii-PDF .. I got this settings by searching on google, but unable to find proper example to use it according to my requirements above.
config/main.php
'ePdf' => array(
'class' => 'ext.yii-pdf.EYiiPdf',
'params' => array(
'HTML2PDF' => array(
'librarySourcePath' => 'application.extensions.html2pdf.*',
'classFile' => 'html2pdf.class.php', // For adding to Yii::$classMap
/*'defaultParams' => array( // More info: http://wiki.spipu.net/doku.php?id=html2pdf:en:v4:accueil
'orientation' => 'P', // landscape or portrait orientation
'format' => 'A4', // format A4, A5, ...
'language' => 'en', // language: fr, en, it ...
'unicode' => true, // TRUE means clustering the input text IS unicode (default = true)
'encoding' => 'UTF-8', // charset encoding; Default is UTF-8
'marges' => array(5, 5, 5, 8), // margins by default, in order (left, top, right, bottom)
)*/
)
),
),
Here is my controller.
class UsersController extends Controller
{
public function createPDF(){
$html2pdf = Yii::app()->ePdf->HTML2PDF();
$html2pdf->WriteHTML($this->renderPartial('index', array(), true));
$html2pdf->Output();
}
}
im totally new to yii, so how to use this extension, I have never used any extension before.. is there any other method to download pdf of each user information. any suggestions or and example of working code.
config/main.php
'ePdf' => array(
'class' => 'ext.yii-pdf.EYiiPdf',
'params' => array(
'HTML2PDF' => array(
'librarySourcePath' => 'application.vendors.html2pdf.*',
'classFile' => 'html2pdf.class.php', // For adding to Yii::$classMap
)
),
),
Controller
class UsersController extends Controller
{
public function createPDF(){
$pdffilename = 'test.pdf';
$html2pdf = Yii::app()->ePdf->HTML2PDF();
$html2pdf->WriteHTML($this->renderPartial('index', array(), true));
ob_clean();
$html2pdf->Output($pdffilename,"I"); // OUTPUT_TO_BROWSER
/* OUTPUT_TO_BROWSER = "I" */
/* OUTPUT_TO_DOWNLOAD = "D" */
/* OUTPUT_TO_FILE = "F" */
/* OUTPUT_TO_STRING = "S" */
}
}
I am using bootstrap extension in my yii project. The project has so many grid-view with summary text Their summery text is {model name} {start} - {end} of {count} . I used grid-view to overwrite summery text:
$this->widget('bootstrap.widgets.TbExtendedGridView', array(
'id' => 'grid1',
'fixedHeader' => true,
'type' => 'listtable',
'template' => "{items}{pager}{summary}",
'summaryText' => 'my text',
'dataProvider' => $model->search(),
'htmlOptions' => array(),
'columns' => array(
// ..
)
));
And now I don't want to write each grid 'summaryText' => 'Shown'.' {end} '.'out of'.' {count}',. I decided to show the same text all grid-views. I don't know how to do it. May I do it inside TbGridView or Where I must set summaryText.
Here is summaryText doc
Just add the code inside TbExtendedGridView class init function
/**
* Widget initialization
*/
public function init()
{
$this->summaryText="Your sumary text";
.....
}
I try to use fileimagearbehavior extension for Yii, and its not a lot documentation for that. In examples I just found how can 1 file be uploaded, but I cant find way how to upload more than 1 file. Here example
class Dish extends CActiveRecord {
public $recipeImg; // used by the form to send the file.
public function rules()
{
return array(
// ...
// for the form too
array('recipeImg', 'file', 'types' => 'png, gif, jpg', 'allowEmpty' => true),
// ...
);
}
public function behaviors() {
return array(
'recipeImgBehavior' => array(
'class' => 'ImageARBehavior',
'attribute' => 'recipeImg', // this must exist
'extension' => 'png, gif, jpg', // possible extensions, comma separated
'prefix' => 'img_',
'relativeWebRootFolder' => 'files/recipes', // this folder must exist
# 'forceExt' => png, // this is the default, every saved image will be a png one.
# Set to null if you want to keep the original format
'useImageMagick' => '/usr/bin', # I want to use imagemagick instead of GD, and
# it is located in /usr/bin on my computer.
// this will define formats for the image.
// The format 'normal' always exist. This is the default format, by default no
// suffix or no processing is enabled.
'formats' => array(
// create a thumbnail grayscale format
'thumb' => array(
'suffix' => '_thumb',
'process' => array('resize' => array(60, 60), 'grayscale' => true),
),
// create a large one (in fact, no resize is applied)
'large' => array(
'suffix' => '_large',
),
// and override the default :
'normal' => array(
'process' => array('resize' => array(200, 200)),
),
),
'defaultName' => 'default', // when no file is associated, this one is used by getFileUrl
// defaultName need to exist in the relativeWebRootFolder path, and prefixed by prefix,
// and with one of the possible extensions. if multiple formats are used, a default file must exist
// for each format. Name is constructed like this :
// {prefix}{name of the default file}{suffix}{one of the extension}
)
);
}
}
And here piece of view:
echo $form->fileField($model,'recipe');
I am creating my own module and one of its requirement is to have it located in a certain menu. My problem is that the menu is generated using a plugin PyroStreams.
So first things first, I downloaded a copy of the sample module on the Github, then have it place in addons/default/modules/. I refreshed my PyroCMS Admin -> Add-ons -> Modules and see the sample module in there. As stated on the detail.php of this sample module
public function info()
{
return array(
'name' => array(
'en' => 'Test Modules'
),
'description' => array(
'en' => 'My custom module.'
),
'frontend' => FALSE,
'backend' => TRUE,
'menu' => 'content', // You can also place modules in their top level menu. For example try: 'menu' => 'Sample',
'sections' => array(
'items' => array(
'name' => 'Test', // These are translated from your language file
'uri' => 'admin/sample',
'shortcuts' => array(
'create' => array(
'name' => 'sample:create',
'uri' => 'admin/sample/create',
'class' => 'add'
)
)
)
)
);
}
It should appear on the Content menu which is correct. Now, I can't find anything on docs that states instructions on properly mapping the menu for custom modules, so out of initiative I tried to change the value for menu => "content" to menu => "Test Stream" but that didn't work. As shown in the screenshot below, that is where I wanted to place my custom module, under the menu "Test Stream". What am I missing?
Add this method to your detail.php file:
public function admin_menu(&$menu)
{
// Create main menu item
add_admin_menu_place('lang:module:title', 9); // 9 is the placement order of your menu item, it would be after profile
// Create sub-menu
$menu['lang:module:title']['lang:module:submeu1'] = 'admin/add';
$menu['lang:module:title']['lang:module:submeu2'] = 'admin/edit';
}
also set the 'menu'=> false, at your info() method.