Exercise: Install and configure Smarty, and write a small example


Solution
Download the solution to this exercise in a zip file exercise-smarty.zip. Be carreful, the architecture presented here is not secure at all. Directories containing templates and config files must be out of the document root.
  • Configuration of Smarty : don't forget to change the rights on the directory, otherwhise, should work easily.
  • The index.php file, contains the connection to the DB and the corresponding business logic (Source File).
  • The file index.tpl contains the main template
  • The file header.tpl contains the header template (the same as for the given example)
  • The file footer.tpl contains the footer template (same as original also)
  • The file test.conf contains the configurations

Install Smarty

  • Download smarty from the smarty server
  • Install the smarty files in a directory.
  • Update your php.ini file, such that the smarty dir is in the include path.
  • Create a directory (outside your web root) that contains the following directories: template, template_c, configs, and cache,
  • Make the directories template_c and cachewriteable for the user "nobody" or "www" (the one apache is configured with).
  • Inside your document root, write a php test file. Write the corresponding template file inside the template directory (the one you have just created).

Write a template

Write an HTML template for displaying one single article. Connect your template with the program writen for the DB course where you could display a single article.
Write an HTML template for displaying a list of articles. You should have the same header in the case of a single article like in the case of a list of articles.
Link this template with the data contained in the DB that you wrote in the DB course. You will display a list of all the items with a link opening each of the articles in a single page (the one you have just written).