<?xml version="1.0"?>
<atom:feed xmlns:atom="http://www.w3.org/2005/Atom" xmlns:html="http://www.w3.org/1999/xhtml">
  <atom:id>http://bill.welliver.org/atom/pike/Fins/Internals</atom:id>
  <atom:title type="text">electronic.alchemy :: Internals</atom:title>
  <atom:updated>2026-05-24T16:57:58-04:00</atom:updated>
  <atom:link href="http://bill.welliver.org/atom/pike/Fins/Internals" type="application/atom+xml"></atom:link>
  <atom:link href="http://bill.welliver.org/space/pike/Fins/Internals" type="text/html"></atom:link>
  <atom:link href="http://bill.welliver.org/rss/pike/Fins/Internals" type="application/rss+xml"></atom:link>
  <atom:generator uri="http://modules.gotpike.org/blahblah/Public.Syndication.ATOM" version="0.1">Public.Syndication.ATOM (Pike v8.0 release 702)</atom:generator>
  <atom:icon>http://bill.welliver.org/favicon.ico</atom:icon>
  <atom:logo>http://bill.welliver.org/static/images/alchemy.gif</atom:logo>
  <atom:subtitle type="xhtml"><html:div xmlns:html="http://www.w3.org/1999/xhtml"><html:p>Getting started with Fins and&#xD;
