Question

I have the typical address book in which I have in my main page a list of my contacts. When I click on the classic magnify glass icon I want to go to another page that will show full info of the contact. I have this code for showing the people on a table:

<table class="table table-hover">
    <thead>
        <tr>
            <td>Name</td>
            <td>Surname</td>
            <td>Actions</td>
        </tr>
    </thead>
    <?php foreach ($this->entries as $entry): ?>
    <tbody>
        <tr>
    <td><?php echo $this->escape($entry->name) ?></td>
            <td><?php echo $this->escape($entry->surname) ?></td>
            <td><a href="<?php echo $this->url(
                array(
                    'controller' => 'contact',
                    'action'     => 'viewDetails'
                ),
                'default',
                true) ?>">
                <span class="glyphicon glyphicon-search"></span></a>
            </td>
        </tr>
    </tbody>
    <?php endforeach ?>
</table>

As you see, in the array to call the viewDetails action I'd need to send the ID of the contact I want the full info, but I don't know how to do this. Anyone knows how to send this ID and receive it in the landing page or where to find more info about the fields I can send to this link?

Thank you very much in advance.

Was it helpful?

Solution

You can try something like this:

<a href="<?php echo $this->url(
                array(
                    'controller' => 'contact',
                    'action'     => 'viewDetails',
                    'id'         => $entry->id
                ),
                'default',
                true) ?>">
// Output: "contact/viewDetails/id/id_value" with id_value = $entry->id

And in viewDetails action, you can retrieve the id like this:

$id = $this->getRequest()->getParam('id');

I hope it will help you :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top