OOP Arrow Calls in Tor CakePHP

 

 

products_controller.php/view

 

username= billgoss

string 'billgoss' (length=8)

userid= 17

int 17

Product ID= 69

Remember the Associations

Remember this is in the products_controller.php

$product = $this->Product->read(null, $id);  //product in question

 

array
  'Product' => 
    array
      'id' => string '69' (length=2)
      'title' => string 'Product7' (length=8)
      'dealer_id' => string '30' (length=2)
      'description' => string 'Product7 not updated' (length=20)
  'Dealer' => 
    array
      'id' => string '30' (length=2)
      'title' => string 'Goss4' (length=5)
  'User' => 
    array
      0 => 
        array
          'id' => string '17' (length=2)
          'username' => string 'billgoss' (length=8)
          'password' => string '4e671d1f5972f2fe1d8a3215db5167fd' (length=32)
          'email' => string 'wgoss@indy.rr.com' (length=17)
          'first_name' => string 'William' (length=7)
          'last_name' => string 'Goss' (length=4)

Tor : Welcome billgoss

Products | Favorites | Login | Logout

Product

Id

69  

Title

Product7  

Dealer

Goss4  

Description

Product7 not updated  

CakePHP: the rapid development php framework

23 queries took 25 ms

Nr

Query

Error

Affected

Num. rows

Took (ms)

1

DESCRIBE `aros`

 

7

7

4

2

DESCRIBE `acos`

 

7

7

4

3

DESCRIBE `aros_acos`

 

7

7

4

4

DESCRIBE `products`

 

4

4

3

5

DESCRIBE `dealers`

 

2

2

3

6

DESCRIBE `users`

 

6

6

4

7

DESCRIBE `products_users`

 

2

2

3

8

SELECT `Product`.`id`, `Product`.`title`, `Product`.`dealer_id`, `Product`.`description`, `Dealer`.`id`, `Dealer`.`title` FROM `products` AS `Product` LEFT JOIN `dealers` AS `Dealer` ON (`Product`.`dealer_id` = `Dealer`.`id`) WHERE `Product`.`id` = 69 LIMIT 1

 

1

1

0

9

SELECT `User`.`id`, `User`.`username`, `User`.`password`, `User`.`email`, `User`.`first_name`, `User`.`last_name`, `ProductsUser`.`product_id`, `ProductsUser`.`user_id` FROM `users` AS `User` JOIN `products_users` AS `ProductsUser` ON (`ProductsUser`.`product_id` = 69 AND `ProductsUser`.`user_id` = `User`.`id`) WHERE 1 = 1

 

1

1

0

10

SELECT `Aro`.`id`, `Aro`.`parent_id`, `Aro`.`model`, `Aro`.`foreign_key`, `Aro`.`alias` FROM `aros` AS `Aro` LEFT JOIN `aros` AS `Aro0` ON (`Aro0`.`alias` = 'billgoss') WHERE `Aro`.`lft` <= `Aro0`.`lft` AND `Aro`.`rght` >= `Aro0`.`rght` ORDER BY `Aro`.`lft` DESC

 

2

2

0

11

SELECT `Aco`.`id`, `Aco`.`parent_id`, `Aco`.`model`, `Aco`.`foreign_key`, `Aco`.`alias` FROM `acos` AS `Aco` LEFT JOIN `acos` AS `Aco0` ON (`Aco0`.`alias` = '69-Product7') WHERE `Aco`.`lft` <= `Aco0`.`lft` AND `Aco`.`rght` >= `Aco0`.`rght` ORDER BY `Aco`.`lft` DESC

 

2

2

0

12

SELECT `Permission`.`id`, `Permission`.`aro_id`, `Permission`.`aco_id`, `Permission`.`_create`, `Permission`.`_read`, `Permission`.`_update`, `Permission`.`_delete`, `Aro`.`id`, `Aro`.`parent_id`, `Aro`.`model`, `Aro`.`foreign_key`, `Aro`.`alias`, `Aro`.`lft`, `Aro`.`rght`, `Aco`.`id`, `Aco`.`parent_id`, `Aco`.`model`, `Aco`.`foreign_key`, `Aco`.`alias`, `Aco`.`lft`, `Aco`.`rght` FROM `aros_acos` AS `Permission` LEFT JOIN `aros` AS `Aro` ON (`Permission`.`aro_id` = `Aro`.`id`) LEFT JOIN `acos` AS `Aco` ON (`Permission`.`aco_id` = `Aco`.`id`) WHERE `Permission`.`aro_id` = 3 AND `Permission`.`aco_id` IN (35, 32) ORDER BY `Aco`.`lft` desc

 

2

2

0

13

SELECT `User`.`id`, `User`.`username`, `User`.`password`, `User`.`email`, `User`.`first_name`, `User`.`last_name` FROM `users` AS `User` WHERE `User`.`username` = 'billgoss' LIMIT 1

 

1

1

0

14

SELECT `Product`.`id`, `Product`.`title`, `Product`.`dealer_id`, `Product`.`description`, `ProductsUser`.`product_id`, `ProductsUser`.`user_id` FROM `products` AS `Product` JOIN `products_users` AS `ProductsUser` ON (`ProductsUser`.`user_id` = 17 AND `ProductsUser`.`product_id` = `Product`.`id`) WHERE 1 = 1

 

5

5

0

15

SELECT `Aro`.`id`, `Aro`.`parent_id`, `Aro`.`model`, `Aro`.`foreign_key`, `Aro`.`alias` FROM `aros` AS `Aro` LEFT JOIN `aros` AS `Aro0` ON (`Aro0`.`alias` = 'billgoss') WHERE `Aro`.`lft` <= `Aro0`.`lft` AND `Aro`.`rght` >= `Aro0`.`rght` ORDER BY `Aro`.`lft` DESC

 

2

2

0

16

SELECT `Aco`.`id`, `Aco`.`parent_id`, `Aco`.`model`, `Aco`.`foreign_key`, `Aco`.`alias` FROM `acos` AS `Aco` LEFT JOIN `acos` AS `Aco0` ON (`Aco0`.`alias` = '69-Product7') WHERE `Aco`.`lft` <= `Aco0`.`lft` AND `Aco`.`rght` >= `Aco0`.`rght` ORDER BY `Aco`.`lft` DESC

 

2

2

0

17

SELECT `Permission`.`id`, `Permission`.`aro_id`, `Permission`.`aco_id`, `Permission`.`_create`, `Permission`.`_read`, `Permission`.`_update`, `Permission`.`_delete`, `Aro`.`id`, `Aro`.`parent_id`, `Aro`.`model`, `Aro`.`foreign_key`, `Aro`.`alias`, `Aro`.`lft`, `Aro`.`rght`, `Aco`.`id`, `Aco`.`parent_id`, `Aco`.`model`, `Aco`.`foreign_key`, `Aco`.`alias`, `Aco`.`lft`, `Aco`.`rght` FROM `aros_acos` AS `Permission` LEFT JOIN `aros` AS `Aro` ON (`Permission`.`aro_id` = `Aro`.`id`) LEFT JOIN `acos` AS `Aco` ON (`Permission`.`aco_id` = `Aco`.`id`) WHERE `Permission`.`aro_id` = 3 AND `Permission`.`aco_id` IN (35, 32) ORDER BY `Aco`.`lft` desc

 

2

2

0

18

SELECT `Aro`.`id`, `Aro`.`parent_id`, `Aro`.`model`, `Aro`.`foreign_key`, `Aro`.`alias` FROM `aros` AS `Aro` LEFT JOIN `aros` AS `Aro0` ON (`Aro0`.`alias` = 'billgoss') WHERE `Aro`.`lft` <= `Aro0`.`lft` AND `Aro`.`rght` >= `Aro0`.`rght` ORDER BY `Aro`.`lft` DESC

 

2

2

0

19

SELECT `Aco`.`id`, `Aco`.`parent_id`, `Aco`.`model`, `Aco`.`foreign_key`, `Aco`.`alias` FROM `acos` AS `Aco` LEFT JOIN `acos` AS `Aco0` ON (`Aco0`.`alias` = '69-Product7') WHERE `Aco`.`lft` <= `Aco0`.`lft` AND `Aco`.`rght` >= `Aco0`.`rght` ORDER BY `Aco`.`lft` DESC

 

