-1

I make a view file in ZF2.In which i pass id to the controller.

How i get this id in controller?

Here is my showAction code where i want to get id:

public function showAction()
{           
    $id = (int) $this->params()->fromRoute('id', 0);
    if (!$id) {
        return $this->redirect()->toRoute('calendar', array(
            'action' => 'create'
        ));
    }               
}

and here is my index.phtml on which i pass id to show controller:

<table class="table">
<tr>
    <th>Calendar name</th>
    <th>Description</th>
    <th>Actions</th>
</tr>
<?php foreach ($calendars as $key => $value) :  ?>
<tr>
    <td>
        <a href="<?php echo $this->url('calendar',array('action'=>'show', 'id' => $this->escapeHtml($value['_id'])));?>">
                <?php echo $this->escapeHtml($value['title']);?>
        </a>
    </td>
    <td><?php echo $this->escapeHtml($value['description']);?></td>
    <td>
        <a href="<?php echo $this->url('calendar',
            array('action'=>'settings', 'id' => $this->escapeHtml($value['_id'])));?>">Settings</a>
        <a href="<?php echo $this->url('calendar',
            array('action'=>'delete', 'id' => $this->escapeHtml($value['_id'])));?>">delete</a>
    </td>
</tr>
<?php endforeach; ?>
</table>    
Muhammad Arif
  • 1,014
  • 3
  • 22
  • 56
  • please STOP CREATING NEW THREADS OVER AND OVER AGAIN. This is the same problems for 2 days now and you change NOTHING. You don't even understand where your problem is. You have gotten ALL THE POSSIBLE HELP YOU NEED. This question now doesn't even have a question in it. You have the ID in your `$id` variable already as long as your route accepts it. Once again: START WITH THE DOCUMENTATION, start from the very beginning. – Sam Apr 18 '14 at 09:09
  • possible duplicate of [how to show fullcalendar events in zf2 using mongo odm?](http://stackoverflow.com/questions/23136588/how-to-show-fullcalendar-events-in-zf2-using-mongo-odm) – Sam Apr 18 '14 at 09:10
  • sam i solved my problem who face last two weeks actually i pass id from view but in controller i dont access it,you see my code – Muhammad Arif Apr 18 '14 at 09:11
  • thanks sam i get the id using $id – Muhammad Arif Apr 18 '14 at 09:16

1 Answers1

1

You are gettting your id fro route through this line in your controller

$id = (int) $this->params()->fromRoute('id', 0);

If you want, you can also access it by the following line

$id = (int)$this->params('id');

if you echo $id, you should get your id value

Akhil Sidharth
  • 746
  • 1
  • 6
  • 16