0

以下のコードでは、codeigniter コードを使用しました。ユーザー名、パスワード、名、姓、および電子メール アドレスを挿入できますが、現在の日付を挿入することはできません。pls はこの問題を修正するのに役立ちます。

コントローラ:ログイン

function create_member()
    {
        $this->load->library('form_validation');

        // field name, error message, validation rules
        $this->form_validation->set_rules('first_name', 'Name', 'trim|required');
        $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
        $this->form_validation->set_rules('email_address', 'Email Address', 'trim|required|valid_email');
        $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
        $this->form_validation->set_rules('password2', 'Password Confirmation', 'trim|required|matches[password]');


        if($this->form_validation->run() == FALSE)
        {
            $this->load->view('signup_form');
        }

        else
        {           
            $this->load->model('membership_model');

            if($query = $this->membership_model->create_member())
            {
                $data['main_content'] = 'signup_successful';
                $this->load->view('includes/template', $data);
            }
            else
            {
                $this->load->view('signup_form');           
            }
        }

    }

モデル メンバーシップ_モデル

*

function create_member()
    {

        $new_member_insert_data = array(
            'first_name' => $this->input->post('first_name'),
            'last_name' => $this->input->post('last_name'),
            'email_address' => $this->input->post('email_address'),         
            'username' => $this->input->post('username'),
            'date' => $this->input->post('date','curdate()'),
            'password' => md5($this->input->post('password'))                       
        );

        $insert = $this->db->insert('membership', $new_member_insert_data);
        if ($this->db->_error_number() == 1062)
                {
                echo"<script>alert('This value already exists');</script>";
                }
                if ($this->db->_error_number() == "")
                {
                $this->session->set_flashdata('create', 'create');
                }

        return $insert;
    }
4

1 に答える 1

1

これをヘルパーの 1 つに置くことができます:

function curdate() {
    // gets current timestamp
    date_default_timezone_set('Asia/Manila'); // What timezone you want to be the default value for your current date.
    return date('Y-m-d H:i:s');
}

そして、次のように使用します。

'date' => $this->input->post('date',curdate()), // curdate() as a function

この種のものをグローバルに使用したい場合は、これをカスタムヘルパーに配置して自動ロードすることができます。彼のリンクCodeIgniter: Create new helper?を参照してください。

注 :ここでの私の場合、Web サイトのデフォルトのタイムゾーンを定義することを任されました。必要に応じて UTC を使用できます

于 2013-11-11T09:05:06.167 に答える