2

2

0

20

SELECT `Permission`.`id`, `Permission`.`aro_id`, `Permission`.`aco_id`, `Permission`.`_create`, `Permission`.`_read`, `Permission`.`_update`, `Permission`.`_delete`, `Aro`.`id`, `Aro`.`parent_id`, `Aro`.`model`, `Aro`.`foreign_key`, `Aro`.`alias`, `Aro`.`lft`, `Aro`.`rght`, `Aco`.`id`, `Aco`.`parent_id`, `Aco`.`model`, `Aco`.`foreign_key`, `Aco`.`alias`, `Aco`.`lft`, `Aco`.`rght` FROM `aros_acos` AS `Permission` LEFT JOIN `aros` AS `Aro` ON (`Permission`.`aro_id` = `Aro`.`id`) LEFT JOIN `acos` AS `Aco` ON (`Permission`.`aco_id` = `Aco`.`id`) WHERE `Permission`.`aro_id` = 3 AND `Permission`.`aco_id` IN (35, 32) ORDER BY `Aco`.`lft` desc

 

2

2

0

21

SELECT `Aro`.`id`, `Aro`.`parent_id`, `Aro`.`model`, `Aro`.`foreign_key`, `Aro`.`alias` FROM `aros` AS `Aro` LEFT JOIN `aros` AS `Aro0` ON (`Aro0`.`alias` = 'billgoss') WHERE `Aro`.`lft` <= `Aro0`.`lft` AND `Aro`.`rght` >= `Aro0`.`rght` ORDER BY `Aro`.`lft` DESC

 

2

2

0

22

SELECT `Aco`.`id`, `Aco`.`parent_id`, `Aco`.`model`, `Aco`.`foreign_key`, `Aco`.`alias` FROM `acos` AS `Aco` LEFT JOIN `acos` AS `Aco0` ON (`Aco0`.`alias` = '69-Product7') WHERE `Aco`.`lft` <= `Aco0`.`lft` AND `Aco`.`rght` >= `Aco0`.`rght` ORDER BY `Aco`.`lft` DESC

 

2

2

0

23

SELECT `Permission`.`id`, `Permission`.`aro_id`, `Permission`.`aco_id`, `Permission`.`_create`, `Permission`.`_read`, `Permission`.`_update`, `Permission`.`_delete`, `Aro`.`id`, `Aro`.`parent_id`, `Aro`.`model`, `Aro`.`foreign_key`, `Aro`.`alias`, `Aro`.`lft`, `Aro`.`rght`, `Aco`.`id`, `Aco`.`parent_id`, `Aco`.`model`, `Aco`.`foreign_key`, `Aco`.`alias`, `Aco`.`lft`, `Aco`.`rght` FROM `aros_acos` AS `Permission` LEFT JOIN `aros` AS `Aro` ON (`Permission`.`aro_id` = `Aro`.`id`) LEFT JOIN `acos` AS `Aco` ON (`Permission`.`aco_id` = `Aco`.`id`) WHERE `Permission`.`aro_id` = 3 AND `Permission`.`aco_id` IN (35, 32) ORDER BY `Aco`.`lft` desc

 

2

2

0

 

 

Notice Error When Calling $this->User->read from products_controller.php

 

The Call= $this->User->read(null, $userid)

As the call is in the products_controller.php, yields an error

 

.

.

.

 

 

 

 

 

This is the call for favorites for username=billgoss, userid=17.

This is a Products HABTM Users  (with join table products_users)

products_controller.php/view – Remember associations

The Call: $favorites = $this->Product->User->findByUsername($username)

