2012-06-09 83 views
1

我在我的數據庫有500個條目。在我的後端,我有行動。例如:Symfony 1.4改進學說save()方法

public function executeMyAction(sfWebRequest $request) { 

// Get some data from table 
$templates = Doctrine_Core::getTable('SeoTemplates')->findOneByEntity('training'); 

//Get data from other table(500 items) 
$trainings = Doctrine::getTable('Training')->getTraining(); 

    // Make some operations with data 
    foreach ($trainings as $training) { 

     $training->setSomeValue1('some_data'); 
     $training->setSomeValue2('some_data'); 
     $training->setSomeValue2('some_data'); 

    } 

// Problem part (try to save) 
$trainings->save(); 
} 

save()執行了很長時間。如何解決這個問題呢?可能嗎?

在我的問題的一部分我都知道的錯誤致命錯誤:

回答

3

保存每條記錄超過集合

$templates = Doctrine_Core::getTable('SeoTemplates')->findOneByEntity('training'); 
$trainings = Doctrine::getTable('Training')->getTraining(); 
foreach ($trainings as $training) { 
    $training->setSomeValue1('some_data'); 
    $training->setSomeValue2('some_data'); 
    $training->setSomeValue2('some_data'); 
    $training->save(); 
} 

或使用Doctrine更新,而不是30秒的最長執行時間使用查詢記錄

$q = Doctrine_Query::create() 
    ->update('TABLE') 
    ->set($val1, '?', $val1) 
    ->set($val2, '?', $val2) 
    ->set($val3, '?', $val3) 
    ->where('id = ?', $id) 
    ->execute(); 
+0

謝謝!第二種方法是快速的:-) – denys281