Problem with URL rewrite, the html template file stops working... - Page 2
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 31

Thread: Problem with URL rewrite, the html template file stops working...

  1. #16
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,401
    Quote Originally Posted by Lord Yggdrasill View Post
    it is loaded in a php page class that uses file_get_content($theme). Is this a problem?
    Considering that file_get_contents() does nothing but get the raw contents of a file, yes, that is a problem if you expect PHP to actually examine the contents of the file and execute any PHP code within it (such as what would be done if you were include()/require()'ing the file instead).

  2. #17
    Senior Member
    Join Date
    Sep 2011
    Posts
    258
    Quote Originally Posted by bradgrafelman View Post
    Considering that file_get_contents() does nothing but get the raw contents of a file, yes, that is a problem if you expect PHP to actually examine the contents of the file and execute any PHP code within it (such as what would be done if you were include()/require()'ing the file instead).
    I see, so the problem will be fixed if I write include($theme) rather than file_get_content($theme)? Is it really that, simple?

  3. #18
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,848
    Without seeing what you're doing with the contents of the file one can only guess; if (conceptually) replacing the call to file_get_contents() with a copy-paste of the contents of the file being got results in the Right Thing, then yes. If you're doing anything other than simply outputting it (in which case readfile() would have been a more straightforward choice), then probably not.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  4. #19
    Senior Member
    Join Date
    Sep 2011
    Posts
    258
    Alright thanks. I was wondering how this might work out since there are lots of placeholders in my html template. These placeholders are in the format of :TITLE:, :CONTENT, :SIDEBAR:, which provides a good reason to use get_file_content($template). PHP will replace these placeholders with php variables, this is how one single html file works for pretty much all php pages. I am not quite sure if the same effect can be achieved if I use include($template), since the entire template system may have to be redesigned otherwise.

    And I'd like to ask if there is a way to separate html header from body. The problem can be easily resolved if the <head> tags can be placed in a different html file from <body>. I tried to search on google, but found nothing on how to accomplish this. I am not sure if this is even doable?

  5. #20
    Senior Member traq's Avatar
    Join Date
    Jun 2011
    Location
    so.Cal
    Posts
    949
    Of course it's "doable." Just do it.
    You'd need to process both templates (head and body), of course, and make sure they're output in the correct order.

  6. #21
    Senior Member
    Join Date
    Sep 2011
    Posts
    258
    I see, that would be great. This way I have the header content 'included', while the body is loaded using get_file_content so the html can be partially converted to string with place holders replaced by php vars.

    So is this the correct format?
    header file
    PHP Code:
    <html>
    <
    head>
    // header content here
    </head
    Body File:
    PHP Code:
    <html>
    <
    body>
    // body content here
    </body>
    </
    html

  7. #22
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,848
    You wouldn't have the opening <html> tag in the body file - it's already in the header file.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  8. #23
    Senior Member
    Join Date
    Sep 2011
    Posts
    258
    Thanks for all of your help, everyone. It works now, although it took me longer since I found out that the admin control panel's navlinks were messed up too. I fixed them in 2 hours.

    Perhaps it is time for me to use smarty or a professional template system, this one aint really doing good.

  9. #24
    Senior Member
    Join Date
    Sep 2011
    Posts
    258
    Sorry to have to double post in the topic. I find the url rewriting is not working for get forms, the query string is still messed up. One possible solution is to get rid of get forms, but are there's one problem. Sometimes I do not know what url I will be getting since the url is variable, not fixed. This happens when the form contains drop down select/option elements, and the url depends on these values. What am I supposed to do in this case? I heard its possible to use javascript to get this to work, but I do not know how to do it. Is there another way?

  10. #25
    Senior Member traq's Avatar
    Join Date
    Jun 2011
    Location
    so.Cal
    Posts
    949
    Quote Originally Posted by Lord Yggdrasill View Post
    Perhaps it is time for me to use smarty or a professional template system, this one aint really doing good.
    IMO, Smarty and other template systems for PHP are largely counter-productive, especially for programmers (as opposed to "designers"). You have to learn a second set of rules, syntax, and workarounds for something you could be doing directly in PHP, without the overhead.

    PHP is perfectly suited for templating all on its own. That's basically the task it was created for.
    template.php
    PHP Code:
    <!doctype html>
    <html>
    <head>
        <meta charset-utf-8>
        <title> <?= $title ?> </title>
    <head>
    <body>
        <article>
            <h1> <?= $title ?> </h1>
            <?= $content ?>
        </article>
        <aside>
            <?= $sidebar ?>
        </aside>
    </body>
    </html>
    page.php
    PHP Code:
    <?php

    $title 
    "My PHP Page";
    $content "Hello, World!";
    $sidebar "whatever";

    include( 
    'template.php' );
    ?>
    Quote Originally Posted by Lord Yggdrasill View Post
    Sorry to have to double post in the topic. I find the url rewriting is not working for get forms, the query string is still messed up. One possible solution is to get rid of get forms, but are there's one problem. Sometimes I do not know what url I will be getting since the url is variable, not fixed. This happens when the form contains drop down select/option elements, and the url depends on these values. What am I supposed to do in this case? I heard its possible to use javascript to get this to work, but I do not know how to do it. Is there another way?
    Are you still talking about the URLs to your scripts/stylesheets (same as earlier in this thread)? I don't understand how the query string would be interfering with what we've discussed so far (or why there would be a query string in those URLs in the first place). Or are you talking about something else (you mentioned URL rewriting and form submissions)? Can you clarify/ give an example?
    Last edited by traq; 11-19-2012 at 09:41 PM.

  11. #26
    Senior Member
    Join Date
    Sep 2011
    Posts
    258
    Quote Originally Posted by traq View Post
    IMO, Smarty and other template systems for PHP are largely counter-productive, especially for programmers (as opposed to "designers"). You have to learn a second set of rules, syntax, and workarounds for something you could be doing directly in PHP, without the overhead.

    PHP is perfectly suited for templating all on its own. That's basically the task it was created for.
    template.php
    PHP Code:
    <!doctype html>
    <html>
    <head>
        <meta charset-utf-8>
        <title> <?= $title ?> </title>
    <head>
    <body>
        <article>
            <h1> <?= $title ?> </h1>
            <?= $content ?>
        </article>
        <aside>
            <?= $sidebar ?>
        </aside>
    </body>
    </html>
    page.php
    PHP Code:
    <?php

    $title 
    "My PHP Page";
    $content "Hello, World!";
    $sidebar "whatever";

    include( 
    'template.php' );
    ?>

    Are you still talking about the URLs to your scripts/stylesheets (same as earlier in this thread)? I don't understand how the query string would be interfering with what we've discussed so far (or why there would be a query string in those URLs in the first place). Or are you talking about something else (you mentioned URL rewriting and form submissions)? Can you clarify/ give an example?
    Well the idea is that if I use a get form, the form parameters are automatically passed to the url and mess up the neat format I have been trying to establish. This is an example, although mine is somewhat different:
    http://forums.phpfreaks.com/topic/61...on-a-get-form/

    So I know javascript can be used to solve the problem, but for my application the parameter keys vary from file to file so its tedious to use one javascript function to modify query strings. I was wondering if theres a better way to format the url when it involves a get form.

  12. #27
    Senior Member traq's Avatar
    Join Date
    Jun 2011
    Location
    so.Cal
    Posts
    949
    Are we still talking about this problem, or something else?
    Quote Originally Posted by Lord Yggdrasill View Post
    HTML Code:
    <link rel="stylesheet" href="../templates/acp/css/acp-style.css" type="text/css" />
    I don't understand why a form submission or query string would involve this URL in any way. Are you selecting your stylesheets from a form?

    If we're talking about something else, then I completely "missed it" when we changed the subject.

    In any case, I understand that a problem exists, but I'm afraid I don't understand what "the problem" is.

  13. #28
    Senior Member
    Join Date
    Sep 2011
    Posts
    258
    Oh sorry this is a different problem now, still related to URL rewrite so I did not bother starting a new thread.

    The problem is that using Get Form messes up the well-formatted URL.

  14. #29
    Senior Member traq's Avatar
    Join Date
    Jun 2011
    Location
    so.Cal
    Posts
    949
    which URL?

    Can you explain your new problem from the beginning? I think a new thread would not be inappropriate, since it's a new problem.
    Last edited by traq; 11-20-2012 at 10:23 AM.

  15. #30
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    7,694
    Of course a GET form "messes up" a "well-formed" URL (although 'well-formed' is a nebulous term).

    Do you also complain that clear weather turns the sky blue?

    How about submitting forms via POST and having a central "controller" script that decides where to send the browser, and with what variables attached. It might be written in such a way as to preserve your URI rewriting scheme ... whatever it is.
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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