array
  'User' => 
    array
      'id' => string '17' (length=2)
      'username' => string 'billgoss' (length=8)
      'password' => string '4e671d1f5972f2fe1d8a3215db5167fd' (length=32)
      'email' => string 'wgoss@indy.rr.com' (length=17)
      'first_name' => string 'William' (length=7)
      'last_name' => string 'Goss' (length=4)
  'Product' => 
    array
      0 => 
        array
          'id' => string '42' (length=2)
          'title' => string 'Product2' (length=8)
          'dealer_id' => string '7' (length=1)
          'description' => string 'Product2 updated 7X' (length=19)
      1 => 
        array
          'id' => string '46' (length=2)
          'title' => string 'Product3' (length=8)
          'dealer_id' => string '2' (length=1)
          'description' => string 'Product3' (length=8)
      2 => 
        array
          'id' => string '50' (length=2)
          'title' => string 'Product1' (length=8)
          'dealer_id' => string '7' (length=1)
          'description' => string 'Product1 Updated 1X' (length=19)
      3 => 
        array
          'id' => string '53' (length=2)
          'title' => string 'Product4' (length=8)
          'dealer_id' => string '2' (length=1)
          'description' => string 'Product4' (length=8)
      4 => 
        array
          'id' => string '69' (length=2)
          'title' => string 'Product7' (length=8)
          'dealer_id' => string '30' (length=2)
          'description' => string 'Product7 not updated' (length=20)
 
 
 
 
 
 
 
 
 
The Join Table for the Product HABTM User join table
Full Textsproduct_id user_id 
EditDelete        42      17 
EditDelete       44      18 
EditDelete       46      17 
EditDelete       50      17 
EditDelete       51      18 
EditDelete       53      17 
EditDelete       69      17

Tor : Welcome

Products | Favorites | Login | Logout

CakePHP: the rapid development php framework

11 queries took 25 ms

Nr

Query

Error

Affected

Num. rows

Took (ms)

1

DESCRIBE `aros`

 

7

7

4

2

DESCRIBE `acos`

 

7

7

4

3

DESCRIBE `aros_acos`

 

7

7

4

4

DESCRIBE `products`

 

4

4

3

5

DESCRIBE `dealers`

 

2

2

3

6

DESCRIBE `users`

 

6

6

4

7

DESCRIBE `products_users`

 

2

2

3

8

SELECT `Product`.`id`, `Product`.`title`, `Product`.`dealer_id`, `Product`.`description`, `Dealer`.`id`, `Dealer`.`title` FROM `products` AS `Product` LEFT JOIN `dealers` AS `Dealer` ON (`Product`.`dealer_id` = `Dealer`.`id`) WHERE `Product`.`id` = 69 LIMIT 1

 

1

1

0

9

SELECT `User`.`id`, `User`.`username`, `User`.`password`, `User`.`email`, `User`.`first_name`, `User`.`last_name`, `ProductsUser`.`product_id`, `ProductsUser`.`user_id` FROM `users` AS `User` JOIN `products_users` AS `ProductsUser` ON (`ProductsUser`.`product_id` = 69 AND `ProductsUser`.`user_id` = `User`.`id`) WHERE 1 = 1

 

1

1

0

10

SELECT `User`.`id`, `User`.`username`, `User`.`password`, `User`.`email`, `User`.`first_name`, `User`.`last_name` FROM `users` AS `User` WHERE `User`.`username` = 'billgoss' LIMIT 1

 

1

1

0

11

SELECT `Product`.`id`, `Product`.`title`, `Product`.`dealer_id`, `Product`.`description`, `ProductsUser`.`product_id`, `ProductsUser`.`user_id` FROM `products` AS `Product` JOIN `products_users` AS `ProductsUser` ON (`ProductsUser`.`user_id` = 17 AND `ProductsUser`.`product_id` = `Product`.`id`) WHERE 1 = 1

 

5

5

0

 

 

User Model/removeFavorite Method (remember associations, especially HABTM)

 

$user = $this->read();

