It looks like you're new here. If you want to get involved, click one of these buttons!
I have a user table (id, first_name, last_name, email)
I have a packages table (id, package_title, package_description)
They have keys in user_packages table (id, user_id, packages_id)
In the Userpackages_model part of the Form View I want the User Select box to have the value of the id and the option label attribute to have the values of last_name, first_name email
the HTML would look like this
<option value=1 label="Smith, John johnsmith@email.com">Smith, John johnsmith@email.com</option>
Is there a way to make 3 columns into one value for the dropdown option?
Comments
You can overwrite your model's
options_list()
method:I tried that and it's pulling from the table the model is pulling in the constructor so I get this error
Unknown column 'user.first_name' in 'field list'
SELECT user_package.id, CONCAT(user.first_name, ' ', user.last_name, ' ', user.email) FROM
user_package
ORDER BYuser
.first_name
ascI have this as my foreign_keys and my constructor
public $foreign_keys = array('user_id' => 'User_model', 'package_id' => 'Packages_model');</p> <pre><code>function __construct() { parent::__construct('user_package');
I've updated my post above to change "user" to "users" which should be the proper table name.
I'm actually using clients table instead of users table. So I want to pull client_id, first name, last_name and email from clients that have signed up through the site.
public function options_list($key = 'id', $val = '', $where = array('id !=0 ', 'active =1'), $order = TRUE, $group = TRUE){<br /> $val = "CONCAT(clients.first_name, ' ', clients.last_name, ' ', clients.email_address)";<br /> $order = 'clients.first_name asc';</p> <pre><code> $data =parent::options_list($key, $val, $where, $order); return $data; }
A Database Error Occurred
Error Number: 1054
Unknown column 'clients.first_name' in 'field list'
SELECT user_package.id, CONCAT(clients.first_name, ' ', clients.last_name, ' ', clients.email_address) FROM
user_package
ORDER BYclients
.first_name
ascFilename: /chroot/home/a7f60686/fatjacksports.com/html/fuel/modules/fuel/core/MY_Model.php
Line Number: 1164
class Userpackages_model extends Base_module_model {</p> <p>public $foreign_keys = array('client_id' => 'Clients_model', 'package_id' => 'Packages_model');</p> <pre><code>function __construct() { parent::__construct('user_package'); $this->load->database(); $this->load->library('session'); $this->load->helper('url'); }
So the question is how do I contact the clients table
I figured it out. I used the
$options = array('a' => 'option A', 'b' => 'option B', 'c' => 'option C');
$fields['select_example'] = array('type' => 'select', 'options' => $options, 'model' => 'people', 'first_option' => 'Select one...'); // will use the options_list method from the people_model
$fields['select_example'] = array('type' => 'select', 'options' => $options, 'model' => array('my_module' => array('people' => 'people_options')), 'first_option' => 'Select one...'); //