Class function echo to link

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nitman
Forum Newbie
Posts: 5
Joined: Sun Nov 21, 2010 7:55 pm

Class function echo to link

Post by nitman »

Hi,
I'm fairly a novice to php. So plz excuse my ignorance :D . I've this test app, where I'm bringing some value by echoing public function of a class. I can do the echo part. Now, my question is, can I put this value in some new variable?
Also, can I in some way use it to make a click-able link?

Code: Select all

....snip....
include 'myClass.class.php';
$createFile = new myClassFunction();

                echo '<div id="preview" style="display:block"><p>Please wait.</p>';
                // still working on this part
                flush();
// Main Program
            if ($createFile->DownloadPDF(trim($_POST['userPDFurl'])))
            {
               echo "http://mystie.cc/",$createFile->GetFileName(),"<br />\n";   //This is the file user should be able to download
               echo ($createFile->GeneratePDF('$_POST[quality]')) ? '<p>Success!</p>' : '<p>Error generating PDF file!</p>';
            }
            else
            {
               echo '<p>Error downloading PDF!</p>';
 ....snip....            } 
From above, can I put '$createFile->GetFileName()' in some new variable? I've been trying to use it in href link, bu I'm getting some really :crazy: results.
Thanks.

Nitin
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Class function echo to link

Post by McInfo »

Your question puzzles me because I don't see how you could know how to use classes without knowing about variables. I also don't see how you could use HTML tags like <div> and <p> without knowing about <a>. Did I miss the point of your question?

If you don't know if you can do something, why not try it and see what happens?
nitman
Forum Newbie
Posts: 5
Joined: Sun Nov 21, 2010 7:55 pm

Re: Class function echo to link

Post by nitman »

Thanks for reply. I see what you are saying. So here is the function from the class:

Code: Select all

public function GetFileName()
        {
            return $this->_pdfFileName;
        }
So I'm guessing, I can pipe the value like this

Code: Select all

$myFile = $createFile->GetFileName($_dymamicFile)
It doesn't look right, but worth a try!

Nitin
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Class function echo to link

Post by McInfo »

Except for a missing semicolon and an argument being passed to a function that accepts none, it looks fine to me. I say that with some hesitation because I don't know what the rest of the class looks like.

Is it that you want to call the function once but use the returned value twice? It won't add much overhead to call that particular function multiple times because it just provides access to a (private, I'm assuming) variable; but if you don't want to name a new variable, you can maybe use printf().
nitman
Forum Newbie
Posts: 5
Joined: Sun Nov 21, 2010 7:55 pm

Re: Class function echo to link

Post by nitman »

I think another concept may have got cleared to me about the function, when you stated ".. an argument being passed to a function that accepts none". So the way I equated the variable is in fact passing the value to function. 8O hmm.. Thanks.
Moving along, "Is it that you want to call the function once but use the returned value twice? " Yes, I want be able the value at least twice.
I want the value returned by the function in a hyperlink.

Thanks.
Nitin
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Class function echo to link

Post by McInfo »

Is this topic solved, or do you need help creating a hyperlink?
nitman
Forum Newbie
Posts: 5
Joined: Sun Nov 21, 2010 7:55 pm

Re: Class function echo to link

Post by nitman »

I'd really like help in creating a link. Any input would be appreciated.

Thank you,
Nitin
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Class function echo to link

Post by McInfo »

I'm having difficulty determining your knowledge level, so I'll recommend some resources.

If you need help with HTML, read through the HTML tutorial on W3Schools.com.

If you need help with PHP concepts, take time to read the manual, especially the Language Reference section.

This might be helpful.

Code: Select all

<?php
class MyFile {
    private $name = 'log.txt';
    function getName () {
        return $this->name;
    }
}
$file = new MyFile();
printf('<a href="http://localhost/%1$s">%1$s</a>', $file->getName());
// <a href="http://localhost/log.txt">log.txt</a>
nitman
Forum Newbie
Posts: 5
Joined: Sun Nov 21, 2010 7:55 pm

Re: Class function echo to link

Post by nitman »

Thanks for all your help. As I mentioned, earlier, I'm new to PHP. But I'm learning.
I got the link to show up correctly and click able as well.
Issue resolved.
Post Reply