0

Friends my registration function in codeigniter have to calculate the amount of parcels that intend to register. And with that insert multiple records in the table with the dates of the installments. So step the number of the number of installments and the starting date of the installments by url . I took a var_dump but not returning anything.

   public function cadastrar($nParcelas = null, $dataPrimeiraParcela = null){ esta_logado();
    $nParcelas = $this->input->post('localidade');
    $dt_parcelas = $this->input->post('datainicial'); $this->form_validation->set_message('is_unique', 'Este %s já está cadastrado no sistema'); $this->form_validation->set_message('matches', 'O campo %s está diferente do campo %s'); $this->form_validation->set_rules('aquiller', 'AQUILLER', 'trim|required|ucwords'); $this->form_validation->set_rules('localidad', 'NUMERO PARCELAS', 'trim|required'); $this->form_validation->set_rules('datainicial', 'FECHA DE ENTRADA', 'trim|required');
    if ($this->form_validation->run()==TRUE):
        if($dataPrimeiraParcela && $nParcelas != null){
            $dataPrimeiraParcela = explode( "/",$this->input->post('datainicial'));
            $dia = $dataPrimeiraParcela[0];
            $mes = $dataPrimeiraParcela[1];
            $ano = $dataPrimeiraParcela[2];
        } else {
            $dia = date("d");
            $mes = date("m");
            $ano = date("Y");
        }
    for($x = 1; $x <= $nParcelas; $x++){
        $dt_parcelas[$x] = date("Y-m-d",strtotime("+".$x." month",mktime(0, 0, 0,$mes,$dia,$ano)));
        }
        var_dump($nParcelas);
    foreach ($dt_parcelas as $vencimento)
        {
            $dados = array(
                'id_aquiler_parcelas' => $this->input->post('aquiler'),
                'venc_parcelas' => $vencimento
            ); $this->sindico->base($dados);
        } endif; set_tema('titulo', 'Cadastro de Parcelas a Pagar'); set_tema('conteudo', load_modulo('parcelas', 'cadastrar')); load_template(); }
6
  • any error , notices Commented Jul 18, 2016 at 20:45
  • Message: Invalid argument supplied for foreach() Filename: controllers/parcelas.php Commented Jul 18, 2016 at 20:51
  • form validation is ok? Commented Jul 18, 2016 at 20:57
  • Yes. From validation is ok. No foreach. Commented Jul 18, 2016 at 21:00
  • ucwords as a validation rule i not found in codeigniter validation rules docs Commented Jul 18, 2016 at 21:03

1 Answer 1

1

use this:

       function cadastrar($nParcelas = NULL, $dataPrimeiraParcela = NULL){ 
          esta_logado();
          $nParcelas = $this->input->post('localidade');
          $dt_parcelas = $this->input->post('datainicial'); 
          $this->form_validation->set_message('is_unique', 'Este %s já está cadastrado no sistema'); 
          $this->form_validation->set_message('matches', 'O campo %s está diferente do campo %s'); 
          $this->form_validation->set_rules('aquiller', 'AQUILLER', 'trim|required|ucwords'); 
          $this->form_validation->set_rules('localidad', 'NUMERO PARCELAS', 'trim|required'); 
          $this->form_validation->set_rules('datainicial', 'FECHA DE ENTRADA', 'trim|required');
         if ($this->form_validation->run()==TRUE):
              if(!empty($dataPrimeiraParcela) && !empty($nParcelas)){
                  $dataPrimeiraParcela = explode( "/",$this->input->post('datainicial'));
                  $dia = $dataPrimeiraParcela[0];
                  $mes = $dataPrimeiraParcela[1];
                  $ano = $dataPrimeiraParcela[2];
              } else {
                  $dia = date("d");
                  $mes = date("m");
                  $ano = date("Y");
             }
        for($x = 1; $x <= $nParcelas; $x++){
            $dt_parcelas[$x] = date("Y-m-d",strtotime("+".$x." month",mktime(0, 0, 0,$mes,$dia,$ano)));
         }
         //var_dump($nParcelas);
         if(!empty($dt_parcelas)) {
              foreach ($dt_parcelas as $vencimento)
              {
                  $dados = array(
                'id_aquiler_parcelas' => $this->input->post('aquiler'),
                'venc_parcelas' => $vencimento
               ); 

         $this->sindico->base($dados);
        }
   }
     endif; set_tema('titulo', 'Cadastro de Parcelas a Pagar'); set_tema('conteudo', load_modulo('parcelas', 'cadastrar')); load_template(); }
Sign up to request clarification or add additional context in comments.

7 Comments

Message: Invalid argument supplied for foreach() Filename: controllers/parcelas.php
what is the result of var_dump($nParcelas)
friend I took $nParcelas . and enter a fixed number . however the error continues. as my goal is to generate plots , I'm using foreach , creating the array data. so my doubt is ? Can I create the array controller?
and what about the output of $dt_parcelas
For what purpose esta_logado();is at the top of method
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.