时间:2021-07-01 10:21:17 帮助过:2人阅读
/**
* Class BaseModel
*
* beforeSave()和afterFetch()成对使用,用于读写数据时自动转化数据。
* 例如自动执行serialize unSerialize
*
* save()发生时事件调用顺序是
* initialize,
* onConstruct,
* beforeValidation,
* beforeValidationOnCreate,
* afterValidationOnCreate,
* afterValidation,
* beforeSave,
* beforeCreate,
* afterCreate,
* afterSave,
*
* @package Company\Models\Notification
*/
class BaseModel extends \Phalcon\Mvc\Model
{
/**
* - initialize()在每个请求期间只会调用一次
* - 子类必需调用父类方法
* - 为每个 new 创建的实例执行初始化任务使用onConstruct()
*/
public function initialize()
{
$this->setConnectionService(‘db_notification‘);
//$this->setConnectionService(‘node1‘);
//$this->setConnectionService(‘node2‘);
//
//真实场景可能使用mysqlnd_ms扩展或者haproxy
//仅演示读负载均衡一种思路
//$dbSlave = [‘node1‘, ‘node2‘, ‘node3‘];
//$key = array_rand($dbSlave);
//$db = $dbSlave[$key];
//$this->setReadConnectionService($db);
//
//
//$this->setReadConnectionService(‘dbRead‘);
//$this->setWriteConnectionService(‘dbWrite‘);
}
}
phalcon:数据库分库,读写分离,负载均衡 系统方法执行顺序
标签: