Smutty

MVC Framework

ClassSmutty_Data

The Smutty_Data data object handles access to all data passed to the application by the user. You don't ever have to create this object yourself, your action handlers will be passed it as their second parameter. The class defines some useful functions for fetching data in various formats.

int( $name )

This method will fetch a parameter by name as an int. If the parameter does not exist, or is not a valid integer then it will return 0.

class PostController extends Smutty_Controller {

    function indexAction( $id, $data ) {
        $int = $data->int( 'int_field_name' );
        // more code...
    }

}

string( $name )

This method will return the named parameter as a string. If the parameter does not exist then it will return the empty string.

class PostController extends Smutty_Controller {

    function indexAction( $id, $data ) {
        $string = $data->string( 'string_field_name' );
        // more code...
    }

}

GET, POST, etc...

By default, the data object that is passed to your actions will have either GET or POST data depending on the type of request that was made. You can however get access to all the different data easily with the following method (which all return brand new Smutty_Data objects loaded with the correct data).

  • getPostData() - $_POST
  • getGetData() - $_GET
  • getServerData() - $_SERVER

With your new data object you can then interact with it using all the nice methods that Smutty provides! (these methods are actually static so you can call them as Smutty_Data::getPostData() if you like)

function indexAction( $data, &$session ) {
    $server = $data->getServerData();
    echo $server->int( 'SERVER_PORT' );
    echo $server->string( 'SERVER_NAME' );
    // etc...
}

Links: Post a comment

Useful Pages

Links