See if this makes better sense.

The $this->set('newImage', $image_path);
    $this->layout = 'ajax';

Was me just seeing what if anything would happen, I have a view add.ctp with
<?php echo $newImage ;?> but that does nothing.

Entries controller: this function is accessed from the showcases/view to add
a new photo entry to the specific showcase 
function add($showcase_id = null)
      {
          
          if (!empty($this->data)) {
              $this->data['Entry']['id'] = $this->Entry->generate11Key();
              $this->data['Entry']['showcase_id'] = $showcase_id;
              if ($this->Entry->save($this->data)) {
                  $image_path =
$this->Image->upload_image_and_thumbnail($this->data, 'image', '640', '360',
'177', '100', 'entries', $this->Auth->user('slug'),
$this->data['Entry']['id']);
                  if (isset($image_path)) {
                      $this->Entry->saveField('image', $image_path);
                      $this->set('newImage', $image_path);
                      $this->layout = 'ajax';
                  }
                  //$this->Session->setFlash(__('New entry saved!.', true));
                  //$this->redirect(array('controller' => 'showcases',
'action' => 'view', $showcase_id));
              } else {
                  $this->Session->setFlash(__('The Portfolio could not be
saved. Please, try again.', true));
              }
          }
          $this->set('showcase', $showcase_id);
                  $this->set('entry', $this->data['Entry']['id']);
                  
      }

GALLERIES VIEW:
<div class="showcases view">
General code view images...nothing special
</div>

