The Joomla! Forum ™



Forum rules


Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 
Author Message
PostPosted: Sat Jul 11, 2009 10:45 pm 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Fri Feb 17, 2006 6:02 pm
Posts: 97
Location: Chicago Area
I am building my first Joomla component based on Joe Leblanc's Daily Message tutorial component. I have created a configuration page that reads just fine from a one-record database table. I am now trying to save data back to that record, but am having difficulty mapping the task generated by the 'Save' button to the function in my controller.php that does so.

The component needs to save two types of data, each to its own table. One of these is line items that I retrieve/add then save via a form defined in a function in admin.mycomponent.html.php. This I have working properly. The second is the configuration information mentioned above from another function/form that needs to write back to the one-record table mentioned above. My dilemma has to do with capturing and mapping the task that comes out of the save button for each. By default, the "Save" toolbar button generates a task called 'save' that maps to a function called 'save()' in my controller, and that's fine for the first type of transaction. I also have a function in my controller called 'saveConfig()' that needs to store the data from the second type of transaction to my configuration table. I know I can use registerTask in my controller to map this 'save' task over to another function -- but that will map the save tasks from BOTH types of transactions to the second function.

How do I get the configuration form/function and 'Save' button in admin.mycomponent.html.php to pass something over to my controller.php that I can distinguish from the 'save' task generated in the line item type of transaction -- and then map that over to 'saveConfig()'? Do I need to do something with hidden form variables, or what?


Top
 Profile  
 
PostPosted: Sat Jul 11, 2009 11:35 pm 
User avatar
Joomla! Hero
Joomla! Hero

Joined: Thu Jul 24, 2008 12:48 pm
Posts: 2678
Location: Austin, TX
When in doubt, I look to other core components. Are you defining a toolbar class? Try looking at what they are doing in com_content:
.../administrator/components/com_content/toolbar.content.html.php
.../administrator/components/com_content/toolbar.content.php

This article might also help:
http://docs.joomla.org/How_to_create_a_custom_button

Let me know if this doesn't answer it for you.

_________________
Will Mavis - Joomla Developer
http://www.covertapps.com/jam <<< Joomla! on your Android, iPhone, iPad, and iPod Touch
If you think I can help you, PM me a link to your post and I will respond. Please don't hijack another user's thread.


Top
 Profile  
 
PostPosted: Sun Jul 12, 2009 2:54 am 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Fri Feb 17, 2006 6:02 pm
Posts: 97
Location: Chicago Area
Thanks -- creating a custom button linked to my saveConfig function worked like a dream!

Now I've bumped into another problem that has me scratching my head. The code for my function is...

Code:
function saveConfig()
{
    $option = JRequest::getCmd('option');
    $this->setRedirect('index.php?option=' . $option);
    $post = JRequest::get('post');
    $row =& JTable::getInstance('ACGMapConfig', 'Table');
>>> if (!$row->bind($post)) {
        return JError::raiseWarning(500, $row->getError());
    }
    if (!$row->store()) {
        return JError::raiseWarning(500, $row->getError());
    }
    $this->setMessage('Configuration Saved');
}


The line indicate by ">>>" is giving me this error:

Fatal error: Call to a member function bind() on a non-object in /path_to_code/administrator/components/com_acgmap/controller.php on line 149

Any idea what could be causing this? As far as I can see my TableACGMapConfig class definition is OK.


Top
 Profile  
 
PostPosted: Sun Jul 12, 2009 4:10 pm 
User avatar
Joomla! Hero
Joomla! Hero

Joined: Thu Jul 24, 2008 12:48 pm
Posts: 2678
Location: Austin, TX
Does your TableACGMapConfig class inherit from JTable? Something like:
.../libraries/joomla/database/table/content.php
Code:
class JTableContent extends JTable

JTable is the one that defines the bind method:
.../libraries/joomla/database/table.php
Code:
function bind( $from, $ignore=array() )

_________________
Will Mavis - Joomla Developer
http://www.covertapps.com/jam <<< Joomla! on your Android, iPhone, iPad, and iPod Touch
If you think I can help you, PM me a link to your post and I will respond. Please don't hijack another user's thread.


Top
 Profile  
 
PostPosted: Sun Jul 12, 2009 5:19 pm 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Fri Feb 17, 2006 6:02 pm
Posts: 97
Location: Chicago Area
Yes...

