tkself

Installation:

To install, decompress the tk_self source. You will get the directory structure as shown below. Copy or move this structure to the place where your websites are living.

The next two sections will describe the directory layout of tk_self and how to configure the apache webserver to run a tk_self project.

Directory layout:

Image: directory-layout of tk_self

The conf-directory:

The configuration settings and URL-patterns to bind URLs to the view-functions of the application are in the tk_settings.php and tk_urlpatterns.php files in this directory.

The htdocs-directory:

This is the directory that should be exposed to the public as the web-root directory, all other directories should not be accessible from the internet. The index.php-file is the entry point for a tk_self-based website. The static subdirectory should store all static content like image- or css-files etc.

If you use a shared hosting provider and the top-most directory is the web-root directory, then the index.php file in the root-directory is used as entry-point.

The lib-directory:

The tk_self source files are in this directory.

The phptal- and Smarty-directories:

tk_self is designed to use PHPTAL or Smarty as template engines (or even just PHP). After downloading Smarty copy the content of the Smarty libs-directory into the tk_self-smarty directory or set a symbolic link to the libs-directory (as shown by the image). For using PHPTAL it's the same procedure: copy the content of the directory containing the PHPTAL.php-file into the tk_self phptal-directory or set a symbolic link to this directory. A note for Mac OS X users: the symbolic link has to be set from the console by using the ln -s command. An alias set from the Finder will not work.
Symbolic links have the advantage that you can set up multiple tk_self driven websites linked to a common template engine library. So for all tk_self based websites only the code for a single template engine has to be maintained.

The tmpl-directory:

This is the directory for the template files: all template files have to be stored in one of the tmpl-subdirectories depending on the template-engine to use: the PHP subdirectory is for php-files, the phptal directory is for phptal-templates and Smarty templates are stored in the smarty/templates subdirectory. The tkself directory is used by tk_self.

The views-directory:

This is the place for your PHP-code that builds the application: the code for the view-functions will be stored in PHP-files inside the views-subdirectory.

The xtensions-directory:

This directory should contain code used by the application that is called from the view-functions, but not integral part of a view-function. tk_self comes with one example extension called formmailer. See Xtensions for more information.

Server configuration:

The following instructions are for an apache webserver configured for virtual hosts, for serving php-files and with activated mod_rewrite.

Root Server:

If you run your own server, you should add the following to the apache configuration file:

<VirtualHost *:80>
    ServerName your.domain.tld
    DocumentRoot /local/path/to/domain.name/htdocs
    RewriteEngine On
    RewriteRule ^/static/ - [L]
    RewriteRule ^/(.*)$ /index.php?path=$1 [QSA,L]
</VirtualHost>

The DocumentRoot points to the tk_self htdocs-subdirectory, all other directories are not accessible. Links to static files must begin with "/static/" to be served. All other requests are redirected to the index.php file with the URL as path-parameter.

Shared hosting:

If you use a provider with shared hosting, configuration is done in .htaccess files. Some providers may give you an ftp-access one directory up to your webroot directory. Then this webroot-directory may not be named htdocs but you can rename the tk_self htdocs-directory without any side effects. Next create an .htaccess file with the following content in the (renamed) htdocs directory:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^static/ - [L]
RewriteRule ^(.*)$ index.php?path=$1 [QSA,L]

To use the rewrite engine you may have to set the Options +FollowSymLinks flag if it's not already set from your provider in the global configuration. Also remember that in .htaccess-context the search string for the RewriteRules does not start with a slash "/".

If your provider has configured your root directory to be also the webroot directory, then the .htaccess-file should look like this:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^static/(.*)$ htdocs/static/$1 [L]
RewriteRule ^(.*)$ index.php?path=$1 [QSA,L]

Now the index.php file in the root directory is used as entry point.

Please keep in mind that a configuration where the root directory is also the web-root directory is not an ideal configuration. To disallow web-access to directories, put .htaccess files with the content "deny from all" into these directories.

Contact | Impressum | License