Reputation: 11
I have built a component which has two tables of data, these are related by an ID.
I have it working so that when you are viewing table A, you can click a field and proceed to the view of table B - which is filtered by the the ID from table A.
My last challenge: When the user clicks the AddNew button when viewing table B we need to take the related ID into the addnew form so it saves in a hidden field.
Any pointers welcomed please! Up against a deadline, pulling too much hair out, and overdosing on caffeine!!
Upvotes: 1
Views: 93
Reputation: 340
You could:
a. add a hidden field in the view of table A rows with the related id
<form method="post" name="adminForm" id="adminForm" >
...
<input type="hidden" name="yourid" value="...." />
</form>
b. override the add()
function in your controller of a field of table B (the one that extends the JControllerForm
), add in the redirect url the yourid
parameter
class ...Controller... extends JControllerForm {
public function add() {
//...
$yid = $app->input->get('yourid');
$this->setRedirect(JRoute::_('index.php?option=' .
$this->option . '&view=' . $this->view_item .
'&yourid=' . $yid . $this->getRedirectToItemAppend(), false));
//...
}
}
c. in the model of the table b you can get the yourid
input parameter, and edit the rest queries.
public function __construct($config = array()) {
// ..
$this->yid = $app->input->get('yourid');
parent::__construct($config);
}
Hope this helps.
Upvotes: 1