[eluser]Paul T[/eluser]
OK, after spending some time dissecting the code, I came up with a decent solution. I'm not sure how scalable it is, but it gets the job done.
I did this because there may or may not be a join statement, but if there is, this will prevent ambiguity.
In my controller, I added a couple new arrays to the config array. One maps the many-to-many field name from 'display_fields' to the proper SQL syntax. The other array contains whatever joins you will need. For example:
Code:
$config = array(
'db_table' => 'yourTable', //The name of the table associated with this controller
'form_setup' => $this->spyc->YAMLLOAD($this->codexadmin->getDefinitionFileName('yourTable_form')), //The array that holds our elements
'controller_name' => 'yourController', //The name of the controller, so that it can be used when generating the URLs
'primary_key' => 'id', //The name of the controller, so that it can be used when generating the URLs
'display_fields'=>array('yourTableField1','yourTableField2','yourRelatedField1'),
'field_to_lookup'=>array('yourRelatedField1'=>'yourRelatedTable.yourRelatedFieldName'),
'table_joins'=>array('yourJoinTable'=>'whatever = whatever','yourJoinTable2'=>'whatever = whatever'), //for use in $this->db->join()
'rules'=>$rules
);
Then, in the codexcontroller, make sure to declare your table_joins and field_to_lookup variables, and also populate those variables in the setConfig() function.
if(isset($includejoinstatement)) {
foreach($this->table_joins as $field=>$value)
$this->db->join($field,$value);
}
Did I write nice PHP? Nope. Did I put all this modified code in the right places? Probably not. Does it work? So far!
I'm sure many of you will find a much more elegant way to approach this. If you do have a better way, please share it so I can use well formed code, and not my sloppy PHP. :-)