array
  'User' => 
    array
      'id' => string '17' (length=2)
      'username' => string 'billgoss' (length=8)
      'password' => string '4e671d1f5972f2fe1d8a3215db5167fd' (length=32)
      'email' => string 'wgoss@indy.rr.com' (length=17)
      'first_name' => string 'William' (length=7)
      'last_name' => string 'Goss' (length=4)
  'Product' => 
    array
      0 => 
        array
          'id' => string '42' (length=2)
          'title' => string 'Product2' (length=8)
          'dealer_id' => string '7' (length=1)
          'description' => string 'Product2 updated 7X' (length=19)
      1 => 
        array
          'id' => string '46' (length=2)
          'title' => string 'Product3' (length=8)
          'dealer_id' => string '2' (length=1)
          'description' => string 'Product3' (length=8)
      2 => 
        array
          'id' => string '50' (length=2)
          'title' => string 'Product1' (length=8)
          'dealer_id' => string '7' (length=1)
          'description' => string 'Product1 Updated 1X' (length=19)
      3 => 
        array
          'id' => string '53' (length=2)
          'title' => string 'Product4' (length=8)
          'dealer_id' => string '2' (length=1)
          'description' => string 'Product4' (length=8)
      4 => 
        array
          'id' => string '69' (length=2)
          'title' => string 'Product7' (length=8)
          'dealer_id' => string '30' (length=2)
          'description' => string 'Product7 not updated' (length=20)
 
$fav = array();
foreach($user['Product'] as $product) {
      if ($product_id != $product['id']) {
            $fav[] = $product['id'];
      }
}
var_dump($fav);
 
array
  0 => string '42' (length=2)
  1 => string '46' (length=2)
  2 => string '50' (length=2)
  3 => string '53' (length=2)
$user['Product'] = array('Product'=> $fav);
//var_dump($user);
 
array
  'User' => 
    array
      'id' => string '17' (length=2)
      'username' => string 'billgoss' (length=8)
      'password' => string '4e671d1f5972f2fe1d8a3215db5167fd' (length=32)
      'email' => string 'wgoss@indy.rr.com' (length=17)
      'first_name' => string 'William' (length=7)
      'last_name' => string 'Goss' (length=4)
  'Product' => 
    array
      'Product' => 
        array
          0 => string '42' (length=2)
          1 => string '46' (length=2)
          2 => string '50' (length=2)
          3 => string '53' (length=2)
Warning (2): Cannot modify header information - headers already sent by (output started at C:\home\cake\tor\models\user.php:38) [C:\home\cake\cake\libs\controller\controller.php, line 577]

Code | Context

$status                                                                                              =                                                                                              "Location: http://localhost/tor/users/favorites"
header - [internal], line ??
Controller::header() - C:\home\cake\cake\libs\controller\controller.php, line 577
Controller::redirect() - C:\home\cake\cake\libs\controller\controller.php, line 558
ProductsController::removeFromFavorites() - C:\home\cake\tor\controllers\products_controller.php, line 202
Object::dispatchMethod() - C:\home\cake\cake\libs\object.php, line 116
Dispatcher::_invoke() - C:\home\cake\cake\dispatcher.php, line 256
Dispatcher::dispatch() - C:\home\cake\cake\dispatcher.php, line 230
[main] - C:\wamp\www\tor\index.php, line 90

16 queries took 52 ms

Nr

Query

Error

Affected

Num. rows

Took (ms)

1

DESCRIBE `aros`

 

7

7

4

2

DESCRIBE `acos`

 

7

7

4

3

DESCRIBE `aros_acos`

 

7

7

4

4

DESCRIBE `products`

 

4

4

3

5

DESCRIBE `dealers`

 

2

2

3

6

DESCRIBE `users`

 

6

6

4

7

DESCRIBE `products_users`

 

2

2

3

8

SELECT `User`.`id` FROM `users` AS `User` WHERE `User`.`username` = 'billgoss' LIMIT 1

 

1

1

1

9

SELECT `Product`.`id`, `Product`.`title`, `Product`.`dealer_id`, `Product`.`description`, `ProductsUser`.`product_id`, `ProductsUser`.`user_id` FROM `products` AS `Product` JOIN `products_users` AS `ProductsUser` ON (`ProductsUser`.`user_id` = 17 AND `ProductsUser`.`product_id` = `Product`.`id`) WHERE 1 = 1

 

5

5

0

10

SELECT COUNT(*) AS `count` FROM `users` AS `User` WHERE `User`.`id` = 17

 

1

1

1

11

SELECT `User`.`id`, `User`.`username`, `User`.`password`, `User`.`email`, `User`.`first_name`, `User`.`last_name` FROM `users` AS `User` WHERE `User`.`id` = 17 LIMIT 1

 

1

1

1

12

