[TYPO3-mvc] frontend plugin and pdf_generator2

Franz Koch typo3.RemoveForMessage at elements-net.de
Thu Dec 30 12:34:38 CET 2010


Hey,

> The PDF should be generated out of the detailed view. Once a user searched
> for a booking and sees its details, I want to provide the possibility to
> click on the PDF generator link (in my case an image) and see the detailed
> view (in other words: the current page) as PDF.
>
> I changed the method of the search form to get.
> <f:form controller="Booking" action="show" method="get">
> Bookingnumber:<f:form.textbox name="bookingnumber" />
> Billnumber:<f:form.textbox name="billnumber" />
> Containernumber:<f:form.textbox name="containernumber" />
> <f:form.submit value="Search" />
> </f:form>
>
> Now I get this url:
> http://127.0.0.1/bn_quicksite_2.1/customer-service/freight-tracking/?tx_rafreighttracking_publicsearch[__referrer][extensionName]=RaFreighttracking&tx_rafreighttracking_publicsearch[__referrer][controllerName]=Booking&tx_rafreighttracking_publicsearch[__referrer][actionName]=index&tx_rafreighttracking_publicsearch[__hmac]=a%3A5%3A{s%3A13%3A%22bookingnumber%22%3Bi%3A1%3Bs%3A10%3A%22billnumber%22%3Bi%3A1%3Bs%3A15%3A%22containernumber%22%3Bi%3A1%3Bs%3A6%3A%22action%22%3Bi%3A1%3Bs%3A10%3A%22controller%22%3Bi%3A1%3B}d471aabc4734fb6330b8cd7b9a45eb00a792ed4e&tx_rafreighttracking_publicsearch[bookingnumber]=SA001&tx_rafreighttracking_publicsearch[billnumber]=&tx_rafreighttracking_publicsearch[containernumber]=&=Search
>
> The good thing: now the variables I need for the PDF generation are in the
> url.
> But the detailed view is not shown. -  The actionName is "index" in the url
> although I set it to "show" in the form. Why is that?
> I didn´t change anything but the method in the form. If I change it back to
> post, the detailed view is shown.
>
> Is this the way you suggested?

yepp, it is. I forgot about the overhead that doesn't look very nice in 
the URL. And to bad that the actionName doesn't work - looks like a bug.

> Is there a way to just add the bookingnumber, billnumber and containernumber
> variables to the PDF generation link?

The only other clean solution that comes to my mind would be to either 
use a viewHelper for this or do a redirect.

a) viewHelper
You could either use a custom viewHelper that's creating the pdf link 
button internally using the API of the pdf extension (if available) or 
render the PDF button using the cObject viewHelper rendering a custom TS 
snippet.

b) redirect
If a booking was found, do a redirect to a dedicated detail view 
page/action, that probably looks the same (so also with the search form 
on top) but has a nice and clean URL. But this has the downside of a 
processing overhead due to the redirect.


public function indexAction(Tx_YourExt_Domain_Model_BookingDemand 
$demand = NULL) {
	if ($demand !== NULL && is_object($demand)) {
		$booking = $this->bookingRepository->findDemanded($demand)->getFirst();
		if (is_object($booking) && $booking->getUid()) {
			$this->redirect('show', NULL, NULL, array('booking' => 
$booking->getUid());
		}
	}
	
	$this->view->assign('demand', $demand);
}

public function showAction(Tx_YourExt_Domain_Model_Booking $booking) {
	$this->view->assign('booking', $booking);
}


As you might have noticed in this example, I use a demand object instead 
of the nested if clauses you mentioned. This might be a more elegant way 
and probably more flexible way to do it, but yours is also fine as long 
as it's working.

-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list