[Catalyst] Where is the form field lost?

Charlie Garrison garrison at zeta.org.au
Wed Jan 27 00:51:33 GMT 2010


Good morning,

On 26/01/10 at 7:56 PM +0200, Octavian Rasnita 
<orasnita at gmail.com> wrote:

>>From: "Charlie Garrison" <garrison at zeta.org.au>
>
>>_fs_column_dirs
>>  Returns the sub-directory components for a given file name.
>>Override it to provide a deeper directory tree or change the algorithm.
>
>That's true, but I still don't know how can I store the path to the file.

Don't store it, retrieve it via the file field combined with the 
config (column_info) for the file field; add a method like this:

sub fs_file_path {
     my ($self, $column) = @_;
     my $fh = $self->$column;
     return $fh->relative( 
$self->result_source->column_info($column)->{fs_column_path} )->stringify;
}

And if you only have one file field, then create a second method 
and call it instead (eg, for field named 'image'):

sub image_path  { shift->fs_file_path('image'); }


>If in the file field I store just the file name, I need to create a second
>column just for storing the random path for each file upload field.

Nope, use a method, no need to store the value in the db.

>If I will store the random path and the file name in the same column like
>/e3/e3434ae1b/The original file name.pdf

You don't need to store a random path either; Override the 
_fs_column_dirs & fs_file_name methods to name the file the way 
you want (& store it in the sub-directory you want).

>then each time I would need to create a subroutine that takes this file name
>and gets only the original file name for printing it on the 
>page, but I think this is the most simple way though.

I'm not following that, you would only create the subroutine 
once. If you are writing lots of apps and need to the same 
functionality then either create a base class or role and put 
the sub there.


Charlie

-- 
    Ꮚ Charlie Garrison ♊ <garrison at zeta.org.au>
    〠 PO Box 141, Windsor, NSW 2756, Australia

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
http://www.ietf.org/rfc/rfc1855.txt



More information about the Catalyst mailing list