It looks like you're new here. If you want to get involved, click one of these buttons!
class Member_images_model extends Base_module_model
{
public $record_class = 'Member_image';
public $foreign_keys = array('member_id' => 'members_model');
function __construct()
{
parent::__construct('member_images');
}
function list_items($limit = NULL, $offset = NULL, $col = 'id', $order = 'asc')
{
$this->db->join('members', 'members.id = member_images.member_id', 'left');
$this->db->select('member_images.id, members.title AS member, image', FALSE);
$data = parent::list_items($limit, $offset, $col, $order);
return $data;
}
// cleanup images to member
function on_after_delete($where)
{
$this->delete_related('member_images', 'member_id', $where);
}
}
class Member_image_model extends Base_module_record {
}
function form_fields($values = array())
{
$fields = parent::form_fields();
$CI =& get_instance();
$CI->load->model('categories_model');
$CI->load->model('categories_to_members_model');
$CI->load->model('member_images_model');
$category_options = $CI->categories_model->options_list('id', 'name', array('published' => 'yes'), 'name');
$category_values = (!empty($values['id'])) ? array_keys($CI->categories_to_members_model->find_all_array_assoc('category_id', array('member_id' => $values['id'], 'categories.published' => 'yes'))) : array();
$fields['categories'] = array('label' => 'Categories', 'type' => 'array', 'class' => 'add_edit categories', 'options' => $category_options, 'value' => $category_values, 'mode' => 'multi');
$upload_path = assets_server_path('members/', 'images');
$fields['logo_upload'] = array('type' => 'file', 'upload_path' => $upload_path, 'overwrite' => TRUE);
$fields['image'] = array('type' => 'file', 'upload_path' => $upload_path, 'overwrite' => TRUE);
$fields['add_another_image'] = array('type' => 'button', 'value' => 'Add', 'use_input' => FALSE);
return $fields;
}
function on_after_save($values)
{
$data = (!empty($this->normalized_save_data['categories'])) ? $this->normalized_save_data['categories'] : array();
$this->save_related('categories_to_members_model', array('member_id' => $values['id']), array('category_id' => $data));
$data = (!empty($this->normalized_save_data['image'])) ? $this->normalized_save_data['image'] : array();
$this->save_related('member_images_model', array('member_id' => $values['id']), array('image' => $data));
}
Comments
This process will be quite a bit easier in the upcoming 1.0 release.
I understand that I need to create the field, but how do I make the 'Upload another image' button create another upload image field on the form and save it to the member_images table?
Is it possible?
And I have this code in my members model:
$data = (!empty($this->normalized_save_data['image'])) ? $this->normalized_save_data['image'] : array(); $this->save_related('member_images_model', array('member_id' => $values['id']), array('image' => $data));
Shouldn't this save the image (e.g '01.jpg') in the member_images table?