0

How to get the current id that had been used when editing and viewing a record?

I am currently following the instruction by Alfonso Secas that he posted in this topic..

http://www.grocerycrud.com/forums/topic/1326-how-to-use-grocery-crud-and-image-crud-together/page-2

And now on the part where he said "When editing a record, get the current ID from $this->getStateInfo(); to compose the iframe's source url."

It seems like getStateInfo doesn't exist yet so it shows an error "Fatal error: Call to undefined method Examples::getStateInfo() "

Priya Jayapal
  • 243
  • 3
  • 8
Katherine
  • 573
  • 4
  • 17
  • 43

3 Answers3

0

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

this will do what u want . give it a try

u need to use the CRUD object to call this function instead of $this ..

Shoaib Ahmed
  • 747
  • 12
  • 28
0

You have some options:

Primary key getStateInfo()->get_primary_key

Last uri segment end($this->uri->segments)

Does not work in list action.

uruapanmexicansong
  • 3,068
  • 1
  • 18
  • 22
0

As a workaround you can use one of CodeIgniter's methods to get id from page url https://www.codeigniter.com/userguide3/libraries/uri.html

You need to take last segment from URI

    $segmentsCount = $this->uri->total_segments(); 
    $itemID = intval($this->uri->segment($segmentsCount));

p.s. it is not best solution but it can do the trick

moonvader
  • 19,761
  • 18
  • 67
  • 116