????> ??????????PHP-Phalcon??????????????????????????Phalcon????Model????е?????????????????Model??????ο?:??????
????1. ?????????
??????Phalcon????У??????DI?????db??????????????????????????????????÷??????£?
????use PhalconDbAdapterPdoMysql as DbAdapter;
????$di->set('db'?? function () {
????return new DbAdapter(array(
????"host"     => "localhost"??
????"username" => "root"??
????"password" => ""??
????"dbname"   => "test"
????));
????});
?????????$di??????'db'???????????????host??username??password??dbname????????????????????????ú?db??????????Phalcon?е?ORM??????
????????????????????????????:
????1.????????????????д?????????????Phalcon?????ini?? php?? json???????????????????????ini??????????????
????[database]
????adapter  = Mysql
????host     = localhost
????username = root
????password =
????dbname   = test
????2.?????????????????????д??DI
????$di->set('db'?? function () use ($config) {
????$config = $config->get('database')->toArray();
????$dbClass = 'PhalconDbAdapterPdo\' . $config['adapter'];
????unset($config['adapter']);
????return new $dbClass($config);
????});
????2. ??????????
??????MySQL?н?????????????????:
????CREATE TABLE `customer` (
????`id` int(11) NOT NULL AUTO_INCREMENT??
????`username` varchar(255) DEFAULT NULL??
????`password` varchar(32) DEFAULT NULL??
????PRIMARY KEY (`id`)
????) ENGINE=InnoDB DEFAULT CHARSET=utf8;
??????????佨???????customer???????????id?????username??password??????Ρ?
????3. ???????
???????????????????????Customer.php????????????????????????PhalconMVCModel?????????????????????μ?????????????????????μ?Customer??:
class Customer extends PhalconMvcModel
{
//??????????????????????????????Σ??????д
/**
*
* @var integer
*/
public $id;
/**
*
* @var string
*/
public $username;
/**
*
* @var string
*/
public $password;
/**
* Returns table name mapped in the model.
*
* @return string
*/
public function getSource()
{
return 'customer';
}
}
?????????????????????????????????е???????????????????????????????????????в???????????????????????????в???????????????????????????????????????????????????setSource????????????????????:
????public function initialize()
????{
????$this->setSource("tablename");
????}
?????????????????????????Web????????У?????????????????(CoC)??????????????????????????????Web??????