Page 1 of 1

Simple image module

Posted: Sat May 09, 2015 12:44 am
by MikaelSampoerna
Hi everyone,

I try to creating a simple image module. To the point, the only problem is data is not saved/not loaded everytime I visit this module back. Here's my code in controller:

Code: Select all

if (isset($this->request->post['photo_image'])) {
	$photo_images = $this->request->post['photo_image'];
} elseif (isset($this->request->get['photo_image'])) {
	$photo_images = $this->model_module_photo->getProductImages($this->request->get['photo_image']);
	//$photo_images = $this->model_catalog_product->getProductImages($this->request->get['photo_image']);
	//$photo_images = $this->request->get['photo_image'];
} else {
	$photo_images = array();
}

$data['photo_images'] = array();

foreach ($photo_images as $photo_image) {
	if (is_file(DIR_IMAGE . $photo_image['image'])) {
		$image = $photo_image['image'];
		$thumb = $photo_image['image'];
	} else {
		$image = '';
		$thumb = 'no_image.png';
	}

	$data['photo_images'][] = array(
		'image'      => $image,
		'thumb'      => $this->model_tool_image->resize($thumb, 100, 100)
	);
}
I'm not sure about isset($this->request->get['photo_image']) code above. Because I took from product images controller.
Someone can help me figured it out? Thanks

Re: Simple image module

Posted: Sat May 09, 2015 1:25 am
by IP_CAM
No error message, no error log, nothing?
Ernie

Re: Simple image module

Posted: Sat May 09, 2015 10:11 am
by MikaelSampoerna
Nope, everything works without any error. No data returns when I need to edit this.
Previously, I build another module with single type of field, everything was ok.
Do we need kind of ID for multiple data rows/foreach function?
Thanks

Re: Simple image module

Posted: Sun May 17, 2015 1:45 am
by qart
may be the following will help you,

Code: Select all

$this->load->model('extension/module');

if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
	$module_info = $this->model_extension_module->getModule($this->request->get['module_id']);
}

$this->load->model('module/photo');

if (isset($this->request->post['photo_image'])) {
   $photo_images = $this->request->post['photo_image'];
} elseif (!empty($module_info) {
   $photo_images = $this->model_module_photo->getProductImages($module_info['photo_image']);
} else {
   $photo_images = array();
}

.........................