/** Lightweight PHP Framework.
From developers to developers. */

App\Model

The model is responsible for the app business logic, following the basics of MVC design pattern.

Folders Structure

Base: app/Model/
Methods: Form(), Prepare(), View(), Header(), Template()

Model Clean Estructure

<?php

/**
* @class  Model
* @file   Model.php
* @brief  Model Docs/App Module.
* @date   2013-12-12 03:26:00
* @license http://opensource.org/licenses/GPL-3.0 GNU Public License
* @company: Tipui Co. Ltda.
* @author: Author Name <info@foo.bar>
* @updated: 2013-12-12 03:26:00
*/

namespace Tipui\App\Model\Docs\App;

class 
Model
{

}

Model Namespace

The namespace base is composed by
Framework name: Tipui\ +
App base folder name: App\ +
App Model folder name: Model\ +
Model folder path: Docs\App +

For example, we have module called Foo wich folder path is Docs\App, so, the full namespace will be Tipui\App\Model\Docs\App

See more about Namespaces.

Model Class name

The class name is simply the model name, class Model(){}


View() method

If wants to display results from this model, is necessary to declare the method View().
See the sumarized sample bellow:
<?php
class Model
{
    public function 
View(){}
}
This is required to enables the template file to output and displays.
For passing values from model to view, see bellow:
<?php
class Model
{
    public function 
View(){
        return array( 
'foo' => 'bar' );
    }
}
In the template file, call as the sample bellow:
<?php
echo $T['foo'];
For details about app templates, go to the page: App/Template


Prepare() method

The business logic stuffs must be writen in this method, just to keep the codes organized in their proper layers.
<?php
class Model
{

    private 
$rs;

    public function 
Prepare()
    {
        
$this->rs 'Foo Bar';
        return 
null;
    }

    public function 
View(){
        return array( 
'rs' => $this->rs );
    }

}


Form() method

Instantiates the Form, parameters rules and request method.
<?php
class Model
{

    private 
$rs;

    public function 
Form()
    {
        
Form::SetElement'field_sample''text' );
    }

    public function 
Prepare()
    {
        
$this->rs 'Foo Bar';
        return 
null;
    }

    public function 
View(){
        return array( 
'rs' => $this->rs );
    }

}


Header() method

Customizes the header output.
Sample bellow, outputs the header HTTP Status 200.

200: General results.
404: Not found pages.
For others status codes, must declare the method Header().
<?php
class Model
{

    public function 
View(){}

    public function 
Header()
    {
        return array( 
'http_status' => 200 );
    }

}


Template() method

Customizes the Template settings.
Bellow, all the customizables parameters.
<?php
class Model
{

    public function 
View(){}

    public function 
Template()
    {
        return array( 
            
'language'     => 'en',
            
'charset'      => 'UTF-8',
            
'content_type' => 'text/html',
            
'dir'          => 'OtherFolder' DIRECTORY_SEPARATOR,
            
'file'         => 'Test.html',
        );
    }

}