You are not logged in.
Pages: 1
Is there any easy way to retrieve the field type for each resource when displaying a module or page? I can't see any obvious way to do it. Reason I want to do this is so that I can use modules for defining forms to appear on the front-end of the site, and want to be able to display different form controls depending on the type of field.
Offline
Unfortunately, it doesn't look like there are any simple calls to get that info on the front end right now. I'm going to tweak BigTreeCMS::getTemplate to make it easier in RC2, but for now:
$resource_types = array();
$template = $cms->getTemplate($bigtree["page"]["template"]);
foreach ($template["resources"] as $resource) {
$resource_types[$resource["id"]] = $resource["type"];
}
foreach ($bigtree["page"]["resources"] as $key => $val) {
echo "Resource $key has a type of ".$resource_types[$key]."";
}
That would show you all the types of a given page. It probably makes sense to give the resource IDs as the keys of $template["resources"] enabling us to skip the whole $resource_types array so I'll make that change in RC2 (which is long coming, but will be here soon hopefully).
Ok, now for modules! For this you'll need to do a straight up SQL query to get the form ID first (which assumes you only have one form for your module data).
$module = new WhateverModule;
$form = sqlfetch(sqlquery("SELECT id FROM bigtree_module_forms WHERE `table` = '".sqlescape($module->Table)."'"));
$form = BigTreeAutoModule::getForm($form["id"]);
Once you have $form you can loop through $form["fields"] and grab the types. The keys of that array are the resource IDs and there's the "type" column for the type of resource.
Offline
Thanks Tim,
I was thinking about this a bit more, and occurred to me that querying the module tables, as you've mentioned, would be the best solution. I'm thinking that I can even extend the module class to do all the heavy lifting, and just call a single method.
I'm going to play around with this and see how I get on with using the built in getForm() stuff.
Offline
Let me know if you come up with any cool method for doing it more easily. It's not something I've needed to do before so I haven't thought about it all that much!
Offline
Pages: 1