Joomla component development: Save, apply and cancel toolbar buttons not working
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 A开发者_运维知识库dmin 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
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 :)
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...
精彩评论