⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Problem with set_relation and multiple select



Wathfea

Wathfea
  • profile picture
  • Member

Posted 11 August 2013 - 12:01 PM

Hello everyone!

Maybe I do something wrong, no I'm sure I do something wrong :) and thats why I'm here. 
I would like to make a multiple select box in my crud Add record section which consist data from an other table and I'm not sure how to fill the select box?

What I done yet:

    function torzsadat_karbantartas_management() 
    {
        $crud = new grocery_CRUD();
        $crud->set_subject('Karbantartás törzsadat');
        $crud->set_table('torzsadat_karbantartas');

        $crud->set_relation('torzsadat_apartman_id','kodtar_apartman_type','type');
        $crud->display_as('torzsadat_apartman_id','Apartman típus');

        $crud->set_relation('kodtar_karb_tev_id','kodtar_karbantartasi_tev','type');
        $crud->field_type('kodtar_karb_tev_id', 'multiselect');
        $crud->display_as('kodtar_karb_tev_id','Karbantartási tevékenység');

        $output = $crud->render();
        $this->_main_output($output);   
    }  

And I got this error msg:
 

 


A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: libraries/grocery_crud.php

Line Number: 2157

 

If I remove the field_type line the normal dropdown slect box is working well. 
How could I transform it to a multiselect box?

Best regards, David


davidoster

davidoster
  • profile picture
  • Member

Posted 11 August 2013 - 22:45 PM

Hello and welcome to the forums [member=wathfea].

The function field_type for the multiselect takes 3 arguments.

The 3rd one is an array of values that will show up.

Also, you're not supposed to use at the same time on the same field a set_relation and a field_type. It doesn't make sense!

 

Here is an example of a some code for multiple values using a custom model,

// controller function
		$this->load->model('itemmodel');
		// multiple activities
		$activities = $this->itemmodel->get_activities("activities");
		foreach ($activities->result() as $row)
		{
			$myarray[$row->id] = $row->description;
		}
		$this->grocery_crud->field_type('interest_for','multiselect',$myarray);
// custom model 
<?php
class itemmodel extends CI_Model  {
	
	function __construct()
	{
		parent::__construct();
		$this->load->database();
	}

public function get_activities($table)
	{
		$this->db->select('id, year, description');
		$this->db->order_by('id desc');
		return $this->db->get($table);
	}
}	

Wathfea

Wathfea
  • profile picture
  • Member

Posted 12 August 2013 - 19:10 PM

Hello davidoster!

Thank you for your help now I'm on a good track. One more question. What kind of field type used in this example at the actors section:

 

http://www.grocerycrud.com/demo/film_management/add

 

Where you can drag and drop the field elements?


davidoster

davidoster
  • profile picture
  • Member

Posted 12 August 2013 - 20:25 PM

This is a set_relation_n_n.


Wathfea

Wathfea
  • profile picture
  • Member

Posted 12 August 2013 - 20:30 PM

This is a set_relation_n_n.

Hi!

Ok but I need only a normal relation I just use 2 tables but I would like to use this fancy drag N drop field. like the actors field :) There is no way for that?


davidoster

davidoster
  • profile picture
  • Member

Posted 12 August 2013 - 20:35 PM

No there isn't unless you program it yourself.


Wathfea

Wathfea
  • profile picture
  • Member

Posted 12 August 2013 - 20:55 PM

No there isn't unless you program it yourself.

:) I have just looked after the core code and it's quite interesting. For example there is a function: protected function get_relation_input($field_info,$value) ...
but I can't find anywhere where it is called.... hum. I would like to add an extra variable like $link or something. I'm trying to search back the code but it's huge. :D

So for example If in my controller I use the relation_n like this -> 

$crud->set_relation('kodtar_apartman_type_id','kodtar_apartman_type','type','www.something.com');

I would like to pass this www.something.com to the libary for this function protected function get_relation_input($field_info,$value,$link). But I didn't find yet the good solution for that. :)


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 13 August 2013 - 11:43 AM

Hi Wathfea

 

Well Grocerycrud is an opensource library .. you can alter / modify the same as per your convenience. But you should be aware of what you doing and how to achieve the result on the same.


Wathfea

Wathfea
  • profile picture
  • Member

Posted 13 August 2013 - 18:55 PM

Yeah, thats why I try to figure out how the system works. I'm trying to search back tha functions which call which one. I quite lost yet but trying my best. :) I found the function which one print out the dropdown. And find that which one is calling this function and I added my own code but unfortunately  when I added my own variable the system tries to identify as a where statement, so now I'm going and check the model. And that function you mentioned at the other topic


davidoster

davidoster
  • profile picture
  • Member

Posted 14 August 2013 - 20:54 PM

Good to hear that you're getting somewhere.

Just make sure you know what you change because when an upgrade comes from the core developer and you want to upgrade you might lose your code.

So usually we try to extend instead of having a direct core change.