Code:
class TableACGMap_Config extends JTable
{
   var $id = null;
    var $googleapikey = null;
    var $mapwidth = null;
    var $mapheight = null;
    var $mapcenterlat = null;
    var $mapcenterlon = null;
    var $showsidebar = null;
    var $showaddress = null;
    var $showtelephone = null;
    var $showwebsite = null;
    var $sidebarwidth = null;
    var $sidebaroffset = null;
    var $mapoffset = null;
    var $maxlevels = null;
    var $level1name = null;
    var $level2name = null;
    var $level3name = null;
    var $level4name = null;
    var $level5name = null;
    var $level6name = null;
    var $level7name = null;
    var $level8name = null;
    var $level9name = null;
    var $level10name = null;
    var $bordercolor = null;
    var $borderwidth = null;
   
   function __construct(&$db)
   {
      parent::__construct( '#__acgmap_config', 'id', $db );
   }
}


Top
 Profile  
 
PostPosted: Sun Jul 12, 2009 8:10 pm 
User avatar
Joomla! Hero
Joomla! Hero

Joined: Thu Jul 24, 2008 12:48 pm
Posts: 2678
Location: Austin, TX
Your class is named TableACGMap_Config, but you are trying to create an instance of ACGMapConfig.

http://api.joomla.org/Joomla-Framework/Table/JTable.html#getInstance

Try this:
Code:
$row =& JTable::getInstance('TableACGMap_Config', 'Table');

_________________
Will Mavis - Joomla Developer
http://www.covertapps.com/jam <<< Joomla! on your Android, iPhone, iPad, and iPod Touch
If you think I can help you, PM me a link to your post and I will respond. Please don't hijack another user's thread.


Top
 Profile  
 
PostPosted: Sun Jul 12, 2009 8:26 pm 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Fri Feb 17, 2006 6:02 pm
Posts: 97
Location: Chicago Area
You caught me between versions. I'd been trying various permutations of the class name and corresponding table definition file (acgmapconfig.php), and to be safe eliminated the underscores altogether. No joy, I'm afraid.

Thanks for sticking with me on this!


Top
 Profile  
 
PostPosted: Sun Jul 12, 2009 9:02 pm 
User avatar
Joomla! Hero
Joomla! Hero

Joined: Thu Jul 24, 2008 12:48 pm
Posts: 2678
Location: Austin, TX
Try adding this code after the line with JTable::getInstance to see if you are getting an object back:
Code:
print "Here is row: ".print_r($row, true);exit;


The exit statement will just make sure you don't get redirected or anything so you can see the output.

_________________
Will Mavis - Joomla Developer
http://www.covertapps.com/jam <<< Joomla! on your Android, iPhone, iPad, and iPod Touch
If you think I can help you, PM me a link to your post and I will respond. Please don't hijack another user's thread.


Top
 Profile  
 
PostPosted: Sun Jul 12, 2009 9:11 pm 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Fri Feb 17, 2006 6:02 pm
Posts: 97
Location: Chicago Area
Evidently I'm not -- all I get back is "Here is row:"


Top
 Profile  
 
PostPosted: Sun Jul 12, 2009 9:28 pm 
User avatar
Joomla! Hero
Joomla! Hero

Joined: Thu Jul 24, 2008 12:48 pm
Posts: 2678
Location: Austin, TX
I'm not sure what all magic Joomla uses to find the proper files. I would try to base your component off code in the core components and see if that fixes it.

An example I usually look at is com_banner:
.../administrator/components/com_banners/tables/banner.php
Code:
class TableBanner extends JTable

[b].../administrator/components/com_banners/controllers/banner.php[/code]
Code:
$row =& JTable::getInstance('banner', 'Table');


So, I would make sure you have a tables folder in your component (administrator backend). In that folder, I would create a file that is named acgmapconfig.php (use lowercase just to be safe). In that, I would define a class called TableACGMapConfig. Then I would use the following code:
Code:
$row =& JTable::getInstance('acgmapconfig', 'Table');


Let me know if that works for you.

_________________
Will Mavis - Joomla Developer
http://www.covertapps.com/jam <<< Joomla! on your Android, iPhone, iPad, and iPod Touch
If you think I can help you, PM me a link to your post and I will respond. Please don't hijack another user's thread.


Top
 Profile  
 
PostPosted: Sun Jul 12, 2009 10:28 pm 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Fri Feb 17, 2006 6:02 pm
Posts: 97
Location: Chicago Area
I found my error -- something simple and stupid. I had not added the necessary reference to acgmap_config.php to my installation XML file.

What was baffling me was that I did base my code on functioning code using another table in the same component. The only differences were the table structures, table names and class names, and I stared at those looking for errors so much it was driving me batty. So I figured I had to be missing a parallel reference somewhere, and doing a global search across all my code turned up the issue with the XML file.

Well, hopefully at least, this little exercise may help someone else strugging with the same issue. When I searched the threads for a solution before posting here, I saw that others had indeed had the same problem, but there was never a resolution mentioned.

Thanks again for all your patience and assistance, Will!

DH


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 



Who is online

Users browsing this forum: No registered users and 23 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group