I have a view that lists timesheets.
on that view, each timesheet has a deliverable field... I have a DeliverableController that has an action "DropdownList" that calls upon the model and gets a list of deliverables and pushes them to a deliverable view (which just creates a dropdown box).
When im looping through my timesheets I would like to get the response of the DeliverableController/DropdownList and put it where my deliverable field should be on the timesheet.
- A) is there a way of getting the response of a controller from within a view
- B) is there a way of getting the response of a controller from within a controller method, so that I can push the result to the view?
My code so far is:
DeliverableController:
class DeliverableController extends BaseController {
private $deliverableRepository;
function __Construct( IDeliverableRepository $deliverableRepo )
{
$this->deliverableRepository = $deliverableRepo;
}
...
public /* */ function DropdownList()
{
$deliverables = $this->deliverableRepository->Deliverables();
return View::make( 'Deliverable/_DropdownList', array( "Model" => $deliverables ) );
}
}
Deliverables/_DropdownList View:
<?php
foreach( $Model as $item )
{
?>
<select name="">
<option value = "<?php echo $item->ID; ?>"><?php echo $item->Title; ?></option>
</select>
<?php
}
?>
Timesheet Controller:
class TimesheetController extends BaseController {
private $timesheetRepository;
function __Construct( ITimesheetRepository $timesheetRepo )
{
$this->timesheetRepository = $timesheetRepo;
}
...
// [HttpGET]
public /* */ function GetCreate()
{
return View::make( 'Timesheet/Create' );
}
// [HttpPOST]
public /* */ function PostCreate()
{
// To do
}
}
Timesheet/Create
@extends( 'layout' )
@section( 'Styles' )
<link href="<?php echo Request::root(); ?>/Styles/Timesheet.css" rel="stylesheet">
@stop
@section( 'Title' )
Create timesheets
@stop
@section( 'Content' )
<form role="form">
<table id="TimesheetTable" class="table">
<thead>
<tr>
<th>Project/Deliverable</th>
...
</tr>
</thead>
<tfoot>
<tr>
<td></td>
...
</tr>
</tfoot>
<tbody>
<?php
for( $a = 0; $a < 18; $a++ )
{
?>
<tr id='row<?php echo $a; ?>'>
<td><?php /* Get response from DeliverableController/DropdownList */ ?></td>...
</tr>
<?php
}
?>
</tbody>
</table>
@stop
@section( 'Scripts' )
<script src="<?php echo Request::root(); ?>/Scripts/Timesheet.js"></script>
@stop
Notice the /* Get response from DeliverableController/DropdownList */