0

I feel like I'm going insane. Usually I can figure these things out but this one has be truly stuck. I'm using Cake 2.3.7. I noticed there is a bug in earlier versions of CakePHP.

Hope someone can point out where I'm going wrong. On my site I have Articles that have 3 HABTM associations > Flies, Rivers and Lakes. So:

Article - HABTM - Fly Article - HABTM - River Article - HABTM - Lake

Controller:

...
$flies = $this->Article->Fly->find('list');
$lakes = $this->Article->Lake->find('list');
$rivers = $this->Article->River->find('list');
$this->set(compact('flies', 'lakes', 'rivers'));

View:

echo $this->Form->input('Fly');
echo $this->Form->input('Lake');
echo $this->Form->input('River');

This syntax seems to be exactly as described in the manuals for CakePHP 2.x, and it works on my local test system, but as soon as I upload it to my server, it fails.

Any help with this would be greatly appreciated, and let me know if more information is needed.

  • Also it would help what version of cake is on your local test system and server, if they are the same then your problem is pretty odd. – Royalty Jun 10 '15 at 17:21
  • I have CakePHP on both my test system (MAMP / Mac) and server (Bluehost.com). Could it be the PHP version on the server (5.4)? – Keith Lugthart Jun 11 '15 at 20:43
  • I don't think you have the version of cake right... I don't think 3.2.7 is out yet... can you clarify? – Royalty Jun 15 '15 at 18:51
  • Hey Royalty, thanks and great catch. That's a dyslexic typo... ;) So on both my local machine and on the server I'm running CakePHP 2.3.7. I've also updated above. – Keith Lugthart Jun 15 '15 at 19:20
  • Do you get any errors on your server (bluehost)? Did you ever look in the error logs that cake creates? – Royalty Jun 15 '15 at 19:24
  • I double checked again, all app logs (debug / error) remain clear. I'm still running the app in Dev mode (full logging). On the server I also do not see anything in the log. – Keith Lugthart Jun 15 '15 at 19:34
  • Can you go ahead and retry my answer? Besides this is there anything else misbehaving on server? Are both versions of PHP the same? Is your tmp folder writable? – Royalty Jun 15 '15 at 22:31
  • I want to kick myself!! I figured the issue had to be environmental given it was working on one system. So I want back and carefully looked at both environments. Though I had CakePHP 2.3.7 installed on the server, I also had an old install of 2.3.0, and somehow my app was pointed to it. – Keith Lugthart Jun 16 '15 at 00:23

3 Answers3

0

Why don't you feed the input options? Like so

echo $this->Form->input('Fly',array('options'=>$flies));
echo $this->Form->input('Lake',array('options'=>$lakes));
echo $this->Form->input('River',array('options'=>$rivers));
Royalty
  • 392
  • 2
  • 10
0

For HABTM associations your form fields should be:-

echo $this->Form->input('Fly.Fly');
echo $this->Form->input('Lake.Lake');
echo $this->Form->input('River.River');

Otherwise what you're doing in the controller looks correct.

drmonkeyninja
  • 8,490
  • 4
  • 31
  • 59
0

The server I was uploading to, somehow had a copy of CakePHP 2.3.0 and the app was pointing to it. CakePHP has a known bug that causes this.

Thanks to all who replied.