umm anyone knows how to debug smarty?
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: umm anyone knows how to debug smarty?

  1. #1
    Senior Member
    Join Date
    Sep 2011
    Posts
    258

    umm anyone knows how to debug smarty?

    Well I am trying to incorporate smarty as my template engine. It does not work out right, and instead it shows nothing but a blank page. But this is not really the problem, the issue is that I do not receive any warnings, errors or notices, nothing at all. I make sure the error reporting setting is set to E_ALL, it still wont show anything. Do anyone of you have experience working with Smarty? I heard that Smarty by default turns off error reporting, is there a way to enable it instead? Theres no way I can debug smarty when it shows just a blank page. Even some error messages can at least help me learn what the problem is... *sigh*

  2. #2
    Senior Member
    Join Date
    Mar 2009
    Posts
    811
    I have never used smarty, but my coworkers have. When the word is even whispered, they run for the hills. None of them have even one nice thing to say about it. Is it absolutely necessary to use in your project?
    Declare variables, not war.

  3. #3
    Senior Member
    Join Date
    Sep 2011
    Posts
    258
    Well I think so, it gives me headache to see lots of PHP <? and ?> tags in html files, and smarty's templates make it look so much nicer. Perhaps its just me though.

  4. #4
    Senior Member traq's Avatar
    Join Date
    Jun 2011
    Location
    so.Cal
    Posts
    949
    {debug}

    debugging console

    That's just from a quick google search. I think I've mentioned my opinion of Smarty.
    Last edited by traq; 11-23-2012 at 04:26 PM.

  5. #5
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,428
    Quote Originally Posted by Lord Yggdrasill View Post
    smarty's templates make it look so much nicer. Perhaps its just me though.
    You can avoid looking at all of that syntax altogether and just use something like Microsoft Frontpage to design your website!

  6. #6
    Senior Member
    Join Date
    Sep 2011
    Posts
    258
    Quote Originally Posted by bradgrafelman View Post
    You can avoid looking at all of that syntax altogether and just use something like Microsoft Frontpage to design your website!
    I said it was just my personal opinion, its not like I am trying to force my idea on anyone of you. I dont like having different languages running on the same script, I separate php from html almost completely. If you do not like it, dont bother.

    And after consulting with my host, they found that the inclusion of smarty class was blocked by suhosin. Its kinda weird, but it does explain lots of things such as var_dump() does not show anything after I call include() function on smarty class. I was wondering though, do anyone of you know what is a valid/allowed include path for suhosin? Right now I am using this in my script:

    PHP Code:
    include("http://www.domain.com/scriptpath/inc/smarty/Smarty.class.php"); 
    Is the www part the cause of the error? Or is it with the file name Smarty.class.php? In the worst case scenario I just copy/paste smarty class into the script calling it so it can be loaded, lol.

  7. #7
    Senior Member traq's Avatar
    Join Date
    Jun 2011
    Location
    so.Cal
    Posts
    949
    Is this on the same server as your site? If so, try using the path rather than a URL.

  8. #8
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,428
    Quote Originally Posted by Lord Yggdrasill View Post
    Right now I am using this in my script:

    PHP Code:
    include("http://www.domain.com/scriptpath/inc/smarty/Smarty.class.php"); 
    That shouldn't do anything useful, since you'll only be include()'ing whatever is output by Smarty.class.php. So, unless that file is outputting a bunch of code (e.g. you could directly navigate to that URL in your web browser, view the source code of the page, and see the PHP code you expect to be include()'ing), using a URL here doesn't make any sense.

  9. #9
    Senior Member
    Join Date
    Sep 2011
    Posts
    258
    Quote Originally Posted by traq View Post
    Is this on the same server as your site? If so, try using the path rather than a URL.
    Yeah it is, which is kinda strange.

    Edit: I've found the cause of the problem. It seems that suhosin was blocking the include path, I have to use relative path instead of the path beginning with http://www to get it to work. But this introduces a problem though, it can be a headache when I have to decide how many '../' I have to use in the include path.

  10. #10
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,885
    Quote Originally Posted by Lord Yggradsill
    It seems that suhosin was blocking the include path, I have to use relative path instead of the path beginning with http://www to get it to work.
    That's not surprising. URLs are not file paths. Requesting a file to include via http is a potential security risk, since it implies that the server supplying the document is someone else's.
    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

  11. #11
    Senior Member
    Join Date
    Sep 2011
    Posts
    258
    Quote Originally Posted by Weedpacket View Post
    That's not surprising. URLs are not file paths. Requesting a file to include via http is a potential security risk, since it implies that the server supplying the document is someone else's.
    Yeah I figured, I am using the server var $_SERVER['DOCUMENT_ROOT'] in place of http://www.domain.com/, which works out nicely. There is still one more issue with smarty. When I have a variable that contains url to an external site assigned to smarty template, it will generate a blank page too. One example is this:

    PHP Code:
    $credits "Template Designed by <a href = 'http://www.templatedesign.com'> Smarty Template Design Inc</a>";
    $smarty->assign("credits"$credits); 
    And in the .tpl file it gives a blank page if I attempt to use this variable {$credit}, the blank page goes away as long as I remove it. Is there a way to help with this?

  12. #12
    PHP Witch laserlight's Avatar
    Join Date
    Apr 2003
    Location
    Singapore
    Posts
    13,563
    Quote Originally Posted by Lord Yggdrasill
    I dont like having different languages running on the same script
    I note that if you are using smarty within some HTML page, then technically you are mixing a template language with HTML, so you have "different languages running on the same script". If you use PHP as a template language, then you are still mixing a template language with HTML, so the real difference to you is that "smarty's templates make it look so much nicer"
    Use Bazaar for your version control system
    Read the PHP Spellbook
    Learn How To Ask Questions The Smart Way

  13. #13
    Senior Member
    Join Date
    Jul 2007
    Posts
    3,657
    Quote Originally Posted by Lord Yggdrasill View Post
    Yeah I figured, I am using the server var $_SERVER['DOCUMENT_ROOT'] in place of http://www.domain.com/, which works out nicely.
    No, it doesn't work out nicely. Well, it may work under certain conditions, but they relate to two entirely different concepts, not just two different strings. These two on the other hand are two different strings, which both (possibly) represent file paths, (and possibly might be used as such)
    $string_one = '/path1/file';
    $string_one = '/path2/file';
    [/php]

    While these two are also two different strings - but not file paths They are in point of fact, URLs
    PHP Code:
    $string_one 'http://example.com/path1/file';
    $string_one 'http://example.com/path2/file'
    Do note that accessing a file path means you HAVE to be on the same machine as the file, or otherwise be able to mount a remote disk locally. This is not done via HTTP, altough I supposed you could write code to do so. Also note that accessing an URL means you need to make a HTTP REQUEST to a WEB SERVER, which is completely different than accessing the local file system, even though both requests MAY end up accessing the same file on the same disk.

    And finally note that /path1/file above MAY actually refer to the same file being accessed with http://example.com/path2/file, while /path2/file above MAY actually refer to the same file being accessed by http://example.com/path1/file (and no - there are no variables involved, just plain strings).

    Quote Originally Posted by Lord Yggdrasill View Post
    There is still one more issue with smarty. When I have a variable that contains url to an external site assigned to smarty template, it will generate a blank page too.
    Blank pages are caused by pages containing no output. Or serious errors. Or some additional stuff which performs post processing and fails miserably when there are errors.

    Quote Originally Posted by Lord Yggdrasill View Post
    One example is this:
    PHP Code:
    $credits "Template Designed by <a href = 'http://www.templatedesign.com'> Smarty Template Design Inc</a>";
    $smarty->assign("credits"$credits); 
    Well, if you consider the above a complete example, there is no output. Thus, if you get a blank page, it's working as expected. However, if you do output the above into a document served as HTML, ther will be errors.

    I'm not certain about how HTML5 would treat "href", but I'm guessing it'd work like any other such construct, which would be equal to href="href", which in turn would take you to the RELATIVE PATH document "href". On the other hand, if I try that in Firefox, it takes me to the document root, so it could be href is allowed under HTML5, and defaults to document root (as in http://example.com/ and NOT as /path/to/docroot/). But I doubt it's actually valid HTML 5.
    But I do know that there is no attribute named = and there certainly is no attribute named 'http://www.templatedesign.com'.

    Try removing some white spaces and see what happens.

    Quote Originally Posted by Lord Yggdrasill View Post
    And in the .tpl file it gives a blank page if I attempt to use this variable {$credit}, the blank page goes away as long as I remove it. Is there a way to help with this?
    Smarty ought to ouput whatever you tell it to, as far as I know. But perhaps you have other things, or perhaps it's possible to set up smarty to do additional parsing, and that one or the other stops output when it encounter certain things that are invalid as HTML. But if you copy paste that link into an html page, and then run that page through a validator (http://validator.w3.org), you'd get those errors. Moreover, if you serve the page as XHTML, the href attribute most definitely has to have an explicit value (which possibly may be empty).

    But as far as I know smarty, it would NOT care about invalid HTML output. Smarty is supposed to let you output whatever you like and doesn't concern itself with what that output is.

  14. #14
    Senior Member
    Join Date
    Jul 2007
    Posts
    3,657
    Since it seems the opinions of Smarty ranges from "really bad" to "simply useless since PHP was designed to do what smarty is doing to begin with", I have to pitch in my opinion and state that I like it. As for the second opinion, well... PHP was designed to do a few things, and yet there are today several libraries and frameworks, and you have probably written some things to abstract away basic functionality yourself. Why? Because it's more readable, reusable, etc. As for it being "really bad", well, I'm a bit curious as to how it's "really bad".

    First off, I really like the caching. It's esay to have separate parts of a page being not cached at all, cached for some, cache for all, and cached for different amounts of time. Each language version cached separately (automatically in combinations of the above). Can I do the same thing using PHP? Of course. But it doesn't necessarily mean I'd want to. Or that I'd get it right if doing it from scratch every time... oh the horror.

    Iteration is identical to PHP, but you will easily keep indented html and readable code, even with large blocks and nested loops

    And in the thread referred to above, it was said that
    PHP Code:
    $title "Some page"
    followed by
    HTML Code:
    <title><?= $title; ?></title>
    was better for a designer than anything else would be. Apart from definitely not agreeing that short open tags are good for anyone, I fail to see how it differs from
    PHP Code:
    $smarty->assign('title''Some page'); 
    HTML Code:
    <title>{$title}</title>
    And since smarty 3, instead of assigning smarty-global variables, you can keep then template-local, so that $title may be page title in one template while it's a text heading in another.

    Also while you may actively work around keeping logic and presentation separate when using smarty, it's pretty decently constructed for making that come naturally.

    As for using Microsoft FrontPage, do such tools actually generate any kind of code you'd want to look at? I've never used them myself, so I wouldn't know. But having no real knowledge of what they do and don't... it's my opinion that they are far off from doing things directly - be that using php to generate html or using smarty to generate php that generates html.

  15. #15
    Senior Member Derokorian's Avatar
    Join Date
    Apr 2011
    Location
    Denver
    Posts
    1,782
    Quote Originally Posted by johanafm View Post
    Apart from definitely not agreeing that short open tags are good for anyone
    I fail to see how they are NOT good for anyone, in fact that's why <?= syntax is available by default in php5.4+ even when short open tags are disabled. Its a new day, and a new way. I definitely prefer to see <?=$var?> than <?php echo $var ?> I find it far more readable.
    Sadly, nobody codes for anyone on this forum. People taste your dishes and tell you what is missing, but they don't cook for you. ~anoopmail
    I'd rather be a comma, then a full stop.
    User Authentication in PHP with MySQLi - Don't forget to mark threads resolved - MySQL(i) warning

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
  •