OK, I'm not clear on what you're trying to do here, but it seems like
if you don't have any data in the ID field, then either you have just
done an insert (in which case you need to get the last inserted ID),
or you're looking at the wrong bit of the data.
For instance, in my logic when I register a User, I do the following:
if ( $this->User->save($this->data) ){
$this->data['User']['user_id'] = $this->User-
>getLastInsertId();
This sets the field 'user_id' (which happens to be my primaryKey) to
the value of the row that was just inserted. For the actions where the
User already exists, I don't have to set the ID, since it is already
there once the data is populated.
On Dec 22, 12:14 pm, Ken <[email protected]> wrote:
> Thanks for the reply. Your assistance is most appreciated.
>
> Yes, I have tried this, and no it doesn't work within the model.
> Presently, in the model, I have tried various iterations of:
>
> function getMemberID() {
> return $this->id;
> // or
> return $this->Model->id;
> // or
> return $this->Modelname->id;
> // or
> return $this->getID();
> // or
> return $this->Modelname->getID();
> // or
> return $this->getLastInsertID();
>
> }
>
> AND
>
> var $getMemberID = $this->id;
> // or
> var $getMemberID = $this->Model->id;
> // or
> var $getMemberID = Modelname->id;
> // or
> var $getMemberID = $this->Model->getID();
> // or
> var $getMemberID = $this->Modelname->getID();
> // anon...
>
> All to no avail. The only remotely successful variation:
>
> function getMemberID() {
> return $this->id;
> }
>
> has returned null. The others, of course, are only going to produce
> errors.
>
> I am able to retrieve other fields from the same Model. Just not the
> ID.
>
> In my controller, I have:
>
> $this->set ( 'memberid', $this->Member->getMemberID() );
>
> to prepare the Model data for the view.
>
> I'm flummoxed. This should be working flawlessly, and I get nothing
> but null on a field I know has the data I'm looking for.
>
> On Dec 19, 5:48 pm, Donkeybob <[email protected]> wrote:
>
> > if your in the model . . .does this work? $this->Modelname->id;
>
> > On Dec 19, 6:35 pm, Ken <[email protected]> wrote:
>
> > > This is the worst kind of noob question, but I'm stumped. I've tried
> > > $this->Modelname->getID();
> > > $this->Modelname->getLastInsertID();
> > > $this->data['Modelname']['id'];
>
> > > a special method from the Wizard Component:
> > > $this->Wizard->read('step.Modelname.id'); //by the way, this method
> > > retrieves data for ANY field BUT id.
>
> > > and no joy. I just want the current Model's record id. What am I
> > > missing?
>
> > > Any insight you may be able to offer will be most welcome. Thanks in
> > > advance.
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---