Date in Codeigniter Framework

Asked

Viewed 56 times

0

I’m trying to create a Date field in codeligniter for the user to inform Data, I created a helper file with the date code (actually I used a code that was helpful to another question on this site), but I’m not able to use. I have some questions about the code, 1º After loading the helper in my controller I am loading the method created to format date in a variable in which I call it in the view, I am doing it the right way? 2º when I perform test the date I typed in the form, I give a vardump to test what returns me, and returns NULL. 3º What is the syntax of the native function of the codeigniter _parse_form_attribute, the manual of the codeigniter this out has a few days and I am not able to give continuity to my project.

//HELPER

    if ( ! function_exists('form_common')){
    function form_common($type = 'text', $data = '', $value = '', $extra = '')
    {
        $defaults = array('type' => $type, 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value);

        return "<input "._parse_form_attributes($data, $defaults).$extra." />";
    }
}

    if ( ! function_exists('form_date')){
    function form_date($data = '', $value = '', $extra = '')
    {
        return form_common($type = 'date', $data = '', $value = '', $extra = '');
    }
}

//CONTROLLER REALIZEI TESTE PARA VER O QUE ESTA ME RETORNANDO APÓS DIGITAR A DATA E CLICAR NO BOTÃO, MAS O RESULTADO É NULL

    if(isset($_POST['acao']) && $_POST['acao'] == 'Abrir Agenda >>'){
            $data = $this->input->post('data');
            echo 'A data Informada é '.$data;
            var_dump($data);
        }

//VIEW

    echo form_date('data', 'data');

HOW DO I ADD A NAME TO THIS DATE FIELD AND CALL IT AGAIN TO ASSIGN ITS VALUE TO A VARIABLE.

  • My question is described correctly?

1 answer

2


Note carefully its form_date function, when calling the form_common vc function is assigning values in the variables instead of passing the received values to the function, the correct form would be:

if ( ! function_exists('form_date')){
function form_date($data = '', $value = '', $extra = '')
{
    return form_common('date', $data, $value, $extra);
}
  • Thank you, I’ve found the solution. if ( ! function_exists('form_date')) { Function form_date($data = ', $value = ', $extra = ') { Return form_common($type = 'date', $data = 'data', $value = ', $extra = '); } }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.