The inner workings of a Fins Application.</html:p><html:p class="paragraph"/>
<html:h3 class="heading-1">Prerequisites</html:h3><html:p class="paragraph"/>
Fins runs on Pike 7.8 or higher. Bonjour ready systems &#xD;
(such as MacOS X) will get you automatic announcement of your Fins apps. &#xD;
If you want to use the optional XSLT templating system, you'll need to install libxml, &#xD;
libxslt and the Public.Parser.XML2 module.<html:p class="paragraph"/>
There are some prerequisite modules that you'll need; to avoid having to install them, you should check out the starter bundle at <html:a href="/space/pike/Fins/Windows">Windows</html:a>.<html:p class="paragraph"/>
<html:h3 class="heading-1">Creating a new application</html:h3><html:p class="paragraph"/>
To create a new web application, simply create the following file &#xD;
hierarchy, or use the <html:i class="ital">fins</html:i> tool to create one. You'll probably want to customize all of the files in it, &#xD;
based on your needs.<html:p class="paragraph"/>
<html:div class="code"><html:pre><html:pre>&#xD;
pike -x fins create MyNewApp&#xD;
</html:pre></html:pre></html:div><html:p class="paragraph"/>
&#xD;
Once the app is created, you should edit the config file in <html:i class="ital">MyNewApp/config/dev.cfg</html:i>, to either define a model datasource or comment the entire "model" section out. If you don't do one of these, Fins will bail out because it won't be able to load the model.<html:p class="paragraph"/>
After you have customized the configuration file, you can start up the application by running the following command (the <html:i class="ital">MyNewApp</html:i> directory should be in your current directory):<html:p class="paragraph"/>
<html:div class="code"><html:pre><html:pre>&#xD;
pike -x fins start MyNewApp&#xD;
</html:pre></html:pre></html:div><html:p class="paragraph"/>
&#xD;
<html:i class="ital">or</html:i><html:p class="paragraph"/>
<html:div class="code"><html:pre><html:pre>&#xD;
cd MyNewApp&#xD;
bin/start.sh&#xD;
</html:pre></html:pre></html:div><html:p class="paragraph"/>
<html:h3 class="heading-1">Absolute Bare Minimum</html:h3><html:p class="paragraph"/>
<html:div class="code"><html:pre><html:pre>&#xD;
APPDIR/&#xD;
APPDIR/config&#xD;
APPDIR/config/dev.cfg&#xD;
APPDIR/classes/application.pike&#xD;
APPDIR/classes/controller.pike &#xD;
</html:pre></html:pre></html:div><html:p class="paragraph"/>
&#xD;
(technically, the last file is optional, however the app won't really do much without it).<html:p class="paragraph"/>
<html:h3 class="heading-1">Optional bare-minimum components</html:h3><html:p class="paragraph"/>
<html:div class="code"><html:pre><html:pre>&#xD;
APPDIR/classes/view.pike&#xD;
APPDIR/classes/model.pike&#xD;
APPDIR/templates/*&#xD;
APPDIR/modules/*&#xD;
</html:pre></html:pre></html:div><html:p class="paragraph"/>
&#xD;
A Fins application is stored with an application directory dedicated &#xD;
specifically to that application. Typically the application directory &#xD;
(which will call APPDIR) is named for the application, though this is not &#xD;
a requirement.<html:p class="paragraph"/>
<html:b class="bold">APPDIR/</html:b><html:p class="paragraph"/>
This is the root of the application, and the full path to this directory &#xD;
is included as application-&gt;config-&gt;app_dir<html:p class="paragraph"/>
<html:b class="bold">APPDIR/config</html:b><html:p class="paragraph"/>
This directory holds any necessary configuration files; at a minimum, a &#xD;
fins application consists of a config file and an application class. The &#xD;
files are named configname.cfg, where configname is the string passed as &#xD;
the configuration name argument to fin_serve. If no configuration name is &#xD;
supplied, it is assumed to be "dev". The format of the configuration file &#xD;
is similar to windows style "ini" files, which is broken into sections, &#xD;
with one or more values in each section.<html:p class="paragraph"/>
Your application may use the configuration file to store its own data &#xD;
using the application-&gt;config object. Fins has a few settings that are &#xD;
required:<html:p class="paragraph"/>
<html:b class="bold">[model]</html:b> 
key-value pairs (if the model section is present, these values are &#xD;
mandatory):<html:p class="paragraph"/>
class: the name of the class that implements Fins.FinsModel and will load &#xD;
all of your custom datatypes. Normally, this is "model".<html:p class="paragraph"/>
datasource: the sql url of the database underlying your model.<html:p class="paragraph"/>
debug: if set to "1", all sql statements generated by the model will be &#xD;
written to stderr.<html:p class="paragraph"/>
<html:b class="bold">[controller]</html:b> 
key-value pairs (all mandatory):<html:p class="paragraph"/>
class: the name of a class that implements Fins.FinsController.<html:p class="paragraph"/>
<html:b class="bold">[view]</html:b> 
key-value pairs (all mandatory):<html:p class="paragraph"/>
class: the name of a class that implements Fins.FinsView.<html:p class="paragraph"/>
reload: if set to "1", all first level templates will be checked for &#xD;
changes on each request, and reloaded if necessary. Currently this does &#xD;
not include files included using include directives.<html:p class="paragraph"/>
&#xD;
<html:b class="bold">APPDIR/classes</html:b><html:p class="paragraph"/>
This directory should contain the pike classes you application requires, &#xD;
such as the application, model, view, and any controllers. Normally model &#xD;
object definitions would be stored in a module within the modules &#xD;
directory. This directory is placed in the Pike program path, so you can &#xD;
do things like (program)"myclass" and have the file myclass.pike compiled &#xD;
into a program.<html:p class="paragraph"/>
<html:b class="bold">APPDIR/modules</html:b><html:p class="paragraph"/>
This directory can be used to store any application specific modules. A &#xD;
good example of classes and modules to place in this directory is model &#xD;
related object types.<html:p class="paragraph"/>
<html:b class="bold">APPDIR/static</html:b><html:p class="paragraph"/>
Files contained within this directory are made automatically available on &#xD;
the path /static/. Additionally, a file "favicon.ico" placed in this &#xD;
directory will be automatically short-circuited from /favicon.ico. Note &#xD;
that content in this directory is not subject to any access restrictions, &#xD;
so sensitive content should be placed under the control of a secured &#xD;
controller. Also, directory listings are not generated from this &#xD;
directory; you must request a file directly.<html:p class="paragraph"/>
<html:b class="bold">APPDIR/templates</html:b><html:p class="paragraph"/>
Templates used by the Fins.Template framework are stored within this &#xD;
directory by default (though custom templates can retrieve their source &#xD;
from any location, in theory).<html:p class="paragraph"/>
<html:h3 class="heading-1">Application startup process</html:h3><html:p class="paragraph"/>
Note that Fins makes use of Pike's object orientation features, so that &#xD;
most application startup and operations behavior can be overridden by &#xD;
implimenting replacement classes. Examples include XMLRPCController and &#xD;
DocController. Every application inherits Fins.Application, and by &#xD;
default, basic application setup is performed so that only a few functions &#xD;
need to be provided.&#xD;
<html:ol>
<html:li>classes and modules are added to the program and module paths, respectively.</html:li>
<html:li>the configuration file is parsed and loaded.</html:li>
<html:li>the file classes/application.pike is compiled and instantiated. the configuration is passed to the constructor. see section 2, Fins.Application initialization.</html:li>
<html:li>any listeners are started up by the respective servicing application (fin_serve, caudium module, etc).</html:li>
</html:ol>1 Fins.Application initialization&#xD;
<html:ol>
<html:li>application-&gt;config is set with the configuration file</html:li>
<html:li>load_cache() is called, which instantiates a copy of the Fins.Cache</html:li>
<html:li>load_model() is called, which instantiates the class specified in the model section of the config file (if it exists). See Fins.FinsModel initialization for details.</html:li>
<html:li>load_view() is called, which instantiates the class specified in the model section of the config file (if it exists). See Fins.FinsView initialization for details.</html:li>
<html:li>load_controller() is called, which instantiates the class specified in the controller section of the config file (if it exists). See Fins.FinsView initialization for details.</html:li>
<html:li>start() is called.</html:li>
</html:ol>1 Fins.FinsModel initialization<html:p class="paragraph"/>
inherits Fins.FinsBase, which provides app, cache, view, config and model &#xD;
as local variables.&#xD;
<html:ol>
<html:li>constructor is called with the application object passed as an argument.</html:li>
<html:li>load_model() is called within the local class.</html:li>
<html:li>an instance of Sql.Sql is created using the SQL datasource url provided in the model section of the config file.</html:li>
<html:li>an instance of Fins.Model.DataModelContext is created</html:li>
<html:li>the repository, cache, app and sql connection are populated in the DataModelContext object</html:li>
<html:li>the DMC is initialize()ed, which configures the model rdbms abstraction code for the particular database personality being used.</html:li>
<html:li>the method register_types() is called, which is something you should populate with repository-&gt;add_object_type() calls, unless you're using auto-model registration, which is described more fully at <html:a href="/space/pike/Fins/Developer/Model">Model</html:a>.</html:li>
</html:ol>1 Fins.FinsView initialization<html:p class="paragraph"/>
inherits Fins.FinsBase, which provides app, cache, view, config and model &#xD;
as local variables.<html:p class="paragraph"/>
default_template, default_data and default_context are all pre-populated &#xD;
with classes from Fins.Template, making Fins.Template.Simple the default &#xD;
template type.&#xD;
<html:ol>
<html:li>constructor is called with the application object passed as an argument.</html:li>
<html:li>load_macros() is called, which registers all functions that start with simple_macro_ as simple template macros.</html:li>
</html:ol>1 Fins.FinsController initialization<html:p class="paragraph"/>
inherits Fins.FinsBase, which provides app, cache, view, config and model &#xD;
as local variables.<html:p class="paragraph"/>
you should add approppriate event handlers and sub controllers as &#xD;
necessary. normally you would place the instantiation code for any &#xD;
sub-controllers within start(), and pass the app object to the &#xD;
constructor. the sub-controllers will be "mounted" in the virtual &#xD;
filesystem at a subdirectory corresponding to the name of the variable &#xD;
that they are assigned to within the controller.&#xD;
<html:ol>
<html:li>constructor is called with the application application object as an argument.</html:li>
<html:li>start() is called in the controller.</html:li>
</html:ol>1 How do my requests get directed?<html:p class="paragraph"/>
<html:b class="bold">Event Methods</html:b><html:p class="paragraph"/>
Any public functions present in your controller will be available as &#xD;
paths on your url; if no path is provided, the index method will be run. The base FinsController class expects event methods that take a Fins.Request object, a Fins.Response object and an argument of type "mixed ..." which will contain any arguments.<html:p class="paragraph"/>
<html:b class="bold">Event Method Example:</html:b><html:p class="paragraph"/>
If you have a method called "boo" in your main controller, it will be &#xD;
available as "/boo". Any additional path past that will be sent as &#xD;
arguments to the method.<html:p class="paragraph"/>
Note that your index function can't receive "arguments", as they could &#xD;
potentially mask other methods.<html:p class="paragraph"/>
&#xD;
<html:b class="bold">Sub-controllers</html:b><html:p class="paragraph"/>
If you have a controller class present within &#xD;
the main controller, it will also be available as a subfolder on your &#xD;
application url.<html:p class="paragraph"/>
<html:b class="bold">Sub-controller Example:</html:b><html:p class="paragraph"/>
For example, if you have a controller class called &#xD;
"gazonk" in your main controller, the sub-controller will be available as &#xD;
"/gazonk/". note that if you just choose "/gazonk", you'll automatically &#xD;
be redirected so that you're at the "index" level of that controller.<html:p class="paragraph"/>
Also, your controller should instantiate any sub-controllers from the start() function within the parent controller. Always pass the app object to the constructor of your controllers.<html:p class="paragraph"/>
<html:h3 class="heading-1">Starting a Fins application</html:h3><html:p class="paragraph"/>
Right now, the only way to run a Fins application is with the built in &#xD;
webserver (not that it's that bad). To start up your application, make sure that <html:i class="ital">Fins/lib</html:i> is in your pike module path and then run the fins start program:<html:p class="paragraph"/>
<html:div class="code"><html:pre><html:pre>&#xD;
pike -x fins start [-p [port]|--hilfe] [appname [config]] &#xD;
</html:pre></html:pre></html:div><html:p class="paragraph"/>
&#xD;
where port is the port number your Fins application should run on, which &#xD;
defaults to port 8080. appname is the name of the app you'd like to run. &#xD;
it defaults to "default". config is the name of a configuration you'd &#xD;
like to use, which is loaded from appname/config/config.cfg. this value &#xD;
defaults to dev, which loads config/dev.cfg. if you have a Bonjour &#xD;
subsystem and Pike 7.7, you'll get automatic bookmarks in your Bonjour &#xD;
aware applications (such as Safari).<html:p class="paragraph"/>
<html:h3 class="heading-1">Interactive Fins</html:h3><html:p class="paragraph"/>
fin_serve also supports an interactive "hilfe" mode. This is just like &#xD;
regular hilfe, only your application is loaded and initialized, so that &#xD;
you can call functions within your application, such as the model, &#xD;
interactively.<html:p class="paragraph"/>
you can access your application through the "application" constant.&#xD;
</html:div></atom:subtitle>
</atom:feed>
