SourceForge.jp

Config file

  Some function for config is called before function 'action' is called by framework. You set up database, Model, session etc by these functions. Default movement is occur if you don't define functions.

Deine functions

  It's recommended to define all config function in config.php. You can require it in each php file. Require config.php before require cheetan.php. Define config function like as follows if you want change function in specific page.

config.php
if( !function_exists( "config_function" ) )
{
    function config_function()
    {
        return true;
    }
}
onepage.php
<?php
function config_function()
{
    return false;
}
    require_once( "config.php" );
    require_once( "cheetan.php" );

Config function

  • function is_session()

  Specify if you use session. Return false if you don't want to use session because framework use session in default.

function is_session()
{
    return false;
}




  • function config_controller_class()

  Define when you want to override CController class.

function config_controller_class()
{
    class CMyController extends CController
    {

    }
    return 'CMyController';
}




  • function config_view_class()

  Define when you want to override CView class.

function config_view_class()
{
    class CMyView extends CView
    {

    }
    return 'CMyView';
}




  • function config_database( CDatabase &db )

  Set up database. Call next function to set up database.

function CDatabase::add( string settingname, string host, string user, string password, string dbname)

  'settingname' is name of connection. You can specify it when you call function of Model or database. If you use only one connection, you don't have to specify name.

function config_database( &$db )
{
    $db->add( "", "localhost", "user", "password", "dbname" );
    $db->add( "special", "192.168.0.100", "user", "password", "dbname" );
}




  • function config_models( CController &controller )

  Regist model to controller. Use function as follows.

function CController::AddModel( string filepath [, string name ] )

'filepath' is file path of Model definition. Framework define class like 'user.php' => 'CUser' and refer to table named 'user'.

You can access CUser with array '$m' and $user in Controller in default. You can change variable name by specifying 'name'.

function config_models( &$controller )
{
    $controller->db->query( "SET NAMES ujis" ); //if you need
    $controller->AddModel( dirname(__FILE__) . "/models/user.php" );
}




  • function config_components( CController &controller )

  Regist Components to Controller. Use function as follows

function CController::AddComponent( string filepath [, string cname [, string name ] ] )

Specify cname if you don't want to define default class name( like mail.php => CMail ). Specify name if you don't want to define default name of variable( like mail.php => $c[mail] and $mail )

function config_components( &$controller )
{
    $controller->AddComponent( dirname(__FILE__) . "/components/mail.php" );
    $controller->AddComponent( 'Smarty/Smarty.class.php', 'Smarty', 'smarty' );
    $controller->SetViewExt( '.tpl' );
}




  • function is_secure( CController &controller )
  • function check_secure( CController &controller )

  Set up if framework call function 'check_secure' by function 'is_secure'. Frame work does not call check_secure by default. If you want to make framework called 'check_secure', return true in 'is_secure'.

function is_secure( &$controller )
{
    return true;
}

function check_secure( &$controller )
{
    if( empty( $_SESSION["user"] ) )
    {
        $controller->redirect( "login.php" );
    }
}




  • function config_controller( CController &controller )

  It's function called before action.

function config_controller( &$controller )
{
    $controller->SetTemplateFile( "template.html" );
}




  • function after_action( CController &controller )

  It's function called after action.

function after_action( &$controller )
{
    $view = $controller->GetViewFile();
    $controller->smarty->display( $view );
    exit();
}