Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to use bootstrap tabs to show, edit & delete line items


I need to know the best way to show, edit & delete line items of an employee's salary components in a tab next to employee tab. I have an employee controller, its view & actions and also an employee components controller, view and edit action coded. I would like to show the employee components(line items of employee) in a bootstrap tab adjacent to the employee tab. There is a one to many relation between employee & employee components.

My question, if I understand correctly I should get all related records of an employee, i.e. components, and store them in an array. Show them in the components tab. What happens when the user edits them or deletes some of them. Should I let that be independently handled by the components controller or should I handle that in employee controller. When the data is saved I would like all master data (employee) and line items (employee components) be saved together in a single commit. I read on this forum that its bad design to have multiple controllers managing a single web page, i.e. calling action of components controller from employee controller .

The issue is how to implement delete. Edits can be saved from the POST array but what about deletes. If I use a separate controller, view, action code for the components then only deletes can be committed immediately. Can I let the component tab be independently managed by its controller or is that a bad idea. I will have more such tabs with more 1-many relations in future.


if you have defined relation, you can edit (and delete) related model from your employee controller, as well as presenting them to the view. for readability of code, simply split your view into partials...


So I must write a deleteAction in employee controller which takes action depending on which tab it is invoked from. Right?

rather do two separate delete actions if there are not supposed to do the same thing...i suggested to use a common action to prepare data you presents to view...Also note that you set your db connection and view to "setShared" in your services config, allowing you to call one controller action from another view/ controller..

edited Aug '16

@graphmatic So I will write two separate delete actions as they will be doing different things, i.e. one will delete from table employee and the other from table employee components.

A bit confused about your last sentence. Are you saying its ok to call actions of a controller from another controller. See this post which says its not a good idea call an action of another controller. So do you suggest I create a employee components controller or not. As I understood from your first post I should keep all my code in employee controller itself.



yes maybe it's not a good pactice to call controller action from other one... if you have defined relationship, you can place your two delete action in your employee controller, and let says your are editing one employee, you can acces components using relation alias ( $employee->relationAliasName->delete() ). So one action that prepare and populate one view, splitted in two partials for readability, and separate actions depending you want to act on employee or related components...