This class is one of the most important classes in CGIKit. CKApplication has two major roles.

One role is that CKAplication provides parameters which effect the whole behavior of CGIKit application. The other role is that CKApplication communicates with CKAdapter, an interface between a web server and CGIKit.

When CGIKit receives a request from a client, CKApplication arranges its parameters and creates a CKAdapter object. Next, CKApplication gets a request object from the CKAdapter object. In reponse to the request object, CKApplication creates a response object and sends it to the CKAdapter object.

Application Process

1. Ready a request and response object

First, CKApplication creates a CKAdapter object and gets a request ( CKRequest ) object from it. Then, CKApplication creates a response ( CKResponse ) object.

2. Event loop

Next, CKApplication goes into event loop. In this loop, CKApplication creates components depending on the request and invokes the specified method of the components until it returns an object whose class is not CKComponent.

3. Return the response object to the CKAdapter object

Finally, CKApplication converts the components created in event loop to HTML and adds the HTML to the CKResponse object created in 1. CKApplication sends the response object to the CKAdapter object. Then, the CKAdapter object displays the response object to a client.

Programming Topics




adapter [RW]
Adapter object.
auth_by_remote_addr [RW]
Enables or disables session authorization by IP addresses.
auth_by_user_agent [RW]
Enables or disables session authorization by browsers.
char_code [RW]
Character code to convert form data used in CKComponent#canvert_char_code. Select these Japanese codes: ‘jis’, ‘sjis’ or ‘euc’. If the value is nil, raw form data is substituted for variables. The default value is nil.

The attribute and method is setted for Japanese character codes by default. If you convert form data to non-Japanese character codes, override the method.

component_path [RW]
The file system path for components. Components are searched under it.
database_manager [RW]
Database manager class saving the session.
document_root [RW]
Document root directory.
element_id [RW]
Element ID ( CKElementID object ).
error [R]
Handled exception.
error_page [RW]
Name of an error page component to show caught errors.
interface [RW]
Interface of adapter. The default value is an interface for CGI.
locale [RW]
Locale of an application in a transaction. If the locale is specified, CGIKit change a template for a component. The name of the template includes the component name and the locale name. Also, the template name is seprated by underscore("_"). For example, if the locale is "ja" and the component name is "MainPage", the template name is "MainPage_ja.html".
log_options [RW]
Hash of logging options.
level:Log level. Select in CKLog::DEBUG, CKLog::INFO, CKLog::WARN, CKLog::ERROR, CKLog::FATAL.
name:Program name.
file:File name to output logs. The attribute has priority over "out".
max_file_size:Max file size to log. Enables if "file" is setted.
main [RW]
Main component. If the element ID isn’t specified, this component is shown. The default value is ‘MainPage’.
manage_session [RW]
Enables or disables automatic session management.
master_locale [RW]
Main locale of an application in a transaction. If the master_locale is equal to the specified locale, the components use templates whose name doesn’t include the locale name. For instance, if the master_locale is "ja", the locale is "ja" and the component name is "MainPage", the template name is "MainPage.html".
path [RW]
The file system path of the application.
request [RW]
HTTP request object ( CKRequest ).
resource_manager [RW]
CKResourceManager object.
resources [RW]
Resource directory. It has files that don’t be send to browser.
response [RW]
HTTP response object ( CKResponse ).
session [W]
Session object. If session don’t exist, creates a new session.
session_cookie_expires [RW]
Expiry date of cookie for session. If you set the value to nil, session cookies will be invalid when closing browser.
session_id [RW]
Session ID.
session_key [RW]
Session key.
session_store [RW]
Session database object ( CKSessionStore ).
store_in_cookie [RW]
Enables or disables the use of cookies for storing session IDs.
store_in_url [RW]
Enables or disables the use of URLs for storing session IDs.
timeout [RW]
Seconds until the session has timed out.
tmpdir [RW]
Temporary directory for CGIKit.
web_server_resources [RW]
Web server resources directory. If "file" attribute of CKImage is set, the element searches an image file from the directory.

Classes and Modules

Class CKApplication::SessionAuthorizationError
Class CKApplication::SessionTimeoutError

Public Class Methods


Returns version of CGIKit.

Public Instance Methods

baseurl( session = false )

The application URL based on SCRIPT_NAME with session ID.

clear_session( session )

Deletes the session.


Creates an adapter object.


Creates a session.

handle_error( error )

Handles every errors and return an error page component.

handle_session_error( error )

Hook method to handle session errors.


Hook method to initialize for convenience.


Returns true if the locale is master locale.


Returns the name of the application without file extension.

page( name )

Creates a specified page component.


Hook method called before generating specified component. When calling the method, objects of request and session are already setted.


Hook method called just before sending the response to browser. When calling the method, a web page converted to HTML code has already setted to the response.

restore_session( session_id )

Returns a restored session objects with the session ID.

run( request = nil, response = nil )

Runs the application. This method calls hook methods "pre_run" and "pre_respond".

save_session( session )

Saves the session, and set a cookie if "store_in_cookie" attribute is setted. If "clear" method of the session is called, the session is deleted.


Returns the session object. If the session isn’t existed, returns a new session.


Returns true if the session is existed.

url( id = nil, query = nil, secure = false, direct = false )

Creates a URL.