PHP-Phalcon????е?????????
???????????? ???????[ 2016/5/5 11:43:04 ] ????????PHP ?????
????> ??????????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??????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11