INI view


1Presentation

The INI view is used to send INI files made from PHP data.

By default, this is a simple stream (as for the JSON view) but, optionally, it is possible to specify a file name. The stream in INI format will then be sent to the browser with instructions to treat it as an attachment and offer the user to save it to disk with the file name in question.

2Usage

Here is an example of sending data in INI format:

class ApiController extends \Temma\Web\Controller {
    public function getUsers() {
        // set the data which will be sent
        // in the INI stream
        $this['data'] = [
            'user1' => [
                'name' => 'Alice',
                'age'  => 28,
            ],
            'user2' => [
                'name' => 'Bob',
                'age'  => 54,
            ],
        ];
        // set the file name (optional)
        $this['filename'] = 'userlist.ini';

        // definition of the used view
        $this->_view('\Temma\Views\Ini');
    }
}
  • Lines 5 to 14: The data to be sent in the INI stream are defined by assigning them to the data variable.
  • Line 16: We define the name of the INI file (so that it is treated as an attachment) by assigning it to the filename variable. This parameter is optional.
  • Line 19: We specify that the view to use for the outgoing data is the INI view (and not the usual Smarty view).

Note: The INI view obviously does not need any templates, since it is the PHP data that is directly serialized.

The received data will look like this:

[user1]
"name"="Alice"
"age"=28
[user2]
"name"="Bob"
"age"=5