开发者

How to add a function to one of array in PHP

I have an array $field.

Note: Someone add codeigniter in the tag, but the question itself is about PHP.

Generally save the content this way.

// SAVE FORM CONTENTS
foreach ($fields_to_show as $key=>$value) {
   $this->CI->preference->set_item($key,$this->CI->input->post($key));
}

And this is the method set_item()

    function set_item($name, $value)
    {
        if (is_null($name)) {
           return false;
        }

        $this->preferenceCache[$name] = $value;

      开发者_运维百科  if (is_array($value)) {
               $value = $this->object_keyword . serialize($value);
        }

        $this->db->where('name', $name);
        return $this->db->update(PREFERENCES, array('value'=>$value)); 
}

Now one of field is password, so I want to encode it.

The method encode_password() works fine(I am using it in a different class), but when I tried the following, it does not encode 'ga_password'

// set ga_password
if ($this->CI->input->post('ga_password') != '') {
   // Load userlib language
   $this->CI->load->module_library('auth','userlib');
   $fields_to_show['ga_password'] =   
       $this->CI->userlib->encode_password($this->CI->input->post('ga_password'));
}

// SAVE FORM CONTENTS
foreach ($fields_to_show as $key=>$value) {
   $this->CI->preference->set_item($key,$this->CI->input->post($key));
}


so you are using a method that returns the password as an input for your encode method.

so, if the encode method uses a pass by reference to encode the input, I imagine you would get an error, if it instead is intended to return an encoded value, then you need to do something more like this:

$encoded_password = $this->CI->userlib->encode_password($this->CI->input->post('ga_password'));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