|
From: Brad P. <br...@ro...> - 2002-09-25 03:11:18
|
Hehe. I agree that it if you can stick to one way of doing something,
that is a Good Thing(tm). I just put the call to setDirectory back into
the code that handles the POST. I don't think it's a big deal to do it
there. Maybe if you had a dozen defaults that you wanted to change it
might be worth doing it somewhere else. I played with a setDefaults
method...seemed like overkill for one thing.
On Tue, 2002-09-24 at 20:42, Nathan Dintenfass wrote:
> I feel like there were good reasons I didn't do that, but the only one
> coming to mind is that you sometimes need to pass arguments to an init()
> method, and they should either be always hidden or never hidden. Though, I
> guess whatever you pass to init() you could just make a different method.
> And perhaps it need not be so absolute.
>
> Hmm.
>
> Ah, now I remember. It's that if you have a parent that calls it's own
> init() in the "constructor" then that will happen before the child has a
> chance to run its constructor, which you don't always want. Or something
> like that ;)
>
> - Nathan
>
>
>
> > -----Original Message-----
> > From: mod...@li...
> > [mailto:mod...@li...]On Behalf Of Brad Pauly
> > Sent: Tuesday, September 24, 2002 7:24 PM
> > To: modus devs
> > Subject: RE: [Modus-devs] file upload
> >
> >
> > I call init() in the "constructor" of the code component, then call
> > setDirectory() there as well. I actually like it there. No need to call
> > it when instantiating. What about having components responsible for
> > calling init()?
> >
> >
> > On Tue, 2002-09-24 at 19:51, Nathan Dintenfass wrote:
> > > Well, that is exactly why having access to the parent init would be so
> > > nice -- I could build a new init() in baseFile that calls the
> > parent init
> > > and then calls the setDefaultDirectory() (sort of like the
> > newID() in the
> > > baseContentObject).
> > >
> > > I see the problem you have, though -- you can't call
> > setDirectory() until
> > > you init. Damn. Well, you could manually init() inside of
> > your object, but
> > > that may be confusing for the end user. This brings up an
> > issue about what
> > > should be set vs. CFPARAM'd during an init. This, I think, was
> > the reason I
> > > did:
> > >
> > > <cfparam name="instance.directory" default="#expandPath("/")#">
> > >
> > > inside of the baseFile.cfc instead of:
> > >
> > > <cfset instance.directory = expandPath("/")>
> > >
> > > Hmm, you may just be stuck using setDirectory() where you have
> > it now. I'm
> > > open to suggestions on this, though.
> > >
> > > - n
> > >
> > >
> > >
> > > > -----Original Message-----
> > > > From: mod...@li...
> > > > [mailto:mod...@li...]On Behalf Of Brad Pauly
> > > > Sent: Tuesday, September 24, 2002 6:05 PM
> > > > To: modus devs
> > > > Subject: RE: [Modus-devs] file upload
> > > >
> > > >
> > > > super() would indeed be nice. Perhaps I am missing something, but to
> > > > call setDirectory() in the "constructor" I need to call init() first.
> > > > Which works just fine, I was just wondering if I could do it
> > another way
> > > > and always call init() as part of instantiating an object.
> > > >
> > > >
> > > > On Tue, 2002-09-24 at 17:45, Nathan Dintenfass wrote:
> > > > > Brad:
> > > > >
> > > > > First, I am psyched to see someone actually trying to use Modus!
> > > > >
> > > > > setDirectory() is probably something that should actually be
> > > > refactored in
> > > > > some way. I think a "defaultFileDirectory" might also be
> > > > appropriate for
> > > > > the config file. But, to your question . . .
> > > > >
> > > > > I am not sure why it's counterintuitive that you would need
> > to set the
> > > > > directory before setting the value. Remember, the
> > > > setFieldValues() calls
> > > > > the setValue() on each field, and for the baseFile the
> > > > setValue() method is
> > > > > what actually deals with the upload of the file. Thus, it needs to
> > > > > understand what directory it is going to use before the
> > value gets set.
> > > > >
> > > > > I wish there was a super() in CFC's, because then the baseFile
> > > > would have
> > > > > it's own init() method that called the init() of the
> > baseField and then
> > > > > added a setDefaultDirectory() method that could be overridden in
> > > > > implementations of a base file. But, I digress.
> > > > >
> > > > > I also would probably put the setDirectory() declaration
> > inside of your
> > > > > "code" component -- in the "constructor". That should work
> > > > nicely (assuming
> > > > > all "code" instances should store their files in the same
> > > > place!) and hide
> > > > > the need to know much about the location on the front.
> > > > >
> > > > > Make sense?
> > > > >
> > > > >
> > > > > > -----Original Message-----
> > > > > > From: mod...@li...
> > > > > > [mailto:mod...@li...]On Behalf
> > Of Brad Pauly
> > > > > > Sent: Tuesday, September 24, 2002 4:28 PM
> > > > > > To: modus devs
> > > > > > Subject: [Modus-devs] file upload
> > > > > >
> > > > > >
> > > > > > Hi all... I was playing around some more and I noticed something
> > > > > > interesting. I have dug into it a little, but thought I would
> > > > post here
> > > > > > and see what came of it.
> > > > > >
> > > > > > I made a code object that uses basefile to upload files.
> > (I have been
> > > > > > recreating some of the things on the bacfug site, hence the
> > > > code object,
> > > > > > in hopes that my exploring will produce some
> > documentation on how to
> > > > > > create a simple site with Modus) The code object has a
> > three fields:
> > > > > > title, file, and description. I wanted to change where
> > the file was
> > > > > > uploaded, so I took advantage of the setDirectory method.
> > Here is the
> > > > > > snippet that does this:
> > > > > >
> > > > > >
> > > > > > // create an initizlie a code object
> > > > > > code =
> > createObject("component","bacfug.contentobjects.code").init();
> > > > > >
> > > > > > // if the form was POSTed process it
> > > > > > if (isDefined("form.fieldnames")) {
> > > > > >
> > > > > > // set the id
> > > > > > // i need to explore this more, but it
> > > > > > // seems to work in place of a isNew field
> > > > > > code.setID(form.id);
> > > > > >
> > > > > > // set the directory to upload to
> > > > > >
> > code.getField("file").setDirectory("#expandPath("/bacfug/code/")#");
> > > > > >
> > > > > > // set the field values based on the form
> > > > > > code.setFieldValues(argumentCollection=form);
> > > > > >
> > > > > > // if there are no errors, commit it to the database
> > > > > > if(NOT code.hasErrors()){
> > > > > >
> > > > > > // send it to the database
> > > > > > code.store();
> > > > > >
> > > > > > // reinitialize
> > > > > > code.init();
> > > > > > }
> > > > > > }
> > > > > >
> > > > > >
> > > > > > This works fine. However, if I call setFieldValues before
> > > > setDirectory,
> > > > > > the file is uploaded into the default directory ("/").
> > This is almost
> > > > > > counterintuitive to me. I thought perhaps the setValue calls in
> > > > > > setFieldValues might overwrite something. Looking into these two
> > > > > > methods, I couldn't find anything that would cause one to
> > > > overwrite the
> > > > > > other. That makes me think that I should be able to call
> > > > these in either
> > > > > > order and get the desired outcome.
> > > > > >
> > > > > > Any thoughs?
> > > > > >
> > > > > > Brad
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > -------------------------------------------------------
> > > > > > This sf.net email is sponsored by:ThinkGeek
> > > > > > Welcome to geek heaven.
> > > > > > http://thinkgeek.com/sf
> > > > > > _______________________________________________
> > > > > > Modus-devs mailing list
> > > > > > Mod...@li...
> > > > > > https://lists.sourceforge.net/lists/listinfo/modus-devs
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > > -------------------------------------------------------
> > > > > This sf.net email is sponsored by:ThinkGeek
> > > > > Welcome to geek heaven.
> > > > > http://thinkgeek.com/sf
> > > > > _______________________________________________
> > > > > Modus-devs mailing list
> > > > > Mod...@li...
> > > > > https://lists.sourceforge.net/lists/listinfo/modus-devs
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > -------------------------------------------------------
> > > > This sf.net email is sponsored by:ThinkGeek
> > > > Welcome to geek heaven.
> > > > http://thinkgeek.com/sf
> > > > _______________________________________________
> > > > Modus-devs mailing list
> > > > Mod...@li...
> > > > https://lists.sourceforge.net/lists/listinfo/modus-devs
> > > >
> > >
> > >
> > >
> > > -------------------------------------------------------
> > > This sf.net email is sponsored by:ThinkGeek
> > > Welcome to geek heaven.
> > > http://thinkgeek.com/sf
> > > _______________________________________________
> > > Modus-devs mailing list
> > > Mod...@li...
> > > https://lists.sourceforge.net/lists/listinfo/modus-devs
> > >
> > >
> >
> >
> >
> >
> >
> > -------------------------------------------------------
> > This sf.net email is sponsored by:ThinkGeek
> > Welcome to geek heaven.
> > http://thinkgeek.com/sf
> > _______________________________________________
> > Modus-devs mailing list
> > Mod...@li...
> > https://lists.sourceforge.net/lists/listinfo/modus-devs
> >
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Modus-devs mailing list
> Mod...@li...
> https://lists.sourceforge.net/lists/listinfo/modus-devs
>
>
|