'igrape',
'phpburn' => array(
'database' => 'phpburn'
)
)
Após isso é só usar o model, como?
O seu packages vai ser a estrutura de pasta do seu model
application/models/igrape/ ('igrape' = setado no array do models)
Exemplo de tabela:
CREATE TABLE test (
id_pessoa int(10) NOT NULL AUTO_INCREMENT,
nome varchar(255) NOT NULL,
PRIMARY KEY(id_pessoa)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
Como vamos criar nossa model?
class Test extends PhpBURN_Core {
public $_tablename = 'test';
public $_package = 'igrape';
public function _mapping() {
$this->getMap()->addField('id_pessoa', 'id_pessoa', 'int', 10, array('auto_increment' => true, 'not_null' => true, 'primary' => true));
$this->getMap()->addField('nome', 'nome', 'varchar', 255, array('not_null' => true));
}
}
Pronto agora temos que trabalhar com ele na controller:
class NameController extends AppController {
public $test = array();
function __construct()
{
}
function index()
{
$this->test = new Test();
$this->test->find();
while($this->test->fetch())
{
debug($this->test->toJSON(),"array");
}
$this->layout = 'igrape';
}
function save()
{
$this->test = new Test();
$this->test->nome2 = "Avelino_".rand(100, 200);
$this->test->save();
}
function __destruct()
{
}
}
NameController::index = select no data base;
NameController::save = save ou update no database (O relacionamento para ver se o registro já existe é feito com a PK - FK setada no _mapping da model.
Espero ter solucionado sua duvida.