Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
MVC - technique to share form data for various models?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
AJH  
View profile  
 More options Jul 28 2012, 1:01 am
From: AJH <aaron.hu...@gmail.com>
Date: Fri, 27 Jul 2012 22:01:26 -0700 (PDT)
Local: Sat, Jul 28 2012 1:01 am
Subject: MVC - technique to share form data for various models?

I'm in Joomla! 2.5, following the MVC pattern as described in the docs...

I'm looking for pointers on the best way for my models to 'inherit' fields
from a generic table definition.

Simple example, having multiple tables with 'metadata', and that metadata
is stored in a generic table.  Each table that wants to use this 'metadata'
has a candidate key (unique identifier), and that key is the primary key
for the meta data table.

My initial attempt at this is to override the *getForm* and *loadFormData* methods
of any model that needs this metadata.  

Any suggestions would be most appreciated on how I can inject this metadata
into various models, and not have to do any funny business in my views.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
AJH  
View profile  
 More options Jul 28 2012, 2:20 am
From: AJH <aaron.hu...@gmail.com>
Date: Fri, 27 Jul 2012 23:20:54 -0700 (PDT)
Local: Sat, Jul 28 2012 2:20 am
Subject: Re: MVC - technique to share form data for various models?

I thought I would share my version of success with this issue.  I hope the
experts can make sense of my quick post and share what I have done wrong or
what could be improved.  Overall though, it seems like a fairly simple
solution.  Ideally I would like to have a generic "metadata" xml form, and
not have to copy/past the fields into each form that needs this metadata.

In the model that I want to include' the metadata:

   1. Add the fields that exist in the shared table to your XML form for
   the model in question
   2. Override the getForm method in for the model you wish to have the
   shared metadata something like:

public function getForm($data = array(), $loadData = true)
{
// Get the form.
$form = $this->loadForm('com_yourcomponent.product', 'product',
array('control' => 'jform', 'load_data' => $loadData));
if (empty($form))
{
return false;

}

// This section loads the metadata and injects it into the form we are
returning
$metaDataTable = parent::getTable('MetaData', 'YourComponentTable', $config
= array());
$metaDataTable->load($this->getItem()->guid);
$form->bind($metaDataTable);
 return $form;
}

      3. Override the save method of your model in question like the
following:

public function save($data)
{
$result = parent::save($data);
if($result)
{
// save the metadata
$metaDataTable = parent::getTable('MetaData', 'YourComponentTable', $config
= array());
$result = $metaDataTable->save($data);
 }
return $result;


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »