Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [inny][ZF2][ZendFramework2]Problem z wyświetleniem id.
cykcykacz
post
Post #1





Grupa: Zarejestrowani
Postów: 550
Pomógł: 9
Dołączył: 29.05.2009
Skąd: Ostrów Wielkopolski

Ostrzeżenie: (0%)
-----


Witam,
wyświetla mi wszystkie kolumny z tabelki prócz id. Musi to być jakis drobny problem. Daje kod, kotrollera, modelu, widoku.
Kontroller:
  1. public function indexAction()
  2. {
  3. $this->layout('layout/myaccount');
  4.  
  5. $userTable = $this->getServiceLocator()->get('UserTable');
  6. $viewModel = new ViewModel(array('users' => $userTable->fetchAll()));
  7. return $viewModel;
  8. }

Model:
  1. <?php
  2. namespace Users\Model;
  3.  
  4. use Zend\Db\Adapter\Adapter;
  5. use Zend\Db\ResultSet\ResultSet;
  6. use Zend\Db\TableGateway\TableGateway;
  7.  
  8. class UserTable
  9. {
  10. protected $tableGateway;
  11.  
  12. public function __construct(TableGateway $tableGateway)
  13. {
  14. $this->tableGateway = $tableGateway;
  15. }
  16.  
  17. public function saveUser(User $user)
  18. {
  19. $data = array(
  20. 'email' => $user->email,
  21. 'name' => $user->name,
  22. 'password' => $user->password,
  23. );
  24.  
  25. $id = (int)$user->id;
  26. if ($id == 0) {
  27. $this->tableGateway->insert($data);
  28. } else {
  29. if ($this->getUser($id)) {
  30. if (empty($data['password'])) {
  31. unset($data['password']);
  32. }
  33. $this->tableGateway->update($data, array('id' => $id));
  34. } else {
  35. throw new \Exception('User ID does not exist');
  36. }
  37. }
  38. }
  39.  
  40. public function fetchAll()
  41. {
  42. $resultSet = $this->tableGateway->select();
  43. return $resultSet;
  44. }
  45.  
  46. public function getUser($id)
  47. {
  48. $id = (int) $id;
  49. $rowset = $this->tableGateway->select(array('id' => $id));
  50. $row = $rowset->current();
  51. if (!$row) {
  52. throw new \Exception("Could not find row $id");
  53. }
  54. return $row;
  55. }
  56.  
  57. public function deleteUser($id)
  58. {
  59. $this->tableGateway->delete(array('id' => $id));
  60. }
  61.  
  62. /*
  63.   * Get User account by Email
  64.   */
  65. public function getUserByEmail($user_email)
  66. {
  67. $rowset = $this->tableGateway->select(array('email' => $user_email));
  68. $row = $rowset->current();
  69. if (!$row) {
  70. throw new \Exception("Could not find row $user_email");
  71. }
  72. return $row;
  73. }
  74. }
  75.  

Widok:
Kod
<h3>Users</h3>
<table class="table">
<tr>
    <th>Id</th>
    <th>Name</th>
    <th>User ID/Email</th>
    <th> </th>
</tr>
<?php foreach ($users as $user) : ?>
<tr>
    <td><?php echo $user->id?></td>
    <td><?php echo $this->escapeHtml($user->name);?></td>
    <td><?php echo $this->escapeHtml($user->email);?></td>
    <td>
        <a href="<?php echo $this->url('users/user-manager',
            array('action'=>'edit', 'id' => $user->id));?>">Edit</a> |
        <a href="<?php echo $this->url('users/user-manager',
            array('action'=>'delete', 'id' => $user->id));?>" onclick="return confirm('Are you sure?')">Delete</a>
    </td>
</tr>
<?php endforeach; ?>
</table>


Daj cie znać w czym problem.

Ten post edytował cykcykacz 3.09.2013, 14:10:17
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 24.12.2025 - 13:04