Forms catalyst html::formhandler传递表单值
我使用的是Catalyst,我有一个字段:Forms catalyst html::formhandler传递表单值,forms,perl,catalyst,Forms,Perl,Catalyst,我使用的是Catalyst,我有一个字段: has_field 'client_account_id' => ( type => 'Select', options_method => \&options_account_id); 我有3个与外键连接的表: clients client_accounts login ------- --------------- ----- id client_id clie
has_field 'client_account_id' => ( type => 'Select', options_method =>
\&options_account_id);
我有3个与外键连接的表:
clients client_accounts login
------- --------------- -----
id client_id client_account_id
现在,我希望&options\u account\u id
仅为某个客户id使用客户id填写客户id字段。以下是我目前使用的方法:
sub options_account_id {
use my_app;
my $self = shift;
my @client_accounts = my_app->model('DB::ClientAccount')->search({
'client_id' => $client_id},
{
select => [ qw/id domain/ ], ## SELECT
})->all;
my @options;
for(@client_accounts) {
push @options, { value => $_->id, label => $_->domain};
}
return @options;
}
现在它显然不起作用了,因为$client\u id变量不存在。我的问题是,当我创建新表单时,是否有一种方法可以以某种方式传入特定的客户机id?或者有人知道更好的方法吗?谢谢 如果您已经解决了这个问题,请与我们分享您的解决方案好吗?到目前为止,我可以找到这种方法: 将Catalyst上下文传递给表单对象(不过,这应该避免),然后查询上下文以获取传递的表单参数。表单本身将根据客户端id动态设置这些参数 虽然这种方法混合了MVC,但我不喜欢它。所以,如果你确实找到了更好的解决方案,请告诉我
顺便说一句,很高兴看到来自奥斯汀的Catalyst开发人员 在控制器内的表单构造函数中提供客户端id:
my $form = MyApp::Form::MyFormPage->new( client_id => $some_id);
在表单类中添加属性MyApp::form::MyFormPage
:
has 'client_id' => ( is => 'rw' );
在方法中访问此属性:
sub options_account_id {
my $self = shift; # self is client_account_id field so has no client_id method
my $clientid = $self->form->client_id; # access parent to get client id
}
对不起,我从来没有找到办法。但如果你愿意,我会感谢你的帮助;)如果你没看到,现在有答案了,@Pavel。