duanlujiaji10335 2013-08-22 15:19
浏览 16
已采纳

在一些模型中,在Cakephp 1.2中即时更改数据库

I have an application in CakePhp 1.2, where depends on the domain, SOME of the models have to change dinamically the database.

So I need to find an easy way to:

  1. Check the domain.
  2. Set $useDbConfig on SOME models the database required.

This function on database.php change the database depending just on the domain, but not on the model:

public function __construct(){

if (strpos(env('HTTP_HOST'), 'site_one') !== false) {

  // use site_one database config 
  $this->default = $this->site_one;

} elseif (strpos(env('HTTP_HOST'), 'site_two') !== false) {

  // use site_two database config 
  $this->default = $this->site_two; } 

}

How can I change the database depending also on the model?

Thanks in advance.

  • 写回答

2条回答 默认 最新

  • dongya2030 2013-08-22 20:49
    关注

    What if you used your code, but had an additional database config for those models that don't change? This additional database config would not be changed by the function you posted. In those models that you don't want to change, add the line

    var $useDbConfig = 'static'; 
    

    or whatever the name of your database config is that doesn't change. Then those that do change, you leave using the default config.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 MATLAB APP 制作出现问题
  • ¥15 wannier复现图像时berry曲率极值点与高对称点严重偏移
  • ¥15 利用决策森林为什么会出现这样·的问题(关键词-情感分析)
  • ¥15 DispatcherServlet.noHandlerFound No mapping found for HTTP request with URI[/untitled30_war_e
  • ¥15 使用deepspeed训练,发现想要训练的参数没有梯度
  • ¥15 寻找一块做为智能割草机的驱动板(标签-stm32|关键词-m3)
  • ¥15 信息管理系统的查找和排序
  • ¥15 基于STM32,电机驱动模块为L298N,四路运放电磁传感器,三轮智能小车电磁组电磁循迹(两个电机,一个万向轮),怎么用读取的电磁传感器信号表示小车所在的位置
  • ¥15 如何解决y_true和y_predict数据类型不匹配的问题(相关搜索:机器学习)
  • ¥15 PB中矩阵文本型数据的总计问题。