• 04-09-2022, 23:51:17
    #1
    Kimlik doğrulama veya yönetimden onay bekliyor.
    Merhaba arkadaşlar,

    Aşağıdaki gibi bir kod satırım var.

                $data = [
                    'title' => $this->request->getVar('title'),
                    'cid' => $this->request->getVar('cid'),
                    'openingSpeech' => $this->request->getVar('openingSpeech'),
                    'isPublic' => $this->request->getVar('isPublic'), 
                    'uid' => '1',
                    'reminder' => $this->request->getVar('reminder'),
                    'createdAt' =>  date('Y-m-d H:i:s')
                ];
    Form'dan gelen veri isPublic için On yada boş, on durumunda 1, boş durumunda ise 0 yapmak istiyorum. Yardımcı olur musunuz?
  • 04-09-2022, 23:53:25
    #2
    Trends adlı üyeden alıntı: mesajı görüntüle
    Merhaba arkadaşlar,

    Aşağıdaki gibi bir kod satırım var.

                $data = [
                    'title' => $this->request->getVar('title'),
                    'cid' => $this->request->getVar('cid'),
                    'openingSpeech' => $this->request->getVar('openingSpeech'),
                    'isPublic' => $this->request->getVar('isPublic'),
                    'uid' => '1',
                    'reminder' => $this->request->getVar('reminder'),
                    'createdAt' =>  date('Y-m-d H:i:s')
                ];
    Form'dan gelen veri isPublic için On yada boş, on durumunda 1, boş durumunda ise 0 yapmak istiyorum. Yardımcı olur musunuz?

    if($this->request->getVar('isPublic') == "on"){
      $isPublic = 1;
    }else{
      $isPublic = 0;
    }
    $data = [
        'title' => $this->request->getVar('title'),
        'cid' => $this->request->getVar('cid'),
        'openingSpeech' => $this->request->getVar('openingSpeech'),
        'isPublic' => $isPublic, 
        'uid' => '1',
        'reminder' => $this->request->getVar('reminder'),
        'createdAt' =>  date('Y-m-d H:i:s')
    ];
  • 05-09-2022, 00:05:12
    #3
    Cevabınız için teşekkür ederim kod çalıştı.

    Sociware adlı üyeden alıntı: mesajı görüntüle
    if($this->request->getVar('isPublic') == "on"){
      $isPublic = 1;
    }else{
      $isPublic = 0;
    }
    $data = [
        'title' => $this->request->getVar('title'),
        'cid' => $this->request->getVar('cid'),
        'openingSpeech' => $this->request->getVar('openingSpeech'),
        'isPublic' => $isPublic,
        'uid' => '1',
        'reminder' => $this->request->getVar('reminder'),
        'createdAt' =>  date('Y-m-d H:i:s')
    ];
  • 05-09-2022, 20:24:24
    #4
    Bu da farklı bir kullanım.
    $data = [
        'title' => $this->request->getVar('title'),
        'cid' => $this->request->getVar('cid'),
        'openingSpeech' => $this->request->getVar('openingSpeech'),
        'isPublic' => $isPublic = ($this->request->getVar('isPublic') == "on" ? 1 : 0),
        'uid' => '1',
        'reminder' => $this->request->getVar('reminder'),
        'createdAt' =>  date('Y-m-d H:i:s')
    ];
    Eğer $isPublic değişkenini başka bir yerde kullanmayacaksanız. Atama işlemini kaldırabilirsiniz. Yani şöyle;


    $data = [
        'title' => $this->request->getVar('title'),
        'cid' => $this->request->getVar('cid'),
        'openingSpeech' => $this->request->getVar('openingSpeech'),
        'isPublic' => $this->request->getVar('isPublic') == "on" ? 1 : 0,
        'uid' => '1',
        'reminder' => $this->request->getVar('reminder'),
        'createdAt' =>  date('Y-m-d H:i:s')
    ];