如何在joomla 2.5自定义组件中添加电子邮件/打印
Kindly explain me how to add email/print icon in my component (joomla 2.5).
I am able to accomplish it partially but i cannot print plus this is not a standard way i guess. The print icon and email icon is missing.
<a href="<?php echo JRoute::_('index.php?option=com_mailto&tmpl=component&&template=shape5_vertex&link=ffc8df4efb9cbf37a836ddfeb67f6d0df4155699'); ?>" title="Email" onclick="window.open(this.href,'win2','width=400,height=350,menubar=yes,resizable=yes'); return false;"><img src="/joomla/media/system/images/emailButton.png" alt="Email" /></a>
<a href="<?php echo JRoute::_('index.php?option=com_mycomp&view=comps&tmpl=component&print=1'); ?>" title="Print" onclick="window.open(this.href,'win2','status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no'); return false;" rel="nofollow"><img src="/joomla/media/system/images/printButton.png" alt="Print" /></a>
In a recent project I used the below Joomla Docs tutorial successfully to add print functionality.
You must construct the your URL like so:
<?php
$isModal = JRequest::getVar( 'print' ) == 1; // 'print=1' will only be present in the url of the modal window, not in the presentation of the page
if( $isModal) {
$href = '"#" onclick="window.print(); return false;"';
} else {
$href = 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no';
$href = "window.open(this.href,'win2','".$href."'); return false;";
$href = '"index.php?option=mycomponent&view=myview&tmpl=component&print=1" '.$href;
}
?>
<a href=<?php echo $href; ?> >Click for Printing</a>
The same code will render the link in view and in the resulting modal window with the same Click for Printing, except when the user clicks the button in the modal window it will open the browsers print window.
You of course need to adjust the code with relevant component and view information for your project.
http://docs.joomla.org/Adding_print_pop-up_functionality_to_a_component
* EDIT *
Be sure to add the following line to the top of the view file:
JHtml::_('behavior.modal');
* EDIT 2 *
I reviewed the sample code and one from a working project I had and noticed one glaring ommission. I had failed to define the URL parameter for view. I adjusted the above code snippet (inside else, third $href variable) to reflect change.
This is what i've:
<?php $isModal = JRequest::getVar( 'print' ) == 1; // 'print=1' will only be present in the url of the modal window, not in the presentation of the page
if( $isModal) {
$href = '"#" onclick="window.print(); return false;"';
} else {
$href = 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no';
$href = "window.open(this.href,'win2','".$href."'); return false;";
$href = '"index.php?option=com_mycomp&view=comps&tmpl=component&print=1&layout=default&page="'.@ $request->limitstart.'"'.$href;
}?><a href="<?php echo $href; ?>"><img src="templates/shape5_vertex/images/system/printButton.png" alt="Print" /></a>