I am generating a file with data represented in a html table. The problem occurs when there is so much data that wkhtmltopdf would need to generate page number 42. It never finishes loading. If there is lets say 5000 elements and that covers exactly 41 pages it'll generate quickly, but if I add another element it wont finish.
I am using a php wrapper. There is not a lot of code...
This is the function that builds the html
private function _generate() {
$_html .= '<table>';
$_html .= '<tr>';
$_html .= '<th>Naziv medija</th>';
$_html .= '</tr>';
foreach ($this->_model as $value) {
$_html .= '<tr>';
$_html .= '<td>' . $value->attributes['naziv'] . '</td>';
$_html .= '</tr>';
}
$_html .= '</table>';
return $_html;
}
This function then returns the html to the bottom code
$pdf = new WKPDF();
$pdf->set_html($this->_generate());
$pdf->set_orientation($orientation);
$pdf->set_page_size($pagesize);
$pdf->render();
$pdf->output($type, $this->_filename);
If I generate the html and save it somewhere and then create the pdf through the console there is no problem, it works fine.
Any ideas why i cannot generate more than 41 pages with php?
Related
Hi I have a Api list that is been generated using php here is the code that is been used to generate the list
<html>
<title> API LIST</title>
<body>
<?php
$jsondata = file_get_contents("api_link");
$json = json_decode($jsondata, true);
$output = "<ul>";
foreach($output['A'] as $schools){
$output .= "<li>".$schools['name']."</li>";
}
$output .="</ul>";
echo $output;
?>
the list is populated successfully but how can i add a link to the list so that when a user click on one of the items it opens a particular linked page here are the ways i have tried
$output .= "<li ".$schools['name']."</li>";
$output .= "<li>".$schools['name']. "</li>";
$output .= "<li>".$schools['name']."</li>";
I don't know where or how to add the a href code
Use
$output .= '<li>'.$schools['name'].'</li>';
You just need some changes in your code.You can try for
$output .= '<a href=https://www.google.com'.$schools['name'].'><li>'.$schools['name'].'</li></a>';
As per the comments you can use . to concatenate(join) the string and variable in php.
I have a challenge that is bugging me.
The thing is - I'm creating a plugin that is doing an AJAX call to another file in this plugin. It seems Joomla is preventing me from accessing that file.
I need to POST to a file that returns data from a SOAP call.
I'm calling the file from this line:
$html .= '$.post("search.php", { address: $(\'#address\').val(), zipcode: $(\'#zipcode\').val() },';
I've tried both a relative, absolute and server path as well - Joomla doesn't like it. But I can't remember or find the correct way to do it.
The file is in the same folder as the plugin that outputs above code.
Here's the complete javascript function my plugin outputs:
$html .= '<script type="text/javascript">';
$html .= 'function searchParcels()';
$html .= '{';
$html .= '$.post("search.php", { address: $(\'#address\').val(), zipcode: $(\'#zipcode\').val() },';
$html .= 'function(data) {';
$html .= 'var shops = $.parseJSON(data);';
$html .= '$(\'#shops_output\').html(\'\');';
$html .= 'for(i in shops)';
$html .= '{';
$html .= 'var html = \'<p>\'';
$html .= '+ shops[i][\'CompanyName\'] + \'<br>\'';
$html .= '+ shops[i][\'Streetname\'] + \'<br>\'';
$html .= '+ shops[i][\'ZipCode\'] + \' \' + shops[i][\'CityName\'] + \'<br>\'';
$html .= '+ shops[i][\'Telephone\'] + \'<br>\'';
$html .= '+ \'</p>\';';
$html .= '$(\'#shops_output\').append(html);';
$html .= '}';
$html .= '});';
$html .= '}';
$html .= '</script>';
Any help is greatly appreciated :-)
Thanks.
Please check this post on how to use Joomla's ajax interface (it seems you are not using it). This is much easier and much cleaner (and much more standard) than the method you described. All you need to do is to create the module/plugin (make sure that you have a function name ending with "Ajax") and then issue the right call from anywhere on your Joomla website (make sure you use the URL pattern described on the website).
Not sure I worded the title correctly, I'm unsure of what this is called.
I have a while loop which is populated by an SQL query
while($row = $result->fetch_assoc()){
$Tchannel = $row['chan'];
echo '<img src="https://static-cdn.jtvnw.net/previews-ttv/live_user_'.$Tchannel.'-320x180.jpg" alt="Thumbnail"><br />';
echo '<p>';
}
My problem is that when the page loads it does it in sections. I've seen other websites populate these straight away on page load. How would I replicate something like this?
See Example: http://puu.sh/oTh6v/73446c0c15.jpg
Could this be what you meant to achieve...? And by the way, the opening Paragraph Tag:< p > could contribute to some unexpected &/or sluggish behaviour since it was just opened without being closed anywhere in your code... I commented it out... You may try to see if it helps....
<?php
// CREATE A STRING VARIABLE TO HOLD THE ENTIRE OUTPUT TILL YOU ARE READY TO RENDER IT TO THE STREAM...
$strOutput = "";
while($row = $result->fetch_assoc()){
$Tchannel = $row['chan'];
$strOutput .= '<img src="https://static-cdn.jtvnw.net/previews-ttv/live_user_' . $Tchannel . '-320x180.jpg" alt="Thumbnail"><br />';
// WHY DO YOU NEED THIS OPENING PARAGRAPH TAG? WHERE IS IT CLOSED IN YOUR CODE?
//echo '<p>';
}
// RENDER THE OUTPUT
echo $strOutput;
?
If you need the images wrapped in paragraph tags, you can do it differently:
<?php
// CREATE A STRING VARIABLE TO HOLD THE ENTIRE OUTPUT TILL YOU ARE READY TO RENDER IT TO THE STREAM...
$strOutput = "";
while($row = $result->fetch_assoc()){
$Tchannel = $row['chan'];
$strOutput .= '<p>'; // <== OPEN A PARAGRAPH
$strOutput .= '<img src="https://static-cdn.jtvnw.net/previews-ttv/live_user_' . $Tchannel . '-320x180.jpg" alt="Thumbnail"><br />';
$strOutput .= '</p>'; // <== CLOSE THE PARAGRAPH
// OR ALL IN ONE LINE:
// $strOutput .= '<p><img src="https://static-cdn.jtvnw.net/previews-ttv/live_user_' . $Tchannel . '-320x180.jpg" alt="Thumbnail"><br /></p>';
}
// RENDER THE OUTPUT
echo $strOutput;
?>
My Wordpress plugin creates a few shortcodes that return blocks of HTML.
When I register the shortcodes, I do so like this:
add_shortcode('bb-loans-form', function() {
return Shortcodes::loanApplicationForm();
});
And here is the static method from the Shortcodes class:
public static function loadApplicationForm()
{
$form = new \AdamWathan\Form\FormBuilder;
$html = $form->open()->action('/apply')->class('bb-loan-form');
$html .= '<div class="bb-form-field">';
$html .= '<h2>Loan Application Number</h2>';
$html .= $form->text('loan_app_number')->id('loan-app-number');
$html .= $form->submit('Continue Loan');
$html .= '</div>';
$html .= $form->close();
return $html;
}
This is very cumbersome, and messy. I don't like outputting the HTML like this. I've also used Heredoc, but I had to use string substitution to include important values when the form is rendered.
Is there a better way to store my HTML files? I don't want these files publicly accessible. They would have to live in my plugin directory.
It's not a huge plugin, so I'm not overly concerned, but I'd like to know for future reference if there's a cleaner way to include the needed HTML.
You could just use a single string with concatenations...
$form = new \AdamWathan\Form\FormBuilder;
$html = $form->open()->action('/apply')->class('bb-loan-form') .
'<div class="bb-form-field">
<h2>Loan Application Number</h2>' .
$form->text('loan_app_number')->id('loan-app-number') .
$form->submit('Continue Loan') .
'</div>' .
$form->close();
return $html;
It at least keeps the HTML aligned.
I also don't really see an issue with Heredoc, as long as you assign variables and substitute them in:
$form = new \AdamWathan\Form\FormBuilder;
$form_start = $form->open()->action('/apply')->class('bb-loan-form');
$loan_app = $form->text('loan_app_number')->id('loan-app-number');
$submit = $form->submit('Continue Loan');
$form_end = $form->close();
$html = <<<HTML
{$form_start}
<div class="bb-form-field">
<h2>Loan Application Number</h2>
{$loan_app}
{$submit}
</div>
{$form_end}
HTML;
return $html;
I'm experiencing a 500, Internal Server error on my website. The error logs show the following error: "Premature end of script headers: cgi_wrapper", in my Joomla application.
It only occurs when one particular file is loaded. The rest of the application/website works as it should. There are no other related issues that show up in the error logs - no indication of a timeout or a permissions error.
The file that is causing the error is a template/layout file. Furthermore, I have identified a snippet of code that will cause the error, when this is commented out, the site loads just fine. Here it is:
if( $question->type == '1' || $question->type == '2' || $question->type == '3' )
{
//shuffle items
$shuffled_items = $this->shuffle_assoc($items);
$output = '';
$output .= '<table class="answer-table">';
$output .= '<tr>';
$output .= '<td>';
$output .= '<ul class="answers">';
foreach($shuffled_items as $item)
{
$output .= '<li num=' . $item->num . '>';
$output .= $item->item;
$output .= '</li>';
}
$output .= '</ul>';
$output .= '</td>';
$output .= '</tr>';
$output .= '</table>';
$output .= '<table class="answer-table correct-answer" style="display: none">';
$output .= '<tr>';
$output .= '<td>';
$output .= '<p class="question-instructions">Correct Answer:</p>';
$output .= '<ul class="answers correct-answer">';
foreach($items as $item)
{
$output .= '<li num=' . $item->num . '>';
$output .= $item->item;
$output .= '</li>';
}
$output .= '</ul>';
$output .= '</td>';
$output .= '</table>';
echo $output;
}
It uses a variable, $questions, that is set in the view.html.php file (for those who know Joomla). It is this variable that seems to be triggering the error. If I don't assign the $questions variable, then the template will load just fine.
Also, in the example above, it first tests the question type ($question->type). There are other sections of code that would be triggered, and still produce the error, if $question->type is not 1, 2, or 3. But I left out the other code for brevity, and because it only gets called when the relevant question type exists. When the code above alone gets run, it causes the error.
So, I'm lost here. What baffles me is that only this template file, and the $questions variable causes the error. Everything else works fine. It also runs fine on my local server.
Almost forgot, using Joomla 1.5.22, PHP 5.3.3, Apache 2.2.3, Cent OS 5.8. The server also runs Parallels Plesk Panel 10.
I hope someone can point me to a solution.
Thanks!
Check /var/log/httpd/suexec_log
and permissions on /var/www/cgi-bin/cgi_wrapper/cgi_wrapper
it should be
ls -la /var/www/cgi-bin/cgi_wrapper/cgi_wrapper
-rwxr-xr-x 1 root root 5288 Jul 14 2011 /var/www/cgi-bin/cgi_wrapper/cgi_wrapper