Issues creating a module

I'm following the tutorial to create a module and I just want to create a module where users can upload images which will be pulled onto a gallery page.

I created the module and it shows up in the left nav, but if I click on it, it doesn't display any of the data from the table. I can click the create button and enter the data and it actually uploads the file and puts the record in the database, but it keeps overwriting the same record in the database.

Why does the data not show up when I click the module, and why does it keep overwriting the 1 record in the table?

GalleryImages_model
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class GalleryImages_model extends Base_module_model { public $required = array('title', 'path'); function __construct() { parent::__construct('gallery_images'); } function list_items($limit = NULL, $offset = NULL, $col = 'id', $order = 'asc') { //$this->db->join('authors', 'authors.id = articles.author_id', 'left'); $this->db->select('id, title, path, published', FALSE); $data = parent::list_items($limit, $offset, $col, $order); return $data; } function form_fields($values = array()) { $fields = parent::form_fields($values); // ******************* ADD CUSOM FORM STUFF HERE ******************* $upload_path = assets_server_path('galleryImages/', 'images'); $fields['path'] = array('type' => 'file', 'upload_path' => $upload_path, 'overwriite' => TRUE); $fields['published']['order'] = 1000; // return $fields; } } class GalleryImage_model extends Base_module_record { public function get_gallery_image() { return '<img src="'.img_path($this->path).'" />'; } }

My_fuel_modules
$config['modules']['gallery'] = array( 'module_name' => 'Gallery Images', 'instructions' => 'Here you can manage the gallery images', 'sanitize_images' => TRUE, 'model_name' => 'galleryImages_model' );

DB Create Table Script
CREATE TABLE `gallery_images` ( `id` int(11) NOT NULL DEFAULT '0', `title` varchar(255) NOT NULL, `path` varchar(255) NOT NULL, `published` enum('yes','no') NOT NULL DEFAULT 'yes', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Comments

  • edited September 2011
    What is the primary key ID value of the saved data?
  • The value of the ID field is 0. The data is showing up now when I click the module. Not sure why it wasn't before. It's still overwriting the existing row in the db.

    Also, when I click the edit link, it takes me to a page that has the main template with a 404 error. It should be taking me to an admin page similar to the create page.
  • edited September 2011
    Try deleting that record and then restart your MySQL server. I've ran into that issue before and am not sure what causes MySQL to do that.
  • I deleted that record and restarted my server and it still does the same thing. Also, when I click the save button, I don't a message that tells me it was saved successfully or anything as it does when you create a page.
  • It seems that I didn't have my ID field set to auto increment and that caused it to keep overwriting the row. Now that I fixed that, I do get the successfully saved message as well.
Sign In or Register to comment.