Nefunkční invalidateControl v komponentě
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- echo
- Člen | 134
Zdravím,
menší obstrukce. Při akci na handleDelImage mi při ajaxu firebug vyhodí
error 500 (záznam se smaže, ale presenter nevyhodí výstup). Když to provedu
po staru bez ajaxu, tak vše proběhne v pořádku. Díky za každou radu.
Verze nette: 2 Alpha
Přikládám:
<?php
namespace adminModule;
use \Nette\Environment,
\Nette\Application\AppForm,
\Nette\Forms\SubmitButton,
\Nette\Web\HttpUploadedFile,
\Nette\Image,
\Nette\Web;
class GalleryControl extends \Nette\Application\Control {
public $gallery_id;
public $otherParams = array();
function getImagesModel() {
return new ImagesModel;
}
function render($params) {
$this->gallery_id = $params['gallery_id'];
isset($params['otherParams']) ? $this->otherParams = $params['otherParams'] : $this->otherParams;
$this->template->setFile(__DIR__ . '/gallery.latte');
$this->template->gallery_id = $this->gallery_id;
$this->template->params = array_merge(array('gallery_id' => $this->gallery_id), $this->otherParams);
$this->template->images = $this->ImagesModel->select($this->gallery_id);
$this->template->render();
}
function handleUploadImages() {
if(!empty($_FILES)) {
$upload = new HttpUploadedFile($_FILES['Filedata']);
if($upload->isImage()) {
// Getting general info
$this->gallery_id = $_POST['gallery_id'];
$dest = WWW_DIR.'/goods/';
$name = $upload->getName();
$arr = explode('.', $name);
$ext = end($arr);
$size = $upload->getSize();
$type = $upload->getContentType();
$resize = Image::fromFile($upload->getTemporaryFile());
$resize -> resize(150,100);
$return = $this->ImagesModel->add($this->gallery_id, $dest, $ext, $name, $size, $type);
$resize -> save($dest.$return);
} else {
header('HTTP/1.1 403 Forbidden');die;
}
}
}
function handleSortImages() {
$order = $this->getParam('gallery');
foreach($order as $position => $gallery_image_id) {
$this->ImagesModel->updatePosition($gallery_image_id, $position);
}
}
function handleDelImage() {
$image_id = $this->getParam('image_id');
$this->ImagesModel->del($image_id);
$this->invalidateControl();
}
}
<script>
$(document).ready(function() {
$('#imagesUpload-{!$gallery_id}').uploadify({
'uploader' : '{!$baseUri}/swf/uploadify.swf',
'script' : {link 'UploadImages!'},
'scriptData': {{foreach $params as $param => $value}{$param}:{$value},{/foreach}},
'cancelImg' : '{!$baseUri}/css/uploadify/cancel.png',
'auto' : true,
'multi' : true,
'onComplete' :
function(event, queueID, fileObj, response, data) {
var images = $(response).find("#images-{!$gallery_id}");
$("#images-{!$gallery_id}").html(images);
galleryInit();
}
});
galleryInit();
function galleryInit() {
$('.gallery ul').sortable({
update: function(event, ui) {
var ser = $(this).sortable("serialize");
$.get({link 'sortImages!', 'gallery_id' => $gallery_id} + '&' + ser)
}
});
}
});
</script>
{snippet gallery}
<div class="block">
<div class="gallery" id="images-{!$gallery_id}">
<ul>
{foreach $images as $image}
<li id="gallery-gallery-{$image['gallery_image_id']}">
<img src="{$baseUri}/goods/{$image['gallery_image_path']}" width="100" />
<a class="ajax" href="{link 'DelImage!', 'image_id' => $image['gallery_image_id']}">Delete</a>
</li>
{/foreach}
</ul>
</div>
<!--
<form method="post" action="{link 'UploadImages!'}" ENCTYPE="multipart/form-data">
-->
<input id="imagesUpload-{!$gallery_id}" name="Filedata" type="file" class="clear" />
<!--
<input type="text" name="gallery_id" value="{$gallery_id}" />
<input type="text" name="good_id" value="26" />
<input type="submit" />
</form>
-->
</div>
{/snippet}
Editoval echo (7. 3. 2011 19:45)
- bojovyletoun
- Člen | 667
To může být jakákoli chyba. Vypni Ajax, zapni Laděnku, a uvidíš..
TIP:
místo
function handleDelImage(){$image_id = $this->getParam('image_id');
stačí psát function handleDelImage($image_id){
- echo
- Člen | 134
Projel jsem log a myslím, že se nepředají parametry komponenty ze šablony:
Missing argument 1 for adminModule\GalleryControl::render(), called in E:\xampplite\htdocs\eshop\libs\Nette\Templates\Filters\LatteMacros.php on line 1243 and defined
Když zakomentuji $this->invalidateControl() tak to funguje bez problému. Vrátí se mi ale celá stránka.