I'm working on one module based on sfGuard and I need to allow users to edit or delete records. This is how I get the users:
$id_empresa = $this->getUser()->getGuardUser()->getSfGuardUserProfile()->getIdempresa();
$this->users = Doctrine_Core::getTable('sfGuardUser')->createQuery('u')->leftJoin('u.SfGuardUserProfile p')->where('idempresa = ?', $id_empresa)->execute();
But then in the view while I'm iterating I don't know how to access to user_id
value. I checked BasesfGuardUser
but no method for get the Id exists, any advice or help?
Added the code for the view This is the code for the iteration:
<?php foreach ($users as $user): ?>
<tr>
<td><?php echo $user->getFirstName() ?></td>
<td><?php echo $user->getLastName() ?></td>
<td><?php echo $user->getEmailAddress() ?></td>
<td><?php echo $user->getUsername() ?></td>
<td><?php echo $user->getIsActive() ?></td>
<td>
<a href="<?php echo url_for('guard/users/' . $user->get('id') . '/edit') ?>" class="btn btn-success btn-mini">Editar</a>
<a href="<?php echo url_for('guard/users/' . $user->get('id')) ?>" class="btn btn-danger btn-mini">Eliminar</a>
</td>
</tr>
<?php endforeach; ?>
The problem is the 'guard/users/' . $user->get('id') . '/edit'
part in url_for
. Maybe it's because usuarios/edit/1
is not a valid parameter for url_for
so it's parsed as module/action
and the /1
part is ignored, but I'm not sure.
IIRC url_for
actually has 4 valid form:
url_for('module/action', array('param1' => 'value1'), true /* absolute */)
url_for('@route_name?param1=value1', true /* absolute */)
url_for('route_name', array('param1' => 'value1'), true /* absolute */)
url_for('route_name', $object, true /* absolute */)
or url_for('route_name', array('sf_subject' => $object, 'extra_param' => 'value'), true /* absolute */)
If you have an object route (e.g. sfDoctrineRoute
) you should use the last one, if you have a non-object route with parameters you should use the 3rd and if you have a route with no parameter you should use the 2nd.