home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 June / PCpro_2005_06.ISO / files / opensource / xamp / xampp-win32.exe / xampp / FAQ < prev    next >
Encoding:
Text File  |  2004-03-24  |  12.5 KB  |  281 lines

  1. QUESTION INDEX
  2. --------------
  3.  
  4. GENERAL
  5.  
  6. Q: What is Smarty?
  7. Q: What's the difference between Smarty and other template engines?
  8. Q: What do you mean "Compiled PHP Scripts" ?
  9. Q: Why can't I just use PHPA (http://php-accelerator.co.uk) or Zend Cache?
  10. Q: Why does smarty have a built in cache? Wouldn't it be better to handle this
  11.    in a separate class?
  12. Q: Is Smarty faster than <insert other PHP template engine>?
  13. Q: How can I be sure to get the best performance from Smarty?
  14. Q: Do you have a mailing list?
  15. Q: Can you change the mailing list so reply-to sends to the list and not the
  16.    user?
  17.  
  18. TROUBLESHOOTING
  19.  
  20. Q: Smarty doesn't work.
  21. Q: I get the following error when running Smarty:
  22.    Warning:  Smarty error: problem creating directory "templates_c/239/239105369"
  23.    in /path/to/Smarty.class.php on line 542
  24. Q: I get the following error when running Smarty:
  25.    Warning: Wrong parameter count for preg_replace() in
  26.    Smarty.class.php on line 371
  27. Q: I get this error when passing variables to {include}:
  28.    Fatal error: Call to undefined function: get_defined_vars() in
  29.    /path/to/Smarty/templates_c/index.tpl.php on line 8
  30. Q: I get PHP errors in my {if} tag logic.
  31. Q: I'm changing my php code and/or templates, and my results are not getting
  32.    updated.
  33. Q: I'm running Windows 2000 and I get blank content. My compiled PHP files are
  34.    also zero length.
  35. Q: The template goes into an infinite loop when I include included templates
  36.    that pass local variables
  37. Q: Javascript is causing Smarty errors in my templates.
  38.  
  39. MISC
  40.  
  41. Q: Can I use Macromedia's Dreamweaver to edit my templates?
  42. Q: Dreamweaver is urlencoding the template delimiters when they are in a SRC or
  43.    HREF link. How do I get around this?
  44.  
  45. HOWTO
  46.  
  47. Q: How do I generate different cache files per template based on arguments
  48.    passed to the page?
  49. Q: How do I pass a template variable as a parameter? {function param={$varname}}
  50.    does not work.
  51. Q: How do I include cached template(s) within a non-cached template?
  52.  
  53.  
  54. GENERAL
  55. -------
  56.  
  57. Q: What is Smarty?
  58. A: Smarty is a template engine for PHP... but be aware this isn't just another
  59.    PHP template engine. It's much more than that.
  60.  
  61. Q: What's the difference between Smarty and other template engines?
  62. A: Most other template engines for PHP provide basic variable substitution and
  63.    dynamic block functionality. Smarty takes a step further to be a "smart"
  64.    template engine, adding features such as configuration files, template
  65.    functions, variable modifiers (see the docs!) and making all of this
  66.    functionality as easy as possible to use for both programmers and template
  67.    designers. Smarty also compiles the templates into PHP scripts, eliminating
  68.    the need to parse the templates on every invocation, making Smarty extremely
  69.    scalable and manageable for large application needs.
  70.  
  71. Q: What do you mean "Compiled PHP Scripts" ?
  72. A: Smarty reads the template files and creates PHP scripts from them. Once
  73.    these PHP scripts are created, Smarty executes these, never having to parse
  74.    the template files again. If you change a template file, Smarty will
  75.    recreate the PHP script for it. All this is done automatically by Smarty.
  76.    Template designers never need to mess with the generated PHP scripts or even
  77.    know of their existance. (NOTE: you can turn off this compile checking step
  78.    in Smarty for increased performance.)
  79.  
  80. Q: Why can't I just use PHPA (http://php-accelerator.co.uk) or Zend Cache?
  81. A: You certainly can, and we highly recommend it! What PHPA does is caches
  82.    compiled bytecode of your PHP scripts in shared memory or in a file. This
  83.    speeds up server response and saves the compilation step. Smarty creates PHP
  84.    scripts, which PHPA will cache nicely. Now, Smarty's built-in cache is
  85.    something completely different. It caches the _output_ of the template
  86.    contents. For example, if you have a template that requires several database
  87.    queries, Smarty can cache this output, saving the need to call the database
  88.    every time. Smarty and PHPA (or Zend Cache) complement each other nicely. If
  89.    performance is of the utmost importance, we would recommend using one of
  90.    these with any PHP application, using Smarty or not. As you can see in the
  91.    benchmarks, Smartys performance _really_ excels in combination with a PHP
  92.    accelerator.
  93.  
  94. Q: Why does Smarty have a built in cache? Wouldn't it be better to handle this
  95.    in a separate class?
  96. A: Smarty's caching functionality is tightly integrated with the template
  97.    engine, making it quite a bit more flexible than a simple caching wrapper.
  98.    For instance, you can cache select portions of a template page. Let's say
  99.    you have a polling box on your site. With Smarty, you can leave the poll
  100.    dynamic and cache the rest of the page. You can also pass templates
  101.    multiple cache ids, meaning that a template can have several caches
  102.    depending on URL, cookies, etc.
  103.  
  104. Q: Is Smarty faster than <insert other PHP template engine>?
  105. A: See the benchmark page for some performance comparisons. Smarty's approach
  106.    to templates is a bit different from some languages: it compiles templates
  107.    into PHP scripts instead of parsing them on each invocation. This usually
  108.    results in great performance gains, especially with complex templates.
  109.    Coupled with the built-in caching of Smarty templates, the performance is
  110.    outstanding.
  111.  
  112. Q: How can I be sure to get the best performance from Smarty?
  113. A: Be sure you set $compile_check=false once your templates are initially
  114.    compiled. This will skip the unneeded step of testing if the template has
  115.    changed since it was last compiled. If you have complex pages that don't
  116.    change too often, turn on the caching engine and adjust your application so
  117.    it doesn't do unnecessary work (like db calls) if a cached page is
  118.    available. See the documentation for examples.
  119.    
  120. Q: Do you have a mailing list?
  121. A:  We have a few mailing lists. "general" for you to share your ideas or ask
  122.     questions, "dev" for those interested in the development efforts of Smarty,
  123.     and "cvs" for those that would like to track the updates made in the cvs
  124.     repository.
  125.  
  126.     send a blank e-mail message to:
  127.       smarty-general-subscribe@lists.php.net (subscribe to the general list)
  128.       smarty-general-unsubscribe@lists.php.net (unsubscribe from the general list)
  129.       smarty-general-digest-subscribe@lists.php.net (subscribe to digest)
  130.       smarty-general-digest-unsubscribe@lists.php.net (unsubscribe from digest)
  131.       smarty-dev-subscribe@lists.php.net (subscribe to the dev list)
  132.       smarty-dev-unsubscribe@lists.php.net (unsubscribe from the dev list)
  133.       smarty-cvs-subscribe@lists.php.net (subscribe to the cvs list)
  134.       smarty-cvs-unsubscribe@lists.php.net (unsubscribe from the cvs list)
  135.     You can also browse the mailing list archives at
  136.     http://marc.theaimsgroup.com/?l=smarty&r=1&w=2
  137.  
  138.  
  139.  
  140. Q: Can you change the mailing list so Reply-To sends to the list and not the
  141.    user?
  142. A: Yes we could, but no we won't. Use "Reply-All" in your e-mail client to send
  143.    to the list. http://www.unicom.com/pw/reply-to-harmful.html
  144.  
  145. TROUBLESHOOTING
  146. ---------------
  147.  
  148. Q: Smarty doesn't work.
  149. A: You must be using PHP 4.0.6 or later if you use any version of Smarty
  150.    past 2.0.1. Read the BUGS file for more info.
  151.  
  152. Q: I get the following error when running Smarty:
  153.    Warning:  Smarty error: problem creating directory "templates_c/239/239105369"
  154.    in /path/to/Smarty.class.php on line 542
  155. A: Your web server user does not have permission to write to the templates_c
  156.    directory, or is unable to create the templates_c directory. Be sure the
  157.    templates_c directory exists in the location defined in Smarty.class.php,
  158.    and the web server user can write to it. If you do not know the web server
  159.    user, chmod 777 the templates_c directory, reload the page, then check the
  160.    file ownership of the files created in templates_c. Or, you can check the
  161.    httpd.conf (usually in /usr/local/apache/conf) file for this setting:
  162.    User nobody
  163.    Group nobody
  164.  
  165. Q: I get the following error when running Smarty: Warning: Wrong parameter
  166.    count for preg_replace() in Smarty.class.php on line 371
  167. A: preg_replace had a parameter added in PHP 4.0.2 that Smarty
  168.    requires. Upgrade to at least 4.0.6 to fix all known PHP issues with
  169.    Smarty.
  170.  
  171. Q: I get this error when passing variables to {include}:
  172.    Fatal error: Call to undefined function: get_defined_vars() in
  173.    /path/to/Smarty/templates_c/index.tpl.php on line 8
  174. A: get_defined_vars() was added to PHP 4.0.4. If you plan on passing
  175.    variables to included templates, you will need PHP 4.0.6 or later.
  176.  
  177. Q: I get PHP errors in my {if} tag logic.
  178. A: All conditional qualifiers must be separated by spaces. This syntax will not
  179.    work: {if $name=="Wilma"} You must instead do this: {if $name == "Wilma"}.
  180.    The reason for this is syntax ambiguity. Both "==" and "eq" are equivalent
  181.    in the template parser, so something like {if $nameeq"Wilma"} wouldn't be
  182.    parsable by the tokenizer.
  183.  
  184. Q: I'm changing my php code and/or templates, and my results are not getting
  185.    updated.
  186. A: This may be the result of your compile or cache settings. If you are
  187.    changing your php code, your templates will not necessarily get recompiled
  188.    to reflect the changes. Use $force_compile during develpment to avoid these
  189.    situations. Also turn off caching during development when you aren't
  190.    specifically testing it. You can also remove everything from your
  191.    compile_dir and cache_dir and reload the page to be sure everything gets
  192.    regenerated.
  193.  
  194. Q: I'm running Windows 2000 and I get blank content. My compiled PHP files are
  195.    also zero length.
  196. A: There seems to be a problem with some W2k machines and exclusive file
  197.    locking. Comment out the flock() call in _write_file to get around this,
  198.    although be aware this could possibly cause a problem with simultaneous
  199.    writes to a file, especially with caching turned on. NOTE: As of Smarty
  200.    1.4.0, a workaround was put in place that should solve this.
  201.  
  202. Q: The template goes into an infinite loop when I include included templates
  203.    that pass local variables
  204. A: This was fixed in 1.3.2 (new global attribute)
  205.  
  206. Q: Javascript is causing Smarty errors in my templates.
  207. A: Surround your javascript with {literal}{/literal} tags. See the docs.
  208.  
  209. MISC
  210. ----
  211.  
  212. Q: Can I use Macromedia's Dreamweaver to edit my templates?
  213. A: Certainly. You might want to change your tag delimiters from {} to something
  214.    that resembles valid HTML, like <!--{ }--> or <{ }> or something similar.
  215.    This way the editor won't view the template tags as errors.
  216.  
  217. Q: Dreamweaver is urlencoding the template delimiters when they are in a SRC or
  218.    HREF link. How do I get around this?
  219. A: In Edit - Properties - Rewrite HTML you can specify if Dreamweaver should
  220.    change special letters to %-equivalent or not. The default is on which
  221.    produces this error.
  222.  
  223. HOWTO
  224. -----
  225.    
  226. Q: How do I generate different cache files per template based on arguments
  227.    passed to the page?
  228. A: Use your $REQUEST_URI as the cache_id when fetching the page:
  229.  
  230.    global $REQUEST_URI; // if not already present
  231.    $smarty->display('index.tpl',$REQUEST_URI);
  232.  
  233.    This will create a separate cache file for each unique URL when you call
  234.    index.tpl. See the documentation for display() and fetch()
  235.  
  236. Q: How do I pass a template variable as a parameter? {function param={$varname}}
  237.    does not work.
  238. A: {function param=$varname} (You cannot nest template delimiters.)
  239.  
  240. Q: How do I include cached template(s) within a non-cached template?
  241. A: One way to do it:
  242.  
  243.    $smarty->caching = true;
  244.    $tpl1 = $smarty->fetch("internal1.tpl");
  245.    $tpl2 = $smarty->fetch("internal2.tpl");
  246.    $tpl3 = $smarty->fetch("internal3.tpl");
  247.  
  248.    $smarty->assign("tpl1_contents",$tpl1);
  249.    $smarty->assign("tpl2_contents",$tpl2);
  250.    $smarty->assign("tpl3_contents",$tpl3);
  251.  
  252.    $smarty->caching = false;
  253.    $smarty->display('index.tpl');
  254.  
  255.    index.tpl
  256.    ---------
  257.  
  258.    <table>
  259.            <tr>
  260.                    <td>{$tpl1_contents}</td>
  261.                    <td>{$tpl2_contents}</td>
  262.                    <td>{$tpl3_contents}</td>
  263.            </tr>
  264.    </table>
  265.  
  266.  
  267.  
  268.  
  269.    Another approach:
  270.  
  271.    You could write a custom insert function to fetch your internal
  272.    templates:
  273.  
  274.    <table>
  275.            <tr>
  276.                    <td>{insert name=fetch_tpl tpl="internal1.tpl"}</td>
  277.                    <td>{insert name=fetch_tpl tpl="internal2.tpl"}</td>
  278.                    <td>{insert name=fetch_tpl tpl="internal3.tpl"}</td>
  279.            </tr>
  280.    </table>
  281.