<script type= "text/javascript">/*<![CDATA[*/
$(document).ready(function(){
                                                   
        var button = $('#button1'), interval;
     
        new AjaxUpload(button,{
                action: '/entries/add/<?php echo $showcase['Showcase']['id']
?>', 
                name: 'data[Image][image]',
                autoSubmit: true,
                

                onSubmit : function(file, ext){
                        if (ext && /^(jpg|jpeg)$/.test(ext)){
                
                        button.text('Uploading');
                        } else {
                                
                                // extension is not allowed
                                $('#example1 .text').text('Error: only JPG
or JPEG images are allowed');
                                // cancel upload
                                return false;                           
                        }


                        this.disable();
                        $('.saving').show();    
                },
                
                onComplete: function(file, response){
                        button.text('Upload');
                        alert(response);
                        $('.saving').hide();
                                        $('#example1 .text').text('Upload
Complete');
                                        


                        this.enable();
                        
                        // add file to the list
                        //$('<li></li>').appendTo('#example1
.files').text(file);    
                        
                                        $('<li></li>').appendTo('#example1
.files').html('<img src="/img/entries/thumb/+file" alt="" /><br />');
                                

                }
        });
});/*]]>*/</script>

So when the file is uploaded the onComplete the alert(response); shows this.

<strong>app/controllers/entries_controller.php</strong> (line
<strong>52</strong>)
<pre class="cake-debug">Array
(
    [Image] =&gt; Array
        (
            [image] =&gt; Array
                (
                    [name] =&gt; 7.jpg
                    [type] =&gt; image/jpeg
                    [tmp_name] =&gt; /var/tmp/phpbNJ49Y
                    [error] =&gt; 0
                    [size] =&gt; 42450
                )

        )

)

</pre>

<pre class="cake-debug"><a href="javascript:void(0);"
onclick='document.getElementById("CakeStackTrace1").style.display =
(document.getElementById("CakeStackTrace1").style.display == "none" ? "" :
"none")'><b>Notice</b> (8)</a>: Undefined variable: image_path
[<b>APP/views/entries/add.ctp</b>, line <b>1</b>]
</pre>
<div id="CakeStackTrace1" class="cake-stack-trace" style="display: none;"><a
href="javascript:void(0);"
onclick='document.getElementById("CakeErrorCode1").style.display =
(document.getElementById("CakeErrorCode1").style.display == "none" ? "" :
"none")'>Code</a> | <a href="javascript:void(0);"
onclick='document.getElementById("CakeErrorContext1").style.display =
(document.getElementById("CakeErrorContext1").style.display == "none" ? "" :
"none")'>Context</a><pre id="CakeErrorContext1" class="cake-context"
style="display: none;">$___viewFn       =
"localhost/build/app/views/entries/add.ctp"
$___dataForView =       array(
        "auth" =&gt; "4a5d33b0-97c8-4640-b89c-6ba24adcd75b",
        "slug" =&gt; "joesmith",
        "newImage" =&gt; "joesmith_2b7c7c4a3f1.jpg",
        "showcase" =&gt; "6e87ea500fe",
        "entry" =&gt; "2b7c7c4a3f1"
)
$loadHelpers    =       true
$cached =       false
$loadedHelpers  =       array(
        "Html" =&gt; HtmlHelper
HtmlHelper::$tags = array
HtmlHelper::$base = ""
HtmlHelper::$here = "/entries/add/6e87ea500fe"
HtmlHelper::$params = array
HtmlHelper::$action = "add"
HtmlHelper::$data = array
HtmlHelper::$_crumbs = array
HtmlHelper::$__docTypes = array
HtmlHelper::$helpers = NULL
HtmlHelper::$webroot = "/"
HtmlHelper::$themeWeb = NULL
HtmlHelper::$plugin = NULL
HtmlHelper::$namedArgs = NULL
HtmlHelper::$argSeparator = NULL
HtmlHelper::$validationErrors = NULL
HtmlHelper::$__tainted = NULL
HtmlHelper::$__cleaned = NULL
HtmlHelper::$_log = NULL,
        "Form" =&gt; FormHelper
FormHelper::$helpers = array
FormHelper::$fieldset = array
FormHelper::$__options = array
FormHelper::$fields = array
FormHelper::$requestType = NULL
FormHelper::$base = ""
FormHelper::$webroot = "/"
FormHelper::$themeWeb = NULL
FormHelper::$here = "/entries/add/6e87ea500fe"
FormHelper::$params = array
FormHelper::$action = "add"
FormHelper::$plugin = NULL
FormHelper::$data = array
FormHelper::$namedArgs = NULL
FormHelper::$argSeparator = NULL
FormHelper::$validationErrors = NULL
FormHelper::$tags = array
FormHelper::$__tainted = NULL
FormHelper::$__cleaned = NULL
FormHelper::$_log = NULL
FormHelper::$Html = HtmlHelper object,
        "Javascript" =&gt; JavascriptHelper
JavascriptHelper::$useNative = true
JavascriptHelper::$enabled = true
JavascriptHelper::$safe = false
JavascriptHelper::$tags = array
JavascriptHelper::$_blockOptions = array
JavascriptHelper::$_cachedEvents = array
JavascriptHelper::$_cacheEvents = false
JavascriptHelper::$_cacheToFile = false
JavascriptHelper::$_cacheAll = false
JavascriptHelper::$_rules = array
JavascriptHelper::$__scriptBuffer = NULL
JavascriptHelper::$helpers = NULL
JavascriptHelper::$base = ""
JavascriptHelper::$webroot = "/"
JavascriptHelper::$themeWeb = NULL
JavascriptHelper::$here = "/entries/add/6e87ea500fe"
JavascriptHelper::$params = array
JavascriptHelper::$action = "add"
JavascriptHelper::$plugin = NULL
JavascriptHelper::$data = array
JavascriptHelper::$namedArgs = NULL
JavascriptHelper::$argSeparator = NULL
JavascriptHelper::$validationErrors = NULL
JavascriptHelper::$__tainted = NULL
JavascriptHelper::$__cleaned = NULL
JavascriptHelper::$_log = NULL,
        "Time" =&gt; TimeHelper
TimeHelper::$helpers = NULL
TimeHelper::$base = ""
TimeHelper::$webroot = "/"
TimeHelper::$themeWeb = NULL
TimeHelper::$here = "/entries/add/6e87ea500fe"
TimeHelper::$params = array
TimeHelper::$action = "add"
TimeHelper::$plugin = NULL
TimeHelper::$data = array
TimeHelper::$namedArgs = NULL
TimeHelper::$argSeparator = NULL
TimeHelper::$validationErrors = NULL
TimeHelper::$tags = array
TimeHelper::$__tainted = NULL
TimeHelper::$__cleaned = NULL
TimeHelper::$_log = NULL,
        "Session" =&gt; SessionHelper
SessionHelper::$helpers = NULL
SessionHelper::$__active = true
SessionHelper::$valid = false
SessionHelper::$error = false
SessionHelper::$_userAgent = "3f3cc2ed8b992ccd29f3b994666e680e"
SessionHelper::$path = "/"
SessionHelper::$lastError = NULL
SessionHelper::$security = NULL
SessionHelper::$time = 1249492255
SessionHelper::$sessionTime = false
SessionHelper::$watchKeys = array
SessionHelper::$id = NULL
SessionHelper::$_log = NULL
SessionHelper::$base = ""
SessionHelper::$webroot = "/"
SessionHelper::$here = "/entries/add/6e87ea500fe"
SessionHelper::$params = array
SessionHelper::$action = "add"
SessionHelper::$data = array
SessionHelper::$themeWeb = NULL
SessionHelper::$plugin = NULL,
        "Ajax" =&gt; AjaxHelper
AjaxHelper::$helpers = array
AjaxHelper::$Html = HtmlHelper object
AjaxHelper::$Javascript = JavascriptHelper object
AjaxHelper::$callbacks = array
AjaxHelper::$ajaxOptions = array
AjaxHelper::$dragOptions = array
AjaxHelper::$dropOptions = array
AjaxHelper::$sortOptions = array
AjaxHelper::$sliderOptions = array
AjaxHelper::$editorOptions = array
AjaxHelper::$autoCompleteOptions = array
AjaxHelper::$__ajaxBuffer = array
AjaxHelper::$base = ""
AjaxHelper::$webroot = "/"
AjaxHelper::$themeWeb = NULL
AjaxHelper::$here = "/entries/add/6e87ea500fe"
AjaxHelper::$params = array
AjaxHelper::$action = "add"
AjaxHelper::$plugin = NULL
AjaxHelper::$data = array
AjaxHelper::$namedArgs = NULL
AjaxHelper::$argSeparator = NULL
AjaxHelper::$validationErrors = NULL
AjaxHelper::$tags = array
AjaxHelper::$__tainted = NULL
AjaxHelper::$__cleaned = NULL
AjaxHelper::$_log = NULL
AjaxHelper::$Form = FormHelper object
)
$helper =       "Ajax"
$camelBackedHelper      =       "ajax"
$html   =       HtmlHelper
HtmlHelper::$tags = array
HtmlHelper::$base = ""
HtmlHelper::$here = "/entries/add/6e87ea500fe"
HtmlHelper::$params = array
HtmlHelper::$action = "add"
HtmlHelper::$data = array
HtmlHelper::$_crumbs = array
HtmlHelper::$__docTypes = array
HtmlHelper::$helpers = NULL
HtmlHelper::$webroot = "/"
HtmlHelper::$themeWeb = NULL
HtmlHelper::$plugin = NULL
HtmlHelper::$namedArgs = NULL
HtmlHelper::$argSeparator = NULL
HtmlHelper::$validationErrors = NULL
HtmlHelper::$__tainted = NULL
HtmlHelper::$__cleaned = NULL
HtmlHelper::$_log = NULL
$form   =       FormHelper
FormHelper::$helpers = array
FormHelper::$fieldset = array
FormHelper::$__options = array
FormHelper::$fields = array
FormHelper::$requestType = NULL
FormHelper::$base = ""
FormHelper::$webroot = "/"
FormHelper::$themeWeb = NULL
FormHelper::$here = "/entries/add/6e87ea500fe"
FormHelper::$params = array
FormHelper::$action = "add"
FormHelper::$plugin = NULL
FormHelper::$data = array
FormHelper::$namedArgs = NULL
FormHelper::$argSeparator = NULL
FormHelper::$validationErrors = NULL
FormHelper::$tags = array
FormHelper::$__tainted = NULL
FormHelper::$__cleaned = NULL
FormHelper::$_log = NULL
FormHelper::$Html = HtmlHelper object
$javascript     =       JavascriptHelper
JavascriptHelper::$useNative = true
JavascriptHelper::$enabled = true
JavascriptHelper::$safe = false
JavascriptHelper::$tags = array
JavascriptHelper::$_blockOptions = array
JavascriptHelper::$_cachedEvents = array
JavascriptHelper::$_cacheEvents = false
JavascriptHelper::$_cacheToFile = false
JavascriptHelper::$_cacheAll = false
JavascriptHelper::$_rules = array
JavascriptHelper::$__scriptBuffer = NULL
JavascriptHelper::$helpers = NULL
JavascriptHelper::$base = ""
JavascriptHelper::$webroot = "/"
JavascriptHelper::$themeWeb = NULL
JavascriptHelper::$here = "/entries/add/6e87ea500fe"
JavascriptHelper::$params = array
JavascriptHelper::$action = "add"
JavascriptHelper::$plugin = NULL
JavascriptHelper::$data = array
JavascriptHelper::$namedArgs = NULL
JavascriptHelper::$argSeparator = NULL
JavascriptHelper::$validationErrors = NULL
JavascriptHelper::$__tainted = NULL
JavascriptHelper::$__cleaned = NULL
JavascriptHelper::$_log = NULL
$time   =       TimeHelper
TimeHelper::$helpers = NULL
TimeHelper::$base = ""
TimeHelper::$webroot = "/"
TimeHelper::$themeWeb = NULL
TimeHelper::$here = "/entries/add/6e87ea500fe"
TimeHelper::$params = array
TimeHelper::$action = "add"
TimeHelper::$plugin = NULL
TimeHelper::$data = array
TimeHelper::$namedArgs = NULL
TimeHelper::$argSeparator = NULL
TimeHelper::$validationErrors = NULL
TimeHelper::$tags = array
TimeHelper::$__tainted = NULL
TimeHelper::$__cleaned = NULL
TimeHelper::$_log = NULL
$session        =       SessionHelper
SessionHelper::$helpers = NULL
SessionHelper::$__active = true
SessionHelper::$valid = false
SessionHelper::$error = false
SessionHelper::$_userAgent = "3f3cc2ed8b992ccd29f3b994666e680e"
SessionHelper::$path = "/"
SessionHelper::$lastError = NULL
SessionHelper::$security = NULL
SessionHelper::$time = 1249492255
SessionHelper::$sessionTime = false
SessionHelper::$watchKeys = array
SessionHelper::$id = NULL
SessionHelper::$_log = NULL
SessionHelper::$base = ""
SessionHelper::$webroot = "/"
SessionHelper::$here = "/entries/add/6e87ea500fe"
SessionHelper::$params = array
SessionHelper::$action = "add"
SessionHelper::$data = array
SessionHelper::$themeWeb = NULL
SessionHelper::$plugin = NULL
$ajax   =       AjaxHelper
AjaxHelper::$helpers = array
AjaxHelper::$Html = HtmlHelper object
AjaxHelper::$Javascript = JavascriptHelper object
AjaxHelper::$callbacks = array
AjaxHelper::$ajaxOptions = array
AjaxHelper::$dragOptions = array
AjaxHelper::$dropOptions = array
AjaxHelper::$sortOptions = array
AjaxHelper::$sliderOptions = array
AjaxHelper::$editorOptions = array
AjaxHelper::$autoCompleteOptions = array
AjaxHelper::$__ajaxBuffer = array
AjaxHelper::$base



 

-----Original Message-----
From: brian [mailto:[email protected]] 
Sent: August-05-09 2:30 PM
To: [email protected]
Subject: Re: Pass data to jquery


I'm still not getting it. If there's no view, how is it that javascript
receives that block you posted. And why do you have $this->set('newImage',
$image_path); if there's no view to set it for?

On Wed, Aug 5, 2009 at 12:47 PM, Dave Maharaj ::
WidePixels.com<[email protected]> wrote:
>
> That’s what shows up in the javascript
>
> alert(response);
>
>
> onComplete: function(file, response){
>                        button.text('Upload');
>                        alert(response);
>                        $('.saving').hide();
>                                        $('#example1 
> .text').text('Upload Complete');
>                        // enable upload button
>                        this.enable();
>
>                        // add file to the list
>                        //$('<li></li>').appendTo('#example1
> .files').text(file);
>
>                                        
> $('<li></li>').appendTo('#example1
> .files').html('<img src="/img/entries/thumb/" alt="" /><br />');
>
>
>                }
>
> There is no view file for the returned image, just a button on the 
> page "Upload" which when clicked upens the file browser on users 
> computer...select image upload and when complete the alert response.
>
> Dave
>
> -----Original Message-----
> From: brian [mailto:[email protected]]
> Sent: August-05-09 1:51 PM
> To: [email protected]
> Subject: Re: Pass data to jquery
>
>
> I'm not sure that I understand what that response is. Is that your 
> view file? How are you passing that back to javascript?
>
> On Wed, Aug 5, 2009 at 10:23 AM, Dave Maharaj ::
> WidePixels.com<[email protected]> wrote:
>>
>> Here is the controller function
>>
>> function add($showcase_id = null)
>>      {
>>              if (!empty($this->data)) {
>>              $this->data['Entry']['id'] = 
>> $this->Entry->generate11Key();
>>              $this->data['Entry']['showcase_id'] = $showcase_id;
>>              if ($this->Entry->save($this->data)) {
>>                  $image_path =
>> $this->Image->upload_image_and_thumbnail($this->data, 'image', '640', 
>> '360', '177', '100', 'entries', $this->Auth->user('slug'), 
>> $this->data['Entry']['id']);
>>                  if (isset($image_path)) {
>>                      $this->Entry->saveField('image', $image_path);
>>                      $this->set('newImage', $image_path);
>>                  }
>>                  $this->Session->setFlash(__('New entry saved!.', 
>> true));
>>                  //$this->redirect(array('controller' => 'showcases', 
>> 'action' => 'view', $showcase_id));
>>              } else {
>>                  $this->Session->setFlash(__('Error message. Please, 
>> try again.', true));
>>              }
>>          }
>>          $this->set('showcase', $showcase_id);
>>            $this->set('entry', $this->data['Entry']['id']);
>>
>>      }
>>
>> The response after upload shows this snip where newImage = what I 
>> need to send to the script
>>
>> $___viewFn      =       "/app/views/entries/add.ctp"
>> $___dataForView =       array(
>>        "slug" =&gt; "austinmaharaj",
>>        "newImage" =&gt; "joesmith_25f31f1f34c.jpg",
>>        "showcase" =&gt; "6e87ea500fe",
>>        "entry" =&gt; "25f31f1f34c"
>> )
>>
>> -----Original Message-----
>> From: brian [mailto:[email protected]]
>> Sent: August-05-09 11:44 AM
>> To: [email protected]
>> Subject: Re: Pass data to jquery
>>
>>
>> You haven't shown how/what your controller is sending back to the client.
>> Why does the response contain the SQL query? In any case, just send 
>> the new filename back. Use JSON, for example. Have a look at the
>> json_encode() function.
>>
>> On Wed, Aug 5, 2009 at 9:27 AM, Dave Maharaj ::
>> WidePixels.com<[email protected]> wrote:
>>> I am uloading a file to the server using an ajax upload script. Now 
>>> everything is working fine except I cant figure out how to get the 
>>> name of the file uploaded back to the page after uploading.
>>>
>>> Using Valums ajax upload script
>>>
>>> The file that gets uploaded say 03.jpg gets renamed to 
>>> $user_$unique_id so it turns into myname_12565895.jpg on the server
>>>
>>> I used
>>> alert(response);  in the script after succesful upload and see
>>>
>>> UPDATE `entries` SET `image` = 'joekool_b9b071c1e64.jpg'  WHERE 
>>> `entries`.`id` = 'b9b071c1e64'
>>>
>>> How can I grab the image` = 'joekool_b9b071c1e64.jpg'  and pass it 
>>> back to the script rather than the 03.jpg. After upload it says 
>>> 03.jpg uploaded succesfully but i need the server converted name so 
>>> I can display the image instead of the name.
>>>
>>> Ideas?
>>>
>>> Dave
>>> >
>>>
>>
>>
>>
>> >
>>
>
>
>
> >
>



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

Reply via email to