⚠ 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

Space in Primary Key Field name causing problem with Update/View



basementjack
  • profile picture
  • Member

Posted 15 July 2012 - 19:15 PM

Hi,

I think I'm having a problem with [b]Field Names with spaces[/b] in them.
The problems appear to show up in two ways:[list]
[*]If the Primary Key field has a space in it's name, then the system will throw an error when editing the any record
[*]If the Field name has a space it is not sortable by that field.
[/list]

CodeIgniter 2.1.2
GroceryCRUD 1.2.3

[b]Baseline[/b] - I followed along with the "newbies grocery CRUD installation guide" and everything works.

[b]Working Changes made[/b] - I added a function/method to the controller from the tutorial (/application/controllers/main.php)
New function:

public function QuarterlyTaxAdjustments(){
$tablename = __FUNCTION__ ;
$this->grocery_crud->set_table($tablename);
$output = $this->grocery_crud->render();
$this->_example_output($output);
}

The above code works

[b]Non Working Changes made[/b]:
New Function:

public function Companies(){
$tablename = __FUNCTION__ ;
$this->grocery_crud->set_table($tablename);
$output = $this->grocery_crud->render();
$this->_example_output($output);
}

As you can see [b]the functions are identical[/b] - The Companies table has a primary key named `Company ID`
I believe this space is the issue - is there any known fix besides renaming the table?

Thanks -

Jack


[i]Also, I haven't tried yet, but I have a few tables that use compound Primary Keys - Does anyone know if those are supported?

Lastly, I see in the grocery_crud_model.php quite a few decision tree's around CI version 2.1.0 and 2.1.1 - I'm on CI 2.1.2 - not sure if that matters, but it's basically being treated as if it were CI 2.0.X in the code.[/i]

[i]- Jack[/i]

fdias
  • profile picture
  • Member

Posted 16 July 2012 - 03:14 AM

Dumb question but are you using the space on the name itself or the display_as function?
I believe you cannot use spaces on field names, that's why you have the display_as function:

Check out the docs:

http://www.grocerycrud.com/documentation/options_functions/display_as

I don't know if I understood your problem correctly. I apologize if I got it wrong.


Cheers.

basementjack
  • profile picture
  • Member

Posted 16 July 2012 - 03:49 AM

fdias - the field names have spaces in them at the mySql level - i.e. it's not just the label, but the actual field name.

In my own code, this hasn't been a problem, but I have had to surround field names with the ` character (not a single quote, I call it a tick, it's on the same key as the tilde ( ~ ))

I'm hoping there's some way to deal with this, but I don't know if the issue is with GroceryCRUD, or if it is at the CodeIgniter level.

- Jack