douqin0676 2012-08-01 12:34
浏览 16
已采纳

控制器使用ATK4导入不同格式的供应商数据

I like to understand conceptually how to setup controller / model in case I want to import supplier data (csv/xml/soap/..) via different controllers. I simplified my case for better focus.

In ATK4 I have Model_Supplier. The main fields are: name,type. Type can be csv1,csv2,csv3,xml1,xml2,soap1. Some suppliers are using the same type.

I like to load the model and do ->import(). However import() should be different for each type.

I thought about following possibilities: [1] load model, setController, hook method to model and then use model->import()

$m=$this->add('Model_Supplier)->load(1);
$m->setController($m['type']);
$m->import();

then in Controller_Csv1 the method import() needs to be added like this via the init():

$this->owner->addMethod('import',array($this,'import'));

[2] load model, setController and do controller->import()

$m=$this->add('Model_Supplier)->load(1);
$c=$m->setController($m['type']);
$c->import();

Then the import() in the controller should refer to $this->owner as the model

[3] Another option would be to extend Model_Supplier with Model_Supplier_Csv1 and then have import() in here. However then I first need to load Model_Supplier to identify the type, then unload and load again Model_Supplier_$type

[4] Or add model, then add controller, then set the model instance to the controller and do controller->import()

$m=$this->add('Model_Supplier)->load(1);
$c=$this->add('Controller_'.$m['type']);
$c->setModel($m);
$c->import();

[5] maybe another solution which I didn't think of.

What would be the best approach also in line with ATK4?

  • 写回答

1条回答 默认 最新

  • download12749 2012-08-02 09:56
    关注

    2.

    This varies depending on many factors in your application, but I think second option is most suitable. The usage would be:

    $model->setController($m['type'])->import();
    

    You can also create a method in your model:

    function import(){
        return $this->setController($m['type'])->import();
    }
    

    then you can simply call $model->import();

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么