how to detect last page of pdf in html2pdf with PHP? - php

I am working on a website which is being developed in PHP zend framework.
I need to create a pdf and i am using html2pdf for that.
Its working alright but i need to put a condition on footer content.
Like if the page is the last page then i need to show some content.
I am using this code to display page numbers.
<i>page [[page_cu]]/[[page_nb]]</i>
But how can i use it in to the condition ?
I have tried like this but m sure its wrong because its giving me an error.
<?php if([[page_cu]]==[[page_nb]] { ?>
Can anyone help me please ?

<?php
if($page_cu == $page_nb)
{
echo "Hello world";
}
?>
"Hello World" will appear only on the last page.
I've used it myself this way.

Related

How to link to pages within a php file with page.php?secondpage

I'm looking to divide up my page into smaller sections for ease of organising my content. Other websites I've seen have used the system of having the main page url then a question mark and the next page name after it (eg. www.website.com/page.php?secondpage)
For what I want to achieve, see an example here (under collecting, current, etc). For my current page, see here.
Thanks for your help!
you can try like this in your html
a href="page.php?collections">collections
in your php code, you can write
<?php if($_SERVER["QUERY_STRING"] == 'collections'){ ?>
//second page code goes here
<?php } ?>

Inserting HTML into PHP without an echo?

So on my index page - when it loads I wanted PHP to check if the user was logged in. If the user was logged in it would show the contents of the webpage but if not it would show the login page for the user.
This is the PHP for the check.
<?php
if ($_SESSION['loggedin'] == true) {
echo "contents of the page";
}
else{
echo "the sign up form";
}
?>
My problem now is that right now I have to put all my HTML in an echo statement like this -
echo '<form>inputs</form>';
and that turn into a bunch of yellow text that I can't easily edit because it's being recognized as plain text by the editor(Sublime Text 3)
Maybe there is a way to get the HTML from a different file and link it into the echo?
What do ya'll think? What's the best route to take? Thanks!
You can embed normal HTML after closing PHP tags like this
<?php if(check if user is logged in): ?>
<pure html to show content of page/>
<?php else: ?>
<pure html to show signup form />
<?php endif; ?>
I hope this will help you
You just have to break out of the PHP tag. You can even do it inside a conditional:
if (condition) { ?>
True stuff!
<?php } else { ?>
False stuff...
<?php }
Given the path to your index.html, you could do:
<?php include_once("path/to/index.html"); ?>
You should really consider using php MVC frameworks.
Number one, for this would be Laravel, but you can choose from many others
Symphony, PHALCON, Zend, CodeIgniter.
And regards to IDE I would really recommend PHPStorm, but you can also use others like Eclipse, Netbeans, Aptana Studio....

how to input a chunk of html with php

I am currently working on a website that uses a login system I made.
I have a div that holds a bar that goes on the top of the website. This bar is supposed to change depending if you're a guest, logged in, or a admin. (Therefor there are three separate divs - guestmode, membermode and adminmode)
I have tried to make php print the html when wanted, and it worked. The only problem is that it's messy and not at all easy to edit.
Is it possible for php to print html without using 'echo' or 'print', but copying from another file?
Basically I want to copy normal html syntaxed-code from a file somewhere and turn it into something that php can print, then of course print it.
Is there something out there that can do that?
Thanks in advance!
For PHP, use something like:
echo file_get_contents('path/to/my_html_snippet.my_ext'); // echo instantly
$stored = file_get_contents('path/to/my_html_snippet.my_ext'); // or save it for later in a string
Create a file at path/to/my_html_snippet.my_ext that contains the HTML you want to print.
Its seems like you need a templates.
See mustache (examples and docs - https://github.com/bobthecow/mustache.php)

PHP Pagination different page call

i use php code for call page using url like this
Home
News
Event
etc...
many sample pagination using url
href="news.php?page=$pageno"
my question is how to make link url pagination if using url like
href="?page=news"
i have try using this code
<a href=?page=news?page=$i>$i</a>
but not work, Please help??
i am newbie on php
I think your question is a bit blurry, but try to figure out the logic using the following rudimental code.
In the page where you place your links, enter this:
1
In your news.php:
<?php
if ($_GET['page']) {
// do stuff with $_GET['page'], which is '1' in this case.
}
?>
In this example, $_GET['page'] will evaluate to the number 1. This variable can then be used to include the news you want to display, be it through including another php-page, or by calling a set of articles from a database.
Don't forget to put <?php and ?> tags around the code, otherwise things won't work.

Drupal: How to display block/region in views page?

I have a views page that contains a listing of one of my content type. I used views-view-list--<name of my view>.tpl to theme the page. However, the region/blocks that I defined are not displaying. In other pages it works fine, but on the views page it does not. I'm trying to display a user login block in my defined region.
Please tell me how to access my user login block or my region to display on my views.
Your help is greatly appreciated. I'm using drupal 6 by the way.
Best regards,
Think i ran into something similar yesterday. I was trying to print a region, for example
<?php print $footer ?>
but inside a tpl file that came from views - and for whatever reason, it doesn't output the region from one of the views tpl files.
I used this code:
<?php print theme('blocks', footer); // change "footer" to the name of your region ?>
As I am writing this, a safer and maybe recommended way in D7 would be:
<?php
$region = block_get_blocks_by_region('footer') //first define the block;
print render($region) // then print the block;
?>
I tried #Garry but I got some errors back from Drupal. Please see here
Hope this helps someone down the line.
Any page in drupal have page template based on url or content type . So you have to create right page template for your page where views page/block to be displayed. I'm assuming that you are using page template based on url
This worked for me, except the syntax above needs semi-colons after (); for example print render($region); otherwise thank you for this answer
This is how the snippet will work for Drupal 7 with Bootstrap - HTML tags, considering that the 'billboard' region host an ad:
<aside class="col-xs-0 col-sm-12 role="banner">
<?php
$region = block_get_blocks_by_region('billboard');
print render($region);
?>
</aside>

Categories