Saturday, July 31, 2010

RE: file uploading. problems with ajax and jquery

Ok for my use I have my upload function i stripped out a lot of code as it's
just going to make it harder to understand so I just left the save then
render part.


function manage_add( $showcase_id = null ) {

//do uploading other stuff what not

$white = array('my', 'allowed', 'fields')
if ($this->Entry->save($this->data, true, $white)) {
$this->set('entry',
$this->Entry->getImageInfo($this->data['Entry']['id'],
$this->Auth->User('id')));//set whatever data you need for the element here
$this->render('/elements/entries/new_image', 'ajax'); //all
we want to render is this little block of code
} else {

//whatever render error element / message /
}
}

new_image.ctp
//so here I just return the newly uploaded image since that's all I need but
you may may not need more that that
<?php echo $html->image('entries/thumb/'.$entry['Entry']['image']); ?>

So on your page if you have a target div say in the js response / success
place that where you want it to go and all you will get is the image.

Hope that helps.

I started with this method then moved onto JSON / AJAX responses as it
allowed more flexibility for me but every situation is different so I hope
it helps.
I'm no pro so you may get better answers

Dave

-----Original Message-----
From: Tomfox Wiranata [mailto:tomfox.wiranata@gmail.com]
Sent: July-31-10 6:44 PM
To: CakePHP
Subject: Re: file uploading. problems with ajax and jquery

ok this is what i did

in my view and specifically in the div, where i want the uploaded
image to appear (told jquery to put it there in onclick), i included
this:

echo $this->element('previewProfileImage');

this ctp.-file is in views/elements/previewProfileImage.ctp

the content of this element is just for testing: (no idea yet how to
tell in the view: echo $html->image('profilepics/small/'.
$user['image_path']);)
echo "bla bla";


it works. but i still get all this other cake crap shown too..like the
sql and everything else...and not just "bla bla"

i'm getting nuts here....what am i doing wrong?

On 31 Jul., 22:45, "Dave Maharaj" <m...@davemaharaj.com> wrote:
> Well for my set up I create an element which simply has the "uploaded
> image". Use jQuery to get the response and tell it what DIV to place the
> content in.
>
> -----Original Message-----
> From: Tomfox Wiranata [mailto:tomfox.wiran...@gmail.com]
> Sent: July-31-10 3:24 PM
> To: CakePHP
> Subject: Re: file uploading. problems with ajax and jquery
>
> dave, thx for the quick reply. i appreciate it.
>
> do you mind going into details a little? you render the div-section?
>
> On 31 Jul., 19:28, "Dave Maharaj" <m...@davemaharaj.com> wrote:
> > Render an element containing the image uploaded.
>
> > -----Original Message-----
> > From: Tomfox Wiranata [mailto:tomfox.wiran...@gmail.com]
> > Sent: July-31-10 2:54 PM
> > To: CakePHP
> > Subject: Re: file uploading. problems with ajax and jquery
>
> > ok i found the problem:
>
> > it has to be
> > <script type="text/javascript" src="../js/ajaxupload.js"></script>
>
> > not
> > <script type="text/javascript" src="js/ajaxupload.js"></script>
>
> > but i get another one:
>
> > i see the "...loading" text for the web 2.0 feeling, BUT:
>
> > a) the image wont be uploaded. so i guess my function in controller is
> > not called. and
> > b) because i have
> >         $this->redirect(array('controller' => 'users', 'action' =>
> > 'editprofile'));
> >     in my called function i get to see the whole site in the div,
> > where the uploaded pic should appear.
>
> > but if i delete the redirect, cake asks for a view. makes sense
> > though. what do i need to change, that the whole site wont be shown in
> > this div?
>
> > thx :)
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp others
> > with their CakePHP related questions.
>
> > You received this message because you are subscribed to the Google
Groups
> > "CakePHP" group.
> > To post to this group, send email to cake-php@googlegroups.com
> > To unsubscribe from this group, send email to
> > cake-php+unsubscribe@googlegroups.com For more options, visit this group
> athttp://groups.google.com/group/cake-php?hl=en
>
> Check out the new CakePHP Questions sitehttp://cakeqs.organd help others
> with their CakePHP related questions.
>
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscribe@googlegroups.com For more options, visit this group
athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others
with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: