Passing a task from admin.x.html.php to controller.php

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Locked
User avatar
drhansenjr
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 116
Joined: Fri Feb 17, 2006 6:02 pm
Location: Chicago Area

Passing a task from admin.x.html.php to controller.php

Post by drhansenjr » Sat Jul 11, 2009 10:45 pm

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?

User avatar
wlrdq
Joomla! Hero
Joomla! Hero
Posts: 2672
Joined: Thu Jul 24, 2008 12:48 pm
Location: Austin, TX
Contact:

Re: Passing a task from admin.x.html.php to controller.php

Post by wlrdq » Sat Jul 11, 2009 11:35 pm

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.

User avatar
drhansenjr
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 116
Joined: Fri Feb 17, 2006 6:02 pm
Location: Chicago Area

Re: Passing a task from admin.x.html.php to controller.php

Post by drhansenjr » Sun Jul 12, 2009 2:54 am

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: Select all

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.

User avatar
wlrdq
Joomla! Hero
Joomla! Hero
Posts: 2672
Joined: Thu Jul 24, 2008 12:48 pm
Location: Austin, TX
Contact:

Re: Passing a task from admin.x.html.php to controller.php

Post by wlrdq » Sun Jul 12, 2009 4:10 pm

Does your TableACGMapConfig class inherit from JTable? Something like:
.../libraries/joomla/database/table/content.php

Code: Select all

class JTableContent extends JTable
JTable is the one that defines the bind method:
.../libraries/joomla/database/table.php

Code: Select all

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.

User avatar
drhansenjr
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 116
Joined: Fri Feb 17, 2006 6:02 pm
Location: Chicago Area

Re: Passing a task from admin.x.html.php to controller.php

Post by drhansenjr » Sun Jul 12, 2009 5:19 pm

Yes...

Code: Select all

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 );
	}
}

User avatar
wlrdq
Joomla! Hero
Joomla! Hero
Posts: 2672
Joined: Thu Jul 24, 2008 12:48 pm
Location: Austin, TX
Contact:

Re: Passing a task from admin.x.html.php to controller.php

Post by wlrdq » Sun Jul 12, 2009 8:10 pm

Your class is named TableACGMap_Config, but you are trying to create an instance of ACGMapConfig.

http://api.joomla.org/Joomla-Framework/ ... etInstance

Try this:

Code: Select all

$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.

User avatar
drhansenjr
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 116
Joined: Fri Feb 17, 2006 6:02 pm
Location: Chicago Area

Re: Passing a task from admin.x.html.php to controller.php

Post by drhansenjr » Sun Jul 12, 2009 8:26 pm

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!

User avatar
wlrdq
Joomla! Hero
Joomla! Hero
Posts: 2672
Joined: Thu Jul 24, 2008 12:48 pm
Location: Austin, TX
Contact:

Re: Passing a task from admin.x.html.php to controller.php

Post by wlrdq » Sun Jul 12, 2009 9:02 pm

Try adding this code after the line with JTable::getInstance to see if you are getting an object back:

Code: Select all

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.

User avatar
drhansenjr
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 116
Joined: Fri Feb 17, 2006 6:02 pm
Location: Chicago Area

Re: Passing a task from admin.x.html.php to controller.php

Post by drhansenjr » Sun Jul 12, 2009 9:11 pm

Evidently I'm not -- all I get back is "Here is row:"

User avatar
wlrdq
Joomla! Hero
Joomla! Hero
Posts: 2672
Joined: Thu Jul 24, 2008 12:48 pm
Location: Austin, TX
Contact:

Re: Passing a task from admin.x.html.php to controller.php

Post by wlrdq » Sun Jul 12, 2009 9:28 pm

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: Select all

class TableBanner extends JTable
.../administrator/components/com_banners/controllers/banner.php[/code]

Code: Select all

$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: Select all

$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.

User avatar
drhansenjr
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 116
Joined: Fri Feb 17, 2006 6:02 pm
Location: Chicago Area

Re: Passing a task from admin.x.html.php to controller.php

Post by drhansenjr » Sun Jul 12, 2009 10:28 pm

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


Locked

Return to “Joomla! 1.5 Coding”