2016-08-18 58 views
-2

我使用的CakePHP之间..PHP代码插入所有两年选定年份

fromyearToYear领域在我的形式

我想如果我选择fromYear = 2013和ToYear = 2016

然后它在数据库中插入3行像例如低于..

fromyear 
    2013 
    2014 
    2015 
    2016  

     like wise... 

     please help me to get above scenario.. 

我已经尝试下面的代码...但这是从所有行中插入年份...但我想要插入所有年份之间的所有年份。

public function addVin(){ 
     $this->layout = "backend"; 
     if($this->request->is('post')){  
      $this->loadModel('VinStore'); 
      $from = $this->request->data['VinStore']['FromYear']; 
      $to = $this->request->data['VinStore']['ToYear']; 
      if((!empty($from)) && (!empty($to))) { 
       $count = $from - $to; 
       for ($i=0; $i<=$count; $i++) { 
        $this->VinStore->create();     
        $this->VinStore->save($this->request->data); 
       } 
       $this->Session->setFlash("Vin Data has been added"); 
       $this->redirect('/admins/addVin'); 
      }  

     } 

    } 
+0

你必须向我们展示了'$这个 - > VinStore-)>保存(代码;'之前,我们将确保相当明显的错误是什么 – RiggsFolly

+0

,但我把我的完整功能代码那里...我正在cakephp 2.0上工作... –

+0

需要查看您调用的方法(可能不正确)以保存数据$ this-> VinStore-> save($ this-> request-> data) ;' – RiggsFolly

回答

0
public function addVin(){ 
    $this->layout = "backend"; 
    if($this->request->is('post')){  
     $this->loadModel('VinStore');  
      $from = $this->request->data['VinStore']['MDL_YR']; 
      $to = $this->request->data['VinStore']['MDL_YR_To']; 
      $count = $to - $from; 
      for ($i=0; $i<=$count; $i++) { 
       $year = $from++; 
       $this->request->data['VinStore']['MDL_YR'] = $year; 
       $this->VinStore->create();     
       $this->VinStore->save($this->request->data); 
       $to--; 
      } 
      $this->Session->setFlash("Vin Data has been added"); 
      $this->redirect('/admins/addVin'); 



    }