views:

259

answers:

2

Hi,

I am following the lessons on component development in the "Learning Joomla! 1.5 Extension Development" book. I've followed the instructions in the chapter exactly, creating a component I call "carousel". I've only created the Admin back-end, and I'm able to view the form for creating a new entry or edit existing one, but cannot save or apply changes. Clicking the "Save", "Apply", and "Cancel" buttons only takes me to the Admin index page, but no changes in the DB. However, if I add entries directly in the DB using SQL I'm able to view a listing of them in the Admin interface correctly.

I am using Joomla 1.5.20, PHP 5.2.3 and MySQL 5.0.41 on Windows XP. You can download a zip file of the "com_carousel" folder (which I have in the "administrator/components" folder) from here. I've also correctly registered the component in the DB, such that I'm able to see it under the "Components" menu in the back-end. Here is the SQL am using to create the table "jos_carousel":

CREATE TABLE `jos_carousel` (
`id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`title` VARCHAR( 255 ) NOT NULL ,
`description` TEXT NOT NULL ,
`published` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0'
) ENGINE = innodb;

Please help.

Rgds, Simon

+1  A: 

Not sure if that is the problem but in your main switch you call saveCarousel with one parameter:

case "apply"://NOT WORKING!
    case "save"://NOT WORKING!
        saveCarousel($option);
        break;

and in the function definition it has two parameters:

function saveCarousel($option, $task)

Try adding the $task variable to the function call inside the switch and let us know if that changed anything...

silvo
He should remove the $task var from the function definition, it is not needed.
Martin
Also in this function - function editCarousel($option) on this line $id = $cid[0]; you should cast to an int to avoid possible sql injection attacks, e.g. $id = (int)$cid[0];
Martin
Removed the $task from the function definition. Still no change: can't update a record or add new record in the DB. Thanks for the tip on sql injection Martin.
Simon
A: 

I took some time debugging your extension and found the reason for the strange behaviour you are experiencing. You do not pass the $option variable to the edit form. Therefore, when the form is submitted Joomla does not now which component should be loaded to deal with the request and that is why it just renders the main admin page.

The simplest way to solve this issue is to manually add 'com_carousel' to the hidden field in the edit form (function editCarousel() in admin.carousel.html.php).

Replace

<input type="hidden" name="option" value="<?php echo $option; ?>" />

With

<input type="hidden" name="option" value="com_carousel" />

If you really want to use the $option variable you need to pass it from the admin.carousel.php file.

There are still some things that are not working (mainly publishing/unpublishing), but that is covered later in the book. Once you are done with Learning Joomla! Extension Development your best bet is to read Mastering Joomla.... I am just about to finish reading it and it has been an invaluable resource for me.

Good luck with all your Joomla! extensions :)

silvo
Thanks a lot Silvo. Your answer sorts out everything, and now the Save, Apply and Cancel buttons work as expected. I just added $option to the arguments for editCarousel() in admin.carousel.html.php and the function call in admin.carousel.php, which is actually how it should have been according to the book. Its amazing how such a simple omission can completely mess up everything. Thanks again, too bad i can't up-vote :-)
Simon