public function edit($countryId = null)
 {
     if (!\Cake\Validation\Validation::naturalNumber($countryId)) {
         $this->Flash->error(__('Invalid country ID'));
         return $this->redirect(['action' => 'index']);
     }
     $this->loadModel('Countries');
     $country = $this->Countries->getCountryById($countryId);
     if (!$country) {
         $this->Flash->error(__('Oups. Country with this ID not exist.'));
         return $this->redirect(['action' => 'index']);
     }
     if ($this->request->is(['post', 'put', 'patch'])) {
         if ($this->Countries->updateCountry($country, $this->request->data)) {
             $this->Flash->success(__('Country was updated.'));
             return $this->redirect(['controller' => 'index', 'action' => 'index']);
         } else {
             $this->Flash->error(__('Oups. Country wasn\'t updated.'));
         }
     }
     $this->loadModel('Languages');
     $languages = $this->Languages->getAllLanguagesList();
     $this->set(compact('country', 'languages'));
     $this->render('add');
 }
 /**
  * testNaturalNumber method
  *
  * @return void
  */
 public function testNaturalNumber()
 {
     $this->assertFalse(Validation::naturalNumber('teststring'));
     $this->assertFalse(Validation::naturalNumber('5.4'));
     $this->assertFalse(Validation::naturalNumber(99.004));
     $this->assertFalse(Validation::naturalNumber('0,05'));
     $this->assertFalse(Validation::naturalNumber('-2'));
     $this->assertFalse(Validation::naturalNumber(-2));
     $this->assertFalse(Validation::naturalNumber('0'));
     $this->assertFalse(Validation::naturalNumber('050'));
     $this->assertTrue(Validation::naturalNumber('2'));
     $this->assertTrue(Validation::naturalNumber(49));
     $this->assertTrue(Validation::naturalNumber('0', true));
     $this->assertTrue(Validation::naturalNumber(0, true));
 }
Exemple #3
0
 /**
  * naturalNumber
  * 数値チェック
  * integerなどの上限チェックを同時に行う
  *
  * @access public
  * @author hagiwara
  * @param array $check
  * @param boolean $allowZero
  * @param integer $limit
  * @return boolean
  */
 public static function naturalNumber($check, $allowZero = false, $limit = 2147483647)
 {
     //providersが間違いなく$contextの内容と考えられるので初期値を入力しなおす
     if (is_array($allowZero) && isset($allowZero['providers'])) {
         $allowZero = false;
     }
     if (is_array($limit) && isset($limit['providers'])) {
         $limit = 2147483647;
     }
     //coreのチェックを先に行う
     if (!parent::naturalNumber($check, $allowZero)) {
         return false;
     }
     return abs($check) <= $limit;
 }
 /**
  * dataExist
  * @param Integer $id
  */
 private function dataExist($id)
 {
     //数値などのチェック
     if (!$id || !Validation::naturalNumber($id)) {
         return false;
     }
     $data = $this->_table->find()->where([$this->_table->alias() . '.' . $this->_table->primaryKey() => $id])->first();
     return !empty($data);
 }