如何在joomla 2.5自定义组件中添加电子邮件/打印


how to add email/print in joomla 2.5 custom component

请告诉我如何在我的组件(joomla 2.5)中添加电子邮件/打印图标。

我能够完成它部分,但我不能打印加上这不是一个标准的方式,我猜。打印图标和电子邮件图标丢失。

<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>      

这就是我所做的:

<?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>

在最近的一个项目中,我使用下面的Joomla Docs教程成功地添加了打印功能。

你必须像这样构造你的URL:

<?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>

相同的代码将在视图和生成的模态窗口中呈现链接,使用相同的Click for Printing,除了当用户单击模态窗口中的按钮时,它将打开浏览器的打印窗口。

你当然需要调整代码与相关的组件和查看信息为您的项目。

http://docs.joomla.org/Adding_print_pop-up_functionality_to_a_component

* EDIT *

确保在视图文件的顶部添加以下行:

JHtml::_('behavior.modal');

* EDIT 2 *

我回顾了示例代码和我的一个工作项目,并注意到一个明显的缺陷。我没有为view定义URL参数。我调整了上面的代码片段(在else中,第三个$href变量)来反映变化。