SELECT `Product`.`id`, `Product`.`title`, `Product`.`dealer_id`, `Product`.`description`, `ProductsUser`.`product_id`, `ProductsUser`.`user_id` FROM `products` AS `Product` JOIN `products_users` AS `ProductsUser` ON (`ProductsUser`.`user_id` = 17 AND `ProductsUser`.`product_id` = `Product`.`id`) WHERE 1 = 1

 

5

5

0

13

UPDATE `users` SET `id` = 17, `username` = 'billgoss', `password` = '4e671d1f5972f2fe1d8a3215db5167fd', `email` = 'wgoss@indy.rr.com', `first_name` = 'William', `last_name` = 'Goss' WHERE `users`.`id` = 17

 

0

 

1

14

SELECT `ProductsUser`.`user_id` FROM `products_users` AS `ProductsUser` WHERE `ProductsUser`.`user_id` = 17

 

5

5

1

15

DELETE `ProductsUser` FROM `products_users` AS `ProductsUser` WHERE `ProductsUser`.`user_id` IN (17, 17, 17, 17, 17)

 

5

 

19

16

INSERT INTO `products_users` (`user_id`,`product_id`) VALUES (17,'42'), (17,'46'), (17,'50'), (17,'53')

 

4

 

3

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Code | Context

$status                                                                                              =                                                                                              "Location: http://localhost/tor/users/favorites"
header - [internal], line ??
Controller::header() - C:\home\cake\cake\libs\controller\controller.php, line 577
Controller::redirect() - C:\home\cake\cake\libs\controller\controller.php, line 558
ProductsController::removeFromFavorites() - C:\home\cake\tor\controllers\products_controller.php, line 201
Object::dispatchMethod() - C:\home\cake\cake\libs\object.php, line 116
Dispatcher::_invoke() - C:\home\cake\cake\dispatcher.php, line 256
Dispatcher::dispatch() - C:\home\cake\cake\dispatcher.php, line 230
[main] - C:\wamp\www\tor\index.php, line 90

16 queries took 57 ms

Nr

Query

Error

Affected

Num. rows

Took (ms)

1

DESCRIBE `aros`

 

7

7

4

2

DESCRIBE `acos`

 

7

7

4

3

DESCRIBE `aros_acos`

 

7

7

4

4

DESCRIBE `products`

 

4

4

4

5

DESCRIBE `dealers`

 

2

2

3

6

DESCRIBE `users`

 

6

6

4

7

DESCRIBE `products_users`

 

2

2

3

8

SELECT `User`.`id` FROM `users` AS `User` WHERE `User`.`username` = 'billgoss' LIMIT 1

 

1

1

1

9

SELECT `Product`.`id`, `Product`.`title`, `Product`.`dealer_id`, `Product`.`description`, `ProductsUser`.`product_id`, `ProductsUser`.`user_id` FROM `products` AS `Product` JOIN `products_users` AS `ProductsUser` ON (`ProductsUser`.`user_id` = 17 AND `ProductsUser`.`product_id` = `Product`.`id`) WHERE 1 = 1

 

5

5

0

10

SELECT COUNT(*) AS `count` FROM `users` AS `User` WHERE `User`.`id` = 17

 

1

1

1

11

SELECT `User`.`id`, `User`.`username`, `User`.`password`, `User`.`email`, `User`.`first_name`, `User`.`last_name` FROM `users` AS `User` WHERE `User`.`id` = 17 LIMIT 1

 

1

1

1

12

SELECT `Product`.`id`, `Product`.`title`, `Product`.`dealer_id`, `Product`.`description`, `ProductsUser`.`product_id`, `ProductsUser`.`user_id` FROM `products` AS `Product` JOIN `products_users` AS `ProductsUser` ON (`ProductsUser`.`user_id` = 17 AND `ProductsUser`.`product_id` = `Product`.`id`) WHERE 1 = 1

 

5

5

0

13

UPDATE `users` SET `id` = 17, `username` = 'billgoss', `password` = '4e671d1f5972f2fe1d8a3215db5167fd', `email` = 'wgoss@indy.rr.com', `first_name` = 'William', `last_name` = 'Goss' WHERE `users`.`id` = 17

 

0

 

1

