Dmitri,

In answer to your:
What am I doing wrong?

Cast the hash assignment as an array, otherwise it's scalar and you'd get the number of elements in the array instead of the array contents.

@someArray = qw/ 1 2 3 4 /;
%someHash = ();
of the array
##
@{$someHash{key}} = @someArray;
##
use Data::Dumper;
print Dumper(\%someHash);

...nothing wrong with the other solution offerred of using an array ref i.e.
$c->stash->{categoriesToDelete} = [EMAIL PROTECTED];

...although, best if you know what was causing your actual problem.



Message: 6
Date: Sun, 6 May 2007 16:39:23 +0200
From: "Dmitri Pissarenko" <[EMAIL PROTECTED]>
Subject: [Catalyst] FOREACH problem
To: [email protected]
Message-ID:
        <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hello!

I have an action, which should do following:

It reads from the GET parameter a string with record IDs, i. e. "1,2,3,".

Then, this action should fetch from the database the records with these IDs.

Finally, it should pass the resulting array to another page, in which
these records are displayed using

[% FOREACH cat IN categoriesToDelete -%]
  <li>[% cat.name %]</li>
[% END -%]

Now I have the problem that in the page with FOREACH nothing is
displayed, even though categoriesToDelete contains some data.

The code is this:

sub form_deleteSeveralCategories : Local {
    my ($self, $c) = @_;

    # fetch IDs as string
    my $categoryIdsAsSingleString = $c->request->params->{categoryIds};

    # convert string to array of individual IDs
    my @categoryIds = split (/,/,  $categoryIdsAsSingleString);

    # read records from the database and store them in @categoriesToDelete
    my @categoriesToDelete = map
    {
        # $_ is the ID of the record
            $c->model('TimeTrackingAppDB::Category')->find($_);
    } @categoryIds;

    foreach (@categoriesToDelete)
    {
            $c->log->debug('cat: ' . $_);
    };

    # pass the parameters to the page with FOREACH
    $c->stash->{categoryIds} = $categoryIdsAsSingleString;
####
    $c->stash->{categoriesToDelete} = @categoriesToDelete;
####
...
>
> categoriesToDelete is passed to form_deleteSeveralCategories.tt2 very
> well, since "[% categoriesToDelete %]" is displayed as "2" (number of
> elements in the array).
>
> But nothing in displayed in the FOREACH loop.
>
> What am I doing wrong?
>

_________________________________________________________________
Advertisement: Looking for a home loan? Compare 2,000 mortgages at RateCity http://direct.ninemsn.com.au/adclick/CID=02fd7e1a0000000000000000 


_______________________________________________
List: [email protected]
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to