AutoMagic选择框未填充在CakePHP中 [英] AutoMagic select box not populating in CakePHP

查看:84
本文介绍了AutoMagic选择框未填充在CakePHP中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个模型之间的关系设置

I've got the following relationship set-up between two models


  • 故事属于StoryType

  • StoryType hasMany Story

我设置了一个表单,使用以下代码为每个故事选择StoryType: p>

I've set-up a form to select the StoryType for each story using the following code:

echo $this->Form->input('Story.story_type_id', array('tabindex' => 2));

在控制器中使用此代码填充列表

with this code in the controller to populate the list

$this->set('story_types', $this->Story->StoryType->find('list', array ('order' => 'title')));

但它没有填充任何选择框。 find()选项是工作,因为在控制器内进行调试会产生以下结果:

But it's not populating the select box with anything. I know that the find() option is working because doing a debug within the controller produces this:

Array
(
    [1] => First Person
    [3] => Third Person
)


$ b b

奇怪的是,它是完全相同的代码,只是查询其他模型,填充选择列表为用户和类型的东西,它只是故事类型不工作。

The weird thing is that it's exactly the same code, just querying other models, to populate select lists for things like users and genres, it's just the story types that isn't working.

有什么想法吗?干杯。

推荐答案

您不提及您使用的是哪个版本的CakePHP,但请尝试设置 storyTypes 而不是 story_types

You don't mention which version of CakePHP you're using, but try setting storyTypes rather than story_types:

$this->set( 'storyTypes', $this->Story->StoryType->find( 'list', array( 'order' => 'title' ) ) );

较早版本的CakePHP(1.3之前版本)将set变量名称修改为headlessCamelCase,重新使用1.3.x,可能有一点点基础设施滞留。这是一个有点可及,但它很容易测试,看起来似乎可能这可能是你的问题的根源。

Older versions of CakePHP (pre-1.3) modified set variable names to headlessCamelCase and, even if you're using 1.3.x, there may be a little bit of that infrastructure lingering. It's a bit of a reach, but it's easy enough to test and it seems plausible that this could be the root of your problem.

我很想知道你发现了什么。

I'll be curious to see what you find out.

这篇关于AutoMagic选择框未填充在CakePHP中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