Was your problem solved or do you have the problem still now?
[updated 24/11/2012] Dependent dropdown (library)
Posted 27 February 2013 - 19:40 PM
Posted 27 February 2013 - 19:42 PM
i still have same error:
A PHP Error was encountered
Severity: Notice
Message: Undefined index: property
Filename: libraries/gc_dependent_select.php
Line Number: 103
Posted 27 February 2013 - 19:47 PM
the drop down relation works...i just get above error
Posted 27 February 2013 - 19:51 PM
it's strangely because I have no that property in the 103 line;
this is that line:
$where = array($this->fields[$field_info->name]['relate'] => $this->data[$parent['field']]);
Posted 27 February 2013 - 19:54 PM
Can you send me your controller and dump of the database? I can try test it now
Posted 27 February 2013 - 20:02 PM
I have attached my view, controller and sql dump file. excuse my messy code i am learning. If you goto rooms/units on menu and try to edit a room you will see the error.
thanks again so much victor!
Posted 27 February 2013 - 20:07 PM
And sometimes I have a problem with integrating it with my code :D :D :D :D
I have some plans for creatig some librarires, but I have no time at all :( and I have no time to fix this laibrary too.
I started to learn English and my brain get very much information :) It's very hard for me )))
Posted 27 February 2013 - 20:10 PM
Posted 27 February 2013 - 20:11 PM
Or if you have Skype id you can add me in your contact list
Posted 27 February 2013 - 20:18 PM
i emailed haha it is 6 megs i hope it goes through
Posted 03 March 2013 - 10:15 AM
i still have same error:
A PHP Error was encountered
Severity: Notice
Message: Undefined index: property
Filename: libraries/gc_dependent_select.php
Line Number: 103
This has nothing to do with the library that [member=Victor] has made!!!
This has to do with some array that has not being initialized correctly!
Search it to google, it's a PHP warning and you can get rid of it!
Posted 03 March 2013 - 12:36 PM
It's was a wrong config value
Posted 04 March 2013 - 16:23 PM
Yes thank you Victor for all of your support and help. Victor pointed out that I had the main table wrong. Under:
$config = array( 'main_table' => 'properties',
Should of been:
$config = array( 'main_table' => 'rooms',
Thanks again Victor! This library saved me so much time!
Posted 05 March 2013 - 15:19 PM
Victor,
Help please, doesn't work.
DUMP:
CREATE TABLE dd_country (
country_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
country_title VARCHAR(150) NULL,
PRIMARY KEY(country_id)
);
CREATE TABLE dd_state (
state_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
country_ids INTEGER UNSIGNED NOT NULL,
state_title VARCHAR(150) NULL,
PRIMARY KEY(state_id),
INDEX dd_state_FKIndex1(country_ids)
);
CREATE TABLE dd_city (
city_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
state_ids INTEGER UNSIGNED NOT NULL,
city_title VARCHAR(150) NULL,
PRIMARY KEY(city_id),
INDEX dd_city_FKIndex1(state_ids)
);
CREATE TABLE dd_goods (
goods_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
goods_city INTEGER UNSIGNED NOT NULL,
goods_state INTEGER UNSIGNED NOT NULL,
goods_country INTEGER UNSIGNED NOT NULL,
goods_name VARCHAR(150) NULL,
PRIMARY KEY(goods_id),
INDEX dd_goods_FKIndex1(goods_name),
INDEX dd_goods_FKIndex2(goods_state),
INDEX dd_goods_FKIndex3(goods_city)
);
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Teste extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->database();
$this->load->helper('url');
$this->load->helper('date');
$this->load->library('grocery_CRUD');
$this->load->library('gc_dependent_select');
$this->load->model('controledeacessos_model','',TRUE);
}
function index()
{
$crud = new grocery_CRUD();
$crud->set_table('dd_goods');
$crud->set_relation('goods_country', 'dd_country', 'country_title');
$crud->set_relation('goods_state', 'dd_state', 'state_title');
$crud->set_relation('goods_city', 'dd_city', 'city_title');
$this->load->library('gc_dependent_select');
// settings
$fields = array(
// first field:
'goods_country' => array( // first dropdown name
'table_name' => 'dd_country', // table of country
'title' => 'country_title', // country title
'relate' => null // the first dropdown hasn't a relation
),
// second field
'goods_state' => array( // second dropdown name
'table_name' => 'dd_state', // table of state
'title' => 'state_title', // state title
'id_field' => 'state_id', // table of state: primary key
'relate' => 'country_ids', // table of state:
'data-placeholder' => 'select state' //dropdown's data-placeholder:
),
// third field. same settings
'goods_city' => array(
'table_name' => 'dd_city',
'where' =>"post_code>'167'", // string. It's an optional parameter.
'order_by'=>"state_title DESC", // string. It's an optional parameter.
'title' => 'id: {city_id} / city : {city_title}', // now you can use this format )))
'id_field' => 'city_id',
'relate' => 'state_ids',
'data-placeholder' => 'select city'
)
);
$config = array(
'main_table' => 'dd_goods',
'main_table_primary' => 'goods_id',
"url" => base_url() .'index.php/'. __CLASS__ . '/' . __FUNCTION__ . '/',
'ajax_loader' => base_url() . 'ajax-loader.gif', // path to ajax-loader image. It's an optional parameter
'segment_name' =>'Your_segment_name' // It's an optional parameter. by default "get_items"
);
$categories = new gc_dependent_select($crud, $fields, $config);
// first method:
//$output = $categories->render();
// the second method:
$js = $categories->get_js();
$output = $crud->render();
$output->output.= $js;
$this->_example_output($output);
}
function _example_output($output = null)
{
$this->load->view('our_template.php',$output);
}
}
/* End of file cep.php */
/* Location: ./application/principal/cep.php */
Posted 06 March 2013 - 20:55 PM
Hi Victor, I am currently
compiling a site using both grocery crud and the dependent dropdown library.
I have managed to use the
library to create dependent dropdowns on many of my screens, however I have
another need that I am unsure of the best way to proceed.
I need to populate a first
dropdown list of “types†using standard static details (as these do not exist
in the DB)
Once a selection has been made
from the static first dropdown list of “typesâ€, I then need the second dropdown
to generate based on the selection from the first dropdown (selections from
DB).
Example being:
A user clicks on the first
“type†dropdown and selects “cakesâ€, this would go and query the cakes table
and list all available cakes in the second dropdown.
Or if a user clicks on the first
dropdown and selects “piesâ€, this would go and query a different table “piesâ€
and list all available pies in the second dropdown.
I have searched around and have
not managed to find any documentation on how to achieve this,
I would be grateful if anyone
could link to any documentation, or suggest any code/methods that may work for
this,
Thanks in advance,
Posted 08 March 2013 - 06:26 AM
Hi Victor,
Thank you for the library. Unfortunately I cannot seem to make it work and probably I am missing something. If you can help me to find out that will be great. My controller looks like this :
public function attendance() { $crud = new grocery_CRUD(); $tid = $this->tank_auth->get_user_id(); $crud->set_table('attendance'); $crud->where('attendance.att_tid',$tid); $crud->set_subject("Attendance"); $crud->set_relation('att_cid','classes','{classname}',array('tid' => $tid)); $crud->set_relation('att_schid','class_schedule','{date}-{start_time}',array('tid' => $tid)); $crud->set_relation('att_sid','students','{firstname}-{lastname}',array('tid' => $tid)); $crud->display_as('att_cid','Class'); $crud->display_as('att_schid','Schedule'); $crud->display_as('att_sid','Student'); $this->load->library('gc_dependent_select'); $fields = array( 'att_cid' => array ( 'table_name' => 'classes', 'where' => "tid = $tid", 'title' => 'classname', 'relate'=> 'null', 'data-placeholder' => 'Select Class' ), 'att_schid' => array( 'table_name' => 'class_schedule', 'title' => '{date} {start_time}', 'where' => "tid = $tid", 'id_field' => 'id', 'relate' => 'cid', 'data-placeholder' => 'Select Schedule' ), 'att_sid' => array( 'table_name' => 'students', 'title' => '{first_name} {last_name}', 'where' => "tid = $tid", 'id_field' => 'id', 'relate' => 'cid', 'data-placeholder' => 'Select Student' ) ); $config = array( 'main_table' => 'attendance', 'main_table_primary' => 'id', "url" => base_url() .'index.php/'. __CLASS__ . '/' . __FUNCTION__ . '/' ); $categories = new gc_dependent_select($crud, $fields, $config); $crud->columns('att_cid','att_schid','att_sid','attendance_flag'); $crud->required_fields('att_cid','att_schid','att_sid','attendance_flag'); $crud->add_fields('att_cid','att_schid','att_sid','attendance_flag','att_tid'); $crud->edit_fields('att_cid','att_schid','att_sid','attendance_flag','att_tid'); $crud->field_type('att_tid', 'hidden', $tid); $crud->field_type('attendance_flag','enum',array('absent','present')); // first method: $output = $categories->render(); /* $js = $categories->get_js(); $output = $crud->render(); $output->output.= $js; */ //$output = $crud->render(); //$output = $this->grocery_crud->render(); $this->default_output($output); }
The database consists of three/four simple tables with relations like the attached screenshot.
The problem is that in the add page the dropdowns are disabled. When I view the source I dont see the values populated in the dropdowns from the classes,schedules or students table.
I have tried for many hours but cannot figure out why. if you can help me that will be much appreciated.
Thanks
Kanakdeep
Posted 10 March 2013 - 08:11 AM
Posted 13 March 2013 - 14:41 PM
Posted 15 March 2013 - 21:23 PM
Victor, as I can filter (when I edit or add a record) a selectbox, In your example this (Country, State and City). In my application users come from different countries, these users can add less privileged users, ie users of State, I need, according to the user who logs on to the system to choose the Country selectbox only display the user's Country, to this can not add users from other countries. I think doing a modified copy of your library I can achieve this, you think?. Not if I explain well, my English is terrible.
Posted 15 March 2013 - 21:38 PM
maybe this can help you:
'goods_state' => array( // second dropdown name
'table_name' => 'dd_state', // table of state
'title' => 'state_title', // state title
'where' =>"country_id='".$country_id.""' , where $country_id is users country
'id_field' => 'state_id', // table of state: primary key
'relate' => 'country_ids', // table of state:
'data-placeholder' => 'select state' //dropdown's data-placeholder:
),