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] => Array
(
[image] => Array
(
[name] => 7.jpg
[type] => image/jpeg
[tmp_name] => /var/tmp/phpbNJ49Y
[error] => 0
[size] => 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" => "4a5d33b0-97c8-4640-b89c-6ba24adcd75b",
"slug" => "joesmith",
"newImage" => "joesmith_2b7c7c4a3f1.jpg",
"showcase" => "6e87ea500fe",
"entry" => "2b7c7c4a3f1"
)
$loadHelpers = true
$cached = false
$loadedHelpers = array(
"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 = ""
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:bally.zijn@gmail.com]
Sent: August-05-09 2:30 PM
To: cake-php@googlegroups.com
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<dave@widepixels.com> 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:bally.zijn@gmail.com]
> Sent: August-05-09 1:51 PM
> To: cake-php@googlegroups.com
> 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<dave@widepixels.com> 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" => "austinmaharaj",
>> "newImage" => "joesmith_25f31f1f34c.jpg",
>> "showcase" => "6e87ea500fe",
>> "entry" => "25f31f1f34c"
>> )
>>
>> -----Original Message-----
>> From: brian [mailto:bally.zijn@gmail.com]
>> Sent: August-05-09 11:44 AM
>> To: cake-php@googlegroups.com
>> 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<dave@widepixels.com> 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 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:
Post a Comment