Page 1 of 1

Class function echo to link

Posted: Sun Nov 21, 2010 8:08 pm
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

Re: Class function echo to link

Posted: Sun Nov 21, 2010 8:43 pm
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?

Re: Class function echo to link

Posted: Sun Nov 21, 2010 9:39 pm
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

Re: Class function echo to link

Posted: Sun Nov 21, 2010 10:01 pm
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().

Re: Class function echo to link

Posted: Mon Nov 22, 2010 8:34 am
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

Re: Class function echo to link

Posted: Mon Nov 22, 2010 12:33 pm
by McInfo
Is this topic solved, or do you need help creating a hyperlink?

Re: Class function echo to link

Posted: Mon Nov 22, 2010 1:51 pm
by nitman
I'd really like help in creating a link. Any input would be appreciated.

Thank you,
Nitin

Re: Class function echo to link

Posted: Mon Nov 22, 2010 2:43 pm
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>

Re: Class function echo to link

Posted: Mon Nov 22, 2010 3:24 pm
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.