Powered by SmartDoc

Startup

The startup of CGIKit is carried out by startup-program as cgi program. The startup-program is different from components. Normally, it is not neccessary to require components directly in startup-program.

The startup-program does three things.

<番号リスト-1->Creates a CKApplication object.

  1. Sets parameters of the CKApplication object.
  2. Calls CKApplication#run.

Creates a CKApplication object

CKApplication is the central class in CGIKit. This class has the parameters, for example, CGI program's path, MainPage and component path. You can create a CKApplication object by calling CKApplication.new simply.

app = CKApplication.new

Sets parameters of the CKApplication object

CKApplication has many attributes. Here, two of them are introduced. The detail is explained in CKApplication's RDoc document.

Parameters of CKApplication objects
Parameter Description
element_id Component name which CGIKit shows.
main Component name which CGIKit shows if target is not set. The default value is "MainPage".

Calls CKApplication#run

Finally, you call CKApplication#run. By this method, CKApplication loads a component and initializes it.

When CKApplication#run is called, CKApplication decides what component is shown. CKApplication has two ways to decide the name of the top-level component to be shown. One way is CKApplication#element_id and another is query data. If CKApplication#element_id is set as CKElementID object in startup-program, CKApplication loads the component whose name is CKApplication#element_id. If CKApplication#element_id is not set, CKApplication tries to decide the component's name from query data. For example, when a client accesses "http://localhost/hello.cgi?element_id=FooBar" CKApplication loads FooBarcomponent. If both of ways fails, CKApplication load the component specified by CKApplication#main.

HelloWorld.cgi

This is one of the simplest startup-program.

#!/usr/local/bin/ruby

require 'cgikit'

app = CKApplication.new
app.run