14

SELECT `ProductsUser`.`user_id` FROM `products_users` AS `ProductsUser` WHERE `ProductsUser`.`user_id` = 17

 

5

5

1

15

DELETE `ProductsUser` FROM `products_users` AS `ProductsUser` WHERE `ProductsUser`.`user_id` IN (17, 17, 17, 17, 17)

 

5

 

23

16

INSERT INTO `products_users` (`user_id`,`product_id`) VALUES (17,'42'), (17,'46'), (17,'50'), (17,'53')

 

4

 

3

 

 

 

user_controller.php  

 

 function favorites () {

        $username = $this->Session->read('user'); è ‘billgoss’

                     string 'billgoss' (length=8)

        $favorites = array(); è $favorites Array[0]

        if ($username) {

           $this->User->recursive = 2;  ç Notice this

 

           $results = $this->User->findByUsername($username);

 

array
  'User' => 
    array
      'id' => string '17' (length=2)
      'username' => string 'billgoss' (length=8)
      'password' => string '4e671d1f5972f2fe1d8a3215db5167fd' (length=32)
      'email' => string 'wgoss@indy.rr.com' (length=17)
      'first_name' => string 'William' (length=7)
      'last_name' => string 'Goss' (length=4)
  'Product' => 
    array
      0 => 
        array
          'id' => string '42' (length=2)
          'title' => string 'Product2' (length=8)
          'dealer_id' => string '7' (length=1)
          'description' => string 'Product2 updated 7X' (length=19)
          'Dealer' => 
            array
              ‘id’ => ‘7’
              ‘title’ => ‘Goss New Deal’
      1 => 
        array
          'id' => string '46' (length=2)
          'title' => string 'Product3' (length=8)
          'dealer_id' => string '2' (length=1)
          'description' => string 'Product3' (length=8)
          'Dealer' => 
            array
              ‘id’ => ‘2’
              'title' => string 'Tor Johnson School Of Drama' (length=27)
      2 => 
        array
          'id' => string '50' (length=2)
          'title' => string 'Product1' (length=8)
          'dealer_id' => string '7' (length=1)
          'description' => string 'Product1 Updated 1X' (length=19)
          'Dealer' => 
            array
              'id' => string '7' (length=1)
              'title' => string 'Goss New Deal ' (length=14)
 
      3 => 
        array
          'id' => string '53' (length=2)
          'title' => string 'Product4' (length=8)
          'dealer_id' => string '2' (length=1)
          'description' => string 'Product4' (length=8)
          'Dealer' => 
            array
              ‘id’ => ‘2’
              'title' => string 'Tor Johnson School Of Drama' (length=27)
 
      4 => 
        array
          'id' => string '69' (length=2)
          'title' => string 'Product7' (length=8)
          'dealer_id' => string '30' (length=2)
          'description' => string 'Product7 not updated' (length=20)
          'Dealer' => 
            array
              ‘id’ => ‘2’
              'title' => string 'Tor Johnson School Of Drama' (length=27)
 
foreach($results['Product'] as $product)
{
 $favorites[] = array('Product' => $product, 'Dealer' => $product['Dealer']);
}
var_dump($favorites);   Notice no User as in $results
array
  0 => 
    array
      'Product' => 
        array
          'id' => string '42' (length=2)
          'title' => string 'Product2' (length=8)
          'dealer_id' => string '7' (length=1)
          'description' => string 'Product2 updated 7X' (length=19)
          'Dealer' => 
            array
              'id' => string '7' (length=1)
              'title' => string 'Goss New Deal ' (length=14)
 
      'Dealer' => 
        array
          'id' => string '7' (length=1)
          'title' => string 'Goss New Deal ' (length=14)
  1 => 
    array
      'Product' => 
        array
          'id' => string '46' (length=2)
          'title' => string 'Product3' (length=8)
          'dealer_id' => string '2' (length=1)
          'description' => string 'Product3' (length=8)
          'Dealer' => 
            array
              ‘id’ => ‘2’
              'title' => string 'Tor Johnson School Of Drama' (length=27)
      'Dealer' => 
        array
          'id' => string '2' (length=1)
          'title' => string 'Tor Johnson School Of Drama' (length=27)
  2 => 
    array
      'Product' => 
        array
          'id' => string '50' (length=2)
          'title' => string 'Product1' (length=8)
          'dealer_id' => string '7' (length=1)
          'description' => string 'Product1 Updated 1X' (length=19)
          'Dealer' => 
            array
              'id' => string '7' (length=1)
              'title' => string 'Goss New Deal ' (length=14)
 
      'Dealer' => 
        array
          'id' => string '7' (length=1)
          'title' => string 'Goss New Deal ' (length=14)
  3 => 
    array
      'Product' => 
        array
          'id' => string '53' (length=2)
          'title' => string 'Product4' (length=8)
          'dealer_id' => string '2' (length=1)
          'description' => string 'Product4' (length=8)
          'Dealer' => 
            array
              'id' => string '2' (length=1)
              'title' => string 'Tor Johnson School Of Drama' (length=27)
 
      'Dealer' => 
        array
          'id' => string '2' (length=1)
          'title' => string 'Tor Johnson School Of Drama' (length=27)
  4 => 
    array
      'Product' => 
        array
          'id' => string '69' (length=2)
          'title' => string 'Product7' (length=8)
          'dealer_id' => string '30' (length=2)
          'description' => string 'Product7 not updated' (length=20)
          'Dealer' => 
            array
              'id' => string '30' (length=2)
              'title' => string 'Goss4' (length=5)
      'Dealer' => 
        array
          'id' => string '30' (length=2)
          'title' => string 'Goss4' (length=5)

Tor : Welcome billgoss

Products | Favorites | Login | Logout

Favorites

Id

Title

Dealer

Description

Actions

42

Product2

Goss New Deal

Product2 updated 7X

View Remove from Favorites

46

Product3

Tor Johnson School Of Drama

Product3

View Remove from Favorites

50

Product1

Goss New Deal

Product1 Updated 1X

View Remove from Favorites

53

Product4

Tor Johnson School Of Drama

Product4

View Remove from Favorites

69

Product7

Goss4

Product7 not updated

View Remove from Favorites

CakePHP: the rapid development php framework

14 queries took 24 ms

Nr

Query

Error

Affected

Num. rows

Took (ms)

1

DESCRIBE `aros`

 

7

7

4

2

DESCRIBE `acos`

 

7

7

4

3

DESCRIBE `aros_acos`

 

7

7

4

4

DESCRIBE `users`

 

6

6

3

5

DESCRIBE `products`

 

4

4

3

6

DESCRIBE `dealers`

 

2

2

3

7

DESCRIBE `products_users`

 

2

2

3

8

SELECT `User`.`id`, `User`.`username`, `User`.`password`, `User`.`email`, `User`.`first_name`, `User`.`last_name` FROM `users` AS `User` WHERE `User`.`username` = 'billgoss' LIMIT 1

 

1

1

0

9

SELECT `Product`.`id`, `Product`.`title`, `Product`.`dealer_id`, `Product`.`description`, `ProductsUser`.`product_id`, `ProductsUser`.`user_id` FROM `products` AS `Product` JOIN `products_users` AS `ProductsUser` ON (`ProductsUser`.`user_id` = 17 AND `ProductsUser`.`product_id` = `Product`.`id`) WHERE 1 = 1

 

5

5

0

10

SELECT `Dealer`.`id`, `Dealer`.`title` FROM `dealers` AS `Dealer` WHERE `Dealer`.`id` = 7

 

1

1

0

11

SELECT `Dealer`.`id`, `Dealer`.`title` FROM `dealers` AS `Dealer` WHERE `Dealer`.`id` = 2

 

1

1

0

12

SELECT `Dealer`.`id`, `Dealer`.`title` FROM `dealers` AS `Dealer` WHERE `Dealer`.`id` = 7

 

1

1

0

13

SELECT `Dealer`.`id`, `Dealer`.`title` FROM `dealers` AS `Dealer` WHERE `Dealer`.`id` = 2

 

1

1

0

14

SELECT `Dealer`.`id`, `Dealer`.`title` FROM `dealers` AS `Dealer` WHERE `Dealer`.`id` = 30

 

1

1

0