SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Enthusiast trat02community's Avatar
    Join Date
    Sep 2005
    Location
    Slovenia - Europe
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    inserting php function in HTML code prob.

    I have a class BasicPageView.php whitch adds header to page.And one of my functions for adding the css.
    The problem is that I can't put that function(not even echo() ) into html code, that is to be parsed.

    code:
    PHP Code:
    function addHeader($str='',$kateriCss$barva){
            
    $this->output 
                
    '
                <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                <html xmlns="http://www.w3.org/1999/xhtml">
                <head>
                <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                <title>Fideam d.o.o.</title>
                <link href="css/'
    . echo("1024x768") .'.css" rel="stylesheet" type="text/css" />
                </head>
                
                <body>
                '
    ;
        }
    //end method addHeader 
    Any ideas how can I overcome this?Or some other solution maybe?
    I'm putting $output piece by piece together and then echo it out.

  2. #2
    SitePoint Enthusiast pento's Avatar
    Join Date
    Jan 2006
    Location
    Russia, Novosibirsk
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by trat02community
    Any ideas how can I overcome this?Or some other solution maybe?
    I'm putting $output piece by piece together and then echo it out.
    Do you know how PHP works?
    GetDown->MakeLove();

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe YOu Mean concatenation ?
    if, then heres an example how you can do it:

    PHP Code:
    class mypage{
    var 
    $output;

    function 
    header(){
    $this->output .= ' Header Code Goes Here ' ;
    }

    function 
    body(){
    $this->output .= ' body Code Goes Here ' ;
    }

    function 
    footer(){
    $this->output .= ' footer Code Goes Here ' ;

    }


    And On When You Wana Echo The $output

    PHP Code:
    $html = new mypage;
    $html->header();
    $html->body();
    $html->footer();

    echo 
    $html->output

  4. #4
    SitePoint Enthusiast trat02community's Avatar
    Join Date
    Sep 2005
    Location
    Slovenia - Europe
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    Quote Originally Posted by pento
    Do you know how PHP works?
    Well I'm learning
    I managed to solve the problem, I used variable $kateriCss and things work well, tnx.

  5. #5
    SitePoint Enthusiast trat02community's Avatar
    Join Date
    Sep 2005
    Location
    Slovenia - Europe
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know that.
    My problem was
    <link href="css/'. echo("1024x768") .'.css" rel="stylesheet" type="text/css" />
    this line.

    But i still don't know how can I use function in concatenation there.The code is something similar that u showed plus I have classes.

  6. #6
    SitePoint Enthusiast pento's Avatar
    Join Date
    Jan 2006
    Location
    Russia, Novosibirsk
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by trat02community
    I know that.
    My problem was this line.

    But i still don't know how can I use function in concatenation there.The code is something similar that u showed plus I have classes.
    If you want to have dependce of css and screen resolution you must use client-side script such as JavaScript.
    GetDown->MakeLove();

  7. #7
    SitePoint Enthusiast trat02community's Avatar
    Join Date
    Sep 2005
    Location
    Slovenia - Europe
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    I hope you see where my problem is....

    code:
    PHP Code:
    class PodjetjePageView{
       ....
    var 
    $vsebina '
                        <div id="box3">
                          <table border="1" cellspacing="0" cellpadding="0" width="100%" height="300px">
                              <tr>
                                <td valign="top"><!-- polje za navigacijo -->
                                    <div id="navigacija"> <!-- menuji -->
                                        '
    . include("menu.php") .'
                                    </div> 
                                </td>
                                <td valign="top" align="right"><!-- polje za vsebino in ostalo -->
                                    <div id="gumbiSekcije">
                                        Content for  id gumbiSekcije Goes Here        
                                    </div>
                            
                                    <div id="frameVsebine">
                                        Content for  id frameVsebine Goes Here        
                                    </div>
                                </td>
                              </tr>
                          </table>
                     
                        </div>
                        '
    ;
        
        
    /*
         *    Metoda, ki posreduje generiran HTMl naprej!
         *    @return String
         */
        
    function getView(){
            
    $this->addHeader($this->animacija,'1024x768_podjetje');    
            
    $this->addSearch();
            
    $this->addContent($this->vsebina);
            
    $this->addFooter($this->noga);
            return 
    $this->output;
        }
      ....
    }
    //end class 
    code goes to siteController.php:
    PHP Code:
    function render(){
            return 
    $this->page->getView(); 
    and finally to index.php:
    PHP Code:
    include('./lib/SiteController.php');
    include(
    './lib/BasicPageView.php');
    include(
    './lib/MainPageView.php');
    include(
    './lib/PodjetjePageView.php');

    $site = &new SiteController($_GET);
    echo 
    $site->render(); 
    My problem is include statement (include("menu.php")).I can't use any php code if I render page in this way! This was my problem in previous example too.

  8. #8
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Turn menu.php into a function that returns the HTML instead of just including it.

  9. #9
    SitePoint Enthusiast trat02community's Avatar
    Join Date
    Sep 2005
    Location
    Slovenia - Europe
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman
    Turn menu.php into a function that returns the HTML instead of just including it.
    It crossed my mind, but my general problem is that I can't use any php code(function,variable) where the include() statment is now.
    The problem is not the include() statment itself.

    I get this error : Parse error: parse error, unexpected '.', expecting ',' or ';' in ... whitch refers to include() or. echo() line.

    Example:
    Code:
    <tr>
    	<td valign="top">
    		<div id="navigacija">
    			'. echo("this is not working") .'
    		</div> 
    	</td>
    </tr>
    It's same piece of code as previous, just instead include('menu.php') is now used echo("this is not working"). Just to show u where my problem is.I just want to put some function or php code on that place.
    I hope it's clearer where I'm stuck?

  10. #10
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You don't need or want an echo statement there. You want to either put the words directly or a function that returns a string...

    You're assigning a string to the variable $vsebina. You assign it some text, then try to concatenate the echo() function which does not return a string, it immediately sends a string to the browser. That's not the effect you want. Neither is including a file, which also does not return a string, but puts the contents of a file into another file.

    If menu.php just contains straight HTML, you could fopen() it, read it into a string, and add that string to your variable. If it's more complex, turn it into a function that returns a string, include menu.php at the top of whatever file needs access to that function, and use it that way.

  11. #11
    SitePoint Enthusiast trat02community's Avatar
    Join Date
    Sep 2005
    Location
    Slovenia - Europe
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy

    Ok, nice answer.Some things are clearer now.
    This should work then....

    code:
    Code:
    <tr>
    	<td valign="top">
    		<div id="navigacija">
    			'. $this->dodaj(); .'
    		</div> 
    	</td>
     </tr>
    PHP Code:
    function dodaj(){
            return 
    'SOME STRING';
        } 
    but it doesen't?
    I'm still missing something?!

  12. #12
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You use semicolons to end statements in PHP. You're not ending a statement, you're in the middle of a statement, so don't use a semicolon after dodaj().

    I also have the feeling you can't do this when declaring variables for a class. You should assign their initial values in the class constructor or an initialization function.

  13. #13
    SitePoint Enthusiast trat02community's Avatar
    Join Date
    Sep 2005
    Location
    Slovenia - Europe
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried, not working.

  14. #14
    SitePoint Enthusiast trat02community's Avatar
    Join Date
    Sep 2005
    Location
    Slovenia - Europe
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy

    Here is code.It's not much.If someone could tahe a look.
    Attached Files Attached Files

  15. #15
    SitePoint Enthusiast trat02community's Avatar
    Join Date
    Sep 2005
    Location
    Slovenia - Europe
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Ok guys, i managed to input the code in the right place.The problem is that i don't know why didn't work in previous way.
    What i had to do is that I passed the string value in function ( addPodjetjeHeader('STRING') ), whitch generates HTML.

    Tnx,all of u who tried to help me.A learned a lot from this post!!

  16. #16
    SitePoint Enthusiast trat02community's Avatar
    Join Date
    Sep 2005
    Location
    Slovenia - Europe
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wink

    Quote Originally Posted by Dan Grossman
    I also have the feeling you can't do this when declaring variables for a class. You should assign their initial values in the class constructor or an initialization function.
    Exactly why didn't work! Tnx.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •