cakephp access array in view - php

I have a array looks like this:
Array
(
[0] => Array
(
[Project] => Array
(
[id] => 3
[title] => Title001
[created] => 0000-00-00 00:00:00
[modified] => 2013-08-05 17:39:07
)
[Keyword] => Array
(
[0] => Array
(
[id] => 1
[project_id] => 3
[title] => Num1
[demand] => 50000000000
[competition] => 37889.56700
[cpc] => 676.50
[created] => 2013-06-26 17:54:48
[modified] => 2013-09-19 13:37:25
)
[1] => Array
(
[id] => 13
[project_id] => 3
[title] => test
[demand] => 314
[competition] => 2341.00000
[cpc] => 9999.99
[created] => 2013-09-16 11:05:12
[modified] => 2013-09-16 11:05:12
)
)
)
[1] => Array
(
[Project] => Array
(
[id] => 4
[title] => Erdmann
[created] => 0000-00-00 00:00:00
[modified] =>
)
[Keyword] => Array
(
[0] => Array
(
[id] => 3
[project_id] => 4
[title] => Num5
[demand] => 76534000000
[competition] => 5555.55560
[cpc] => 99.34
[created] => 2013-06-26 17:54:48
[modified] => 2013-09-19 13:37:36
)
[1] => Array
(
[id] => 4
[project_id] => 4
[title] => Num anything
[demand] => 84000
[competition] => 8765.62340
[cpc] => 543.83
[created] => 2013-06-26 17:54:48
[modified] => 2013-09-11 12:08:50
)
)
)
[2] => Array
(
[Project] => Array
(
[id] => 5
[title] => Value
[created] => 2013-09-11 11:18:22
[modified] => 2013-09-11 11:18:22
)
[Keyword] => Array
(
[0] => Array
(
[id] => 2
[project_id] => 5
[title] => foo
[demand] => 4500000000
[competition] => 876.78500
[cpc] => 66.67
[created] => 2013-06-26 17:54:48
[modified] => 2013-09-19 13:37:32
)
[1] => Array
(
[id] => 5
[project_id] => 5
[title] => bar
[demand] => 5000568
[competition] => 667.56543
[cpc] => 667.60
[created] => 2013-06-26 17:54:48
[modified] => 2013-09-11 12:08:09
)
)
)
[3] => Array
(
[Project] => Array
(
[id] => 6
[title] => wolrd.net
[created] => 2013-09-16 11:23:42
[modified] => 2013-09-16 11:23:42
)
[Keyword] => Array
(
[0] => Array
(
[id] => 15
[project_id] => 6
[title] => Earth
[demand] => 5363
[competition] => 93479.34000
[cpc] => 5599.99
[created] => 2013-09-16 11:25:15
[modified] => 2013-09-16 11:26:15
)
)
)
)
What is the right way to access Title001 with all Keywords?

Related

Left join return duplicate data although I used GROUP BY

SQL:
$sql = "SELECT orders.*,order_products.*,products.*,psettings.*,cities.*,locations.* FROM orders
LEFT JOIN order_products ON orders.id=order_products.order_id
LEFT JOIN products ON products.id=order_products.product_id
LEFT JOIN psettings ON psettings.product_id=order_products.product_id
LEFT JOIN cities ON cities.id=orders.city_id
LEFT JOIN locations ON locations.id=orders.location_id
WHERE orders.status = '$status'
ORDER BY orders.id ASC ";
It returns unique data. Here is the returned data:
Array
(
[orders] => Array
(
[id] => 12
[name] => Abdus Sattar Bhuiyan
[email] => sattar.kuet#gmail.com
[mobile] => 01673050495
[alt_mobile] => 01818953250
[city_id] => 2
[location_id] => 5
[status] => confirmed
[cashed] => 1115
[created] => 2015-07-02 01:07:18
[modified] => 2015-07-02 01:01:57
[comment] => 07/02/2015 06:00 am
)
[city] => Array
(
[id] => 2
[name] => comilla
)
[location] => Array
(
[id] => 5
[city_id] => 2
[name] => homna
)
[order_products] => Array
(
[0] => Array
(
[id] => 10
[order_id] => 12
[product_id] => 1
[pieces] => 1
)
[1] => Array
(
[id] => 11
[order_id] => 12
[product_id] => 2
[pieces] => 1
)
[2] => Array
(
[id] => 12
[order_id] => 12
[product_id] => 3
[pieces] => 3
)
)
[products] => Array
(
[0] => Array
(
[id] => 1
[category_id] => 1
[name] => নভোযানের নাম সি প্রোগ্রামিং
[writer] => Engr. Abdus Sattar Bhuiyan
[created] => 2015-06-24 16:17:45
)
[1] => Array
(
[id] => 2
[category_id] => 1
[name] => Resonance of creativity with C++
[writer] => Engr. Abdus Sattar Bhuiyan
[created] => 2015-06-26 07:32:52
)
[2] => Array
(
[id] => 3
[category_id] => 1
[name] => programming by story C
[writer] => Hasibul Hasan Shanto
[created] => 2015-06-26 07:35:57
)
)
[psettings] => Array
(
[0] => Array
(
[id] => 1
[category_id] => 1
[product_id] => 1
[img] => 1.jpg
[desc] => description
[created] => 2015-06-29 15:15:58
[bppp] => 165
[sppp] => 300
[discount] => 20
[service_charge] => 30
)
[1] => Array
(
[id] => 2
[category_id] => 1
[product_id] => 2
[img] => 2.jpg
[desc] =>
[created] => 2015-06-26 07:33:41
[bppp] => 150
[sppp] => 250
[discount] => 20
[service_charge] => 30
)
[2] => Array
(
[id] => 3
[category_id] => 1
[product_id] => 3
[img] => 3.jpg
[desc] =>
[created] => 2015-06-26 07:36:26
[bppp] => 150
[sppp] => 250
[discount] => 10
[service_charge] => 30
)
)
)
But When I Add another table to join left with orders table it returns duplicate entry. Additionally I join left 'action_bies' with orders table as follows:
$sql = "SELECT orders.*,order_products.*,products.*,psettings.*,cities.*,locations.*,action_bies.* FROM orders
LEFT JOIN order_products ON orders.id=order_products.order_id
LEFT JOIN action_bies ON orders.id=action_bies.order_id AND action_bies.action='$action'
LEFT JOIN products ON products.id=order_products.product_id
LEFT JOIN psettings ON psettings.product_id=order_products.product_id
LEFT JOIN cities ON cities.id=orders.city_id
LEFT JOIN locations ON locations.id=orders.location_id
WHERE orders.status = '$status'
ORDER BY orders.id ASC ";
This sql return duplicate data. Here is the data:
Array
(
[orders] => Array
(
[id] => 12
[name] => Abdus Sattar Bhuiyan
[email] => sattar.kuet#gmail.com
[mobile] => 01673050495
[alt_mobile] => 01818953250
[city_id] => 2
[location_id] => 5
[status] => confirmed
[cashed] => 1115
[created] => 2015-07-02 01:07:18
[modified] => 2015-07-02 01:01:57
[comment] => 07/02/2015 06:00 am
)
[city] => Array
(
[id] => 2
[name] => comilla
)
[location] => Array
(
[id] => 5
[city_id] => 2
[name] => homna
)
[action] => Array
(
[0] => Array
(
[id] => 1
[action] => confirm
[admin_id] => 30
[order_id] => 12
[created] => 0000-00-00 00:00:00
)
[1] => Array
(
[id] => 4
[action] => confirm
[admin_id] => 30
[order_id] => 12
[created] => 2015-07-02 00:00:00
)
[2] => Array
(
[id] => 5
[action] => confirm
[admin_id] => 30
[order_id] => 12
[created] => 2015-07-02 00:00:00
)
[3] => Array
(
[id] => 1
[action] => confirm
[admin_id] => 30
[order_id] => 12
[created] => 0000-00-00 00:00:00
)
[4] => Array
(
[id] => 4
[action] => confirm
[admin_id] => 30
[order_id] => 12
[created] => 2015-07-02 00:00:00
)
[5] => Array
(
[id] => 5
[action] => confirm
[admin_id] => 30
[order_id] => 12
[created] => 2015-07-02 00:00:00
)
[6] => Array
(
[id] => 1
[action] => confirm
[admin_id] => 30
[order_id] => 12
[created] => 0000-00-00 00:00:00
)
[7] => Array
(
[id] => 4
[action] => confirm
[admin_id] => 30
[order_id] => 12
[created] => 2015-07-02 00:00:00
)
[8] => Array
(
[id] => 5
[action] => confirm
[admin_id] => 30
[order_id] => 12
[created] => 2015-07-02 00:00:00
)
)
[order_products] => Array
(
[0] => Array
(
[id] => 10
[order_id] => 12
[product_id] => 1
[pieces] => 1
)
[1] => Array
(
[id] => 10
[order_id] => 12
[product_id] => 1
[pieces] => 1
)
[2] => Array
(
[id] => 10
[order_id] => 12
[product_id] => 1
[pieces] => 1
)
[3] => Array
(
[id] => 11
[order_id] => 12
[product_id] => 2
[pieces] => 1
)
[4] => Array
(
[id] => 11
[order_id] => 12
[product_id] => 2
[pieces] => 1
)
[5] => Array
(
[id] => 11
[order_id] => 12
[product_id] => 2
[pieces] => 1
)
[6] => Array
(
[id] => 12
[order_id] => 12
[product_id] => 3
[pieces] => 3
)
[7] => Array
(
[id] => 12
[order_id] => 12
[product_id] => 3
[pieces] => 3
)
[8] => Array
(
[id] => 12
[order_id] => 12
[product_id] => 3
[pieces] => 3
)
)
[products] => Array
(
[0] => Array
(
[id] => 1
[category_id] => 1
[name] => নভোযানের নাম সি প্রোগ্রামিং
[writer] => Engr. Abdus Sattar Bhuiyan
[created] => 2015-06-24 16:17:45
)
[1] => Array
(
[id] => 1
[category_id] => 1
[name] => নভোযানের নাম সি প্রোগ্রামিং
[writer] => Engr. Abdus Sattar Bhuiyan
[created] => 2015-06-24 16:17:45
)
[2] => Array
(
[id] => 1
[category_id] => 1
[name] => নভোযানের নাম সি প্রোগ্রামিং
[writer] => Engr. Abdus Sattar Bhuiyan
[created] => 2015-06-24 16:17:45
)
[3] => Array
(
[id] => 2
[category_id] => 1
[name] => Resonance of creativity with C++
[writer] => Engr. Abdus Sattar Bhuiyan
[created] => 2015-06-26 07:32:52
)
[4] => Array
(
[id] => 2
[category_id] => 1
[name] => Resonance of creativity with C++
[writer] => Engr. Abdus Sattar Bhuiyan
[created] => 2015-06-26 07:32:52
)
[5] => Array
(
[id] => 2
[category_id] => 1
[name] => Resonance of creativity with C++
[writer] => Engr. Abdus Sattar Bhuiyan
[created] => 2015-06-26 07:32:52
)
[6] => Array
(
[id] => 3
[category_id] => 1
[name] => programming by story C
[writer] => Hasibul Hasan Shanto
[created] => 2015-06-26 07:35:57
)
[7] => Array
(
[id] => 3
[category_id] => 1
[name] => programming by story C
[writer] => Hasibul Hasan Shanto
[created] => 2015-06-26 07:35:57
)
[8] => Array
(
[id] => 3
[category_id] => 1
[name] => programming by story C
[writer] => Hasibul Hasan Shanto
[created] => 2015-06-26 07:35:57
)
)
[psettings] => Array
(
[0] => Array
(
[id] => 1
[category_id] => 1
[product_id] => 1
[img] => 1.jpg
[desc] => description
[created] => 2015-06-29 15:15:58
[bppp] => 165
[sppp] => 300
[discount] => 20
[service_charge] => 30
)
[1] => Array
(
[id] => 1
[category_id] => 1
[product_id] => 1
[img] => 1.jpg
[desc] => description
[created] => 2015-06-29 15:15:58
[bppp] => 165
[sppp] => 300
[discount] => 20
[service_charge] => 30
)
[2] => Array
(
[id] => 1
[category_id] => 1
[product_id] => 1
[img] => 1.jpg
[desc] => description
[created] => 2015-06-29 15:15:58
[bppp] => 165
[sppp] => 300
[discount] => 20
[service_charge] => 30
)
[3] => Array
(
[id] => 2
[category_id] => 1
[product_id] => 2
[img] => 2.jpg
[desc] =>
[created] => 2015-06-26 07:33:41
[bppp] => 150
[sppp] => 250
[discount] => 20
[service_charge] => 30
)
[4] => Array
(
[id] => 2
[category_id] => 1
[product_id] => 2
[img] => 2.jpg
[desc] =>
[created] => 2015-06-26 07:33:41
[bppp] => 150
[sppp] => 250
[discount] => 20
[service_charge] => 30
)
[5] => Array
(
[id] => 2
[category_id] => 1
[product_id] => 2
[img] => 2.jpg
[desc] =>
[created] => 2015-06-26 07:33:41
[bppp] => 150
[sppp] => 250
[discount] => 20
[service_charge] => 30
)
[6] => Array
(
[id] => 3
[category_id] => 1
[product_id] => 3
[img] => 3.jpg
[desc] =>
[created] => 2015-06-26 07:36:26
[bppp] => 150
[sppp] => 250
[discount] => 10
[service_charge] => 30
)
[7] => Array
(
[id] => 3
[category_id] => 1
[product_id] => 3
[img] => 3.jpg
[desc] =>
[created] => 2015-06-26 07:36:26
[bppp] => 150
[sppp] => 250
[discount] => 10
[service_charge] => 30
)
[8] => Array
(
[id] => 3
[category_id] => 1
[product_id] => 3
[img] => 3.jpg
[desc] =>
[created] => 2015-06-26 07:36:26
[bppp] => 150
[sppp] => 250
[discount] => 10
[service_charge] => 30
)
)
)
Here it should be mentioned that a action_bies table has duplicate data as follows:
How can I get unique data in this case. Thanks to read this large data.
You can select DISTINCT on the most unique identifier you have, which would be orders_products.id most likely.
Example:
SELECT DISTINCT(orders_products.id) FROM orders_products WHERE x = '$y';
I don't see a GROUP BY statement in your original query.

How to re-arrange Array in php

Array
(
[0] => Array
(
[Product] => Array
(
[id] => 5
[user_id] => 5
[category_id] => 1
[name] => Suger
[weight] => 1
[measurement] => kg
[image] =>
[status] => 1
[created] => 2015-05-29 17:02:25
[updated] => 0000-00-00 00:00:00
)
[Category] => Array
(
[id] => 1
[user_id] => 1
[category_name] => Daily uses
[category_image] =>
[status] => 1
[created] => 2015-05-25 12:56:10
[updated] => 2015-06-25 10:27:40
)
[Storeproduct] => Array
(
[0] => Array
(
[id] => 23
[product_id] => 5
[store_id] => 2
[details] =>
[mrp] => 10
[selling_price] => 10
[discount] => 0
[price_difference] => 0
[is_deal] => 0
[deal_start_date] =>
[deal_end_date] =>
[status] => 1
[created] => 1435055384
[updated] => 1435055384
)
[1] => Array
(
[id] => 28
[product_id] => 5
[store_id] => 1
[details] =>
[mrp] => 10
[selling_price] => 10
[discount] => 0
[price_difference] => 0
[is_deal] => 0
[deal_start_date] =>
[deal_end_date] =>
[status] => 1
[created] => 1435062129
[updated] => 1435062129
)
)
)
[1] => Array
(
[Product] => Array
(
[id] => 6
[user_id] => 1
[category_id] => 1
[name] => Tea
[weight] => 1
[measurement] => litre
[image] =>
[status] => 1
[created] => 2015-05-29 17:02:48
[updated] => 2015-06-18 18:53:30
)
[Category] => Array
(
[id] => 1
[user_id] => 1
[category_name] => Daily uses
[category_image] =>
[status] => 1
[created] => 2015-05-25 12:56:10
[updated] => 2015-06-25 10:27:40
)
[Storeproduct] => Array
(
[0] => Array
(
[id] => 22
[product_id] => 6
[store_id] => 2
[details] =>
[mrp] => 10
[selling_price] => 10
[discount] => 0
[price_difference] => 0
[is_deal] => 0
[deal_start_date] =>
[deal_end_date] =>
[status] => 1
[created] => 1435055076
[updated] => 1435055076
)
[1] => Array
(
[id] => 25
[product_id] => 6
[store_id] => 1
[details] =>
[mrp] => 12
[selling_price] => 12
[discount] => 0
[price_difference] => 0
[is_deal] => 0
[deal_start_date] =>
[deal_end_date] =>
[status] => 1
[created] => 1435059905
[updated] => 1435059905
)
)
)
[5] => Array
(
[Product] => Array
(
[id] => 11
[user_id] => 2
[category_id] => 13
[name] => Real Mix Fruit Juice
[weight] => 200
[measurement] => litre
[image] =>
[status] => 1
[created] => 2015-06-17 12:03:19
[updated] => 2015-06-18 13:05:16
)
[Category] => Array
(
[id] => 13
[user_id] => 2
[category_name] => Soft Drink juices
[category_image] =>
[status] => 1
[created] => 2015-06-17 11:15:33
[updated] => 2015-06-18 18:46:03
)
[Storeproduct] => Array
(
[0] => Array
(
[id] => 2
[product_id] => 11
[store_id] => 2
[details] => Real Mix Fruit Juice(200 litre)
[mrp] => 20
[selling_price] => 18
[discount] => 10
[price_difference] => 2
[is_deal] => 0
[deal_start_date] =>
[deal_end_date] =>
[status] => 1
[created] => 1434613767
[updated] => 1434613767
)
[1] => Array
(
[id] => 29
[product_id] => 11
[store_id] => 1
[details] => Real Mix Fruit Juice
[mrp] => 10
[selling_price] => 10
[discount] => 0
[price_difference] => 0
[is_deal] => 0
[deal_start_date] =>
[deal_end_date] =>
[status] => 1
[created] => 1435062192
[updated] => 1435123348
)
)
)
[8] => Array
(
[Product] => Array
(
[id] => 14
[user_id] => 2
[category_id] => 13
[name] => Real Apple Juice
[weight] => 1
[measurement] => ml
[image] =>
[status] => 1
[created] => 2015-06-18 13:06:44
[updated] => 0000-00-00 00:00:00
)
[Category] => Array
(
[id] => 13
[user_id] => 2
[category_name] => Soft Drink juices
[category_image] =>
[status] => 1
[created] => 2015-06-17 11:15:33
[updated] => 2015-06-18 18:46:03
)
[Storeproduct] => Array
(
[0] => Array
(
[id] => 24
[product_id] => 14
[store_id] => 2
[details] =>
[mrp] => 10
[selling_price] => 10
[discount] => 0
[price_difference] => 0
[is_deal] => 0
[deal_start_date] =>
[deal_end_date] =>
[status] => 1
[created] => 1435055411
[updated] => 1435055411
)
)
)
)
In the above array there are two same category array .I would like merge the same category array records
I need a output like
Category => array(
//category data,
Products=>array(//product data,
Storeproducts =>array(
//Storeproducts data
)
)
)
PHP is pretty well documented and you can find all of the Array sorting methods on this page.
There are some good examples in the comments as well - all you need to do is to sort the array by category and you are done.

How to print assosiative array data

Array
(
[0] => stdClass Object
(
[id] => 7
[price] => 1300
[discount] => 13
[early_bird_date] => 2014-12-30
[timing] =>
[batch] =>
[slug] =>
[status] => 1
[ktw_course_id] => 5
[ktw_country_id] => 2
[ktw_city_id] => 5
[ktw_timeslot_id] => 0
[ktw_training_mode_id] => 3
[ktw_currency_id] => 6
[created] =>
[modified] =>
[course] => jquery
[country] => kuwait
[city] => dubai
[currency] => EUR
[workshop_dates] => Array
(
[0] => stdClass Object
(
[id] => 7
[start_date] => 2014-11-04
[end_date] => 2015-01-05
[status] => 1
[ktw_workshop_id] => 7
[created] => 2014-11-28 06:09:41
[modified] => 2014-11-28 06:09:41
)
[1] => stdClass Object
(
[id] => 8
[start_date] => 2015-01-06
[end_date] => 2015-01-07
[status] => 1
[ktw_workshop_id] => 7
[created] => 2014-11-28 06:09:55
[modified] => 2014-11-28 06:09:55
)
[2] => stdClass Object
(
[id] => 9
[start_date] => 2015-01-08
[end_date] => 2015-01-09
[status] => 1
[ktw_workshop_id] => 7
[created] => 2014-11-28 06:10:15
[modified] => 2014-11-28 06:10:15
)
)
)
[1] => stdClass Object
(
[id] => 5
[price] => 900
[discount] => 13
[early_bird_date] => 2014-11-26
[timing] =>
[batch] =>
[slug] =>
[status] => 1
[ktw_course_id] => 5
[ktw_country_id] => 1
[ktw_city_id] => 2
[ktw_timeslot_id] => 0
[ktw_training_mode_id] => 1
[ktw_currency_id] => 1
[created] =>
[modified] => 2014-11-14 14:34:29
[course] => jquery
[country] => india
[city] => vizag
[currency] => INR
[workshop_dates] => Array
(
[0] => stdClass Object
(
[id] => 2
[start_date] => 2014-11-28
[end_date] => 2014-11-29
[status] => 1
[ktw_workshop_id] => 5
[created] =>
[modified] =>
)
)
)
[2] => stdClass Object
(
[id] => 6
[price] => 1300
[discount] => 13
[early_bird_date] => 2014-12-30
[timing] =>
[batch] =>
[slug] =>
[status] => 1
[ktw_course_id] => 5
[ktw_country_id] => 1
[ktw_city_id] => 4
[ktw_timeslot_id] => 0
[ktw_training_mode_id] => 2
[ktw_currency_id] => 1
[created] =>
[modified] => 2014-11-25 10:16:58
[course] => jquery
[country] => india
[city] => hyderabad
[currency] => INR
[workshop_dates] => Array
(
[0] => stdClass Object
(
[id] => 4
[start_date] => 2014-12-30
[end_date] => 2014-12-31
[status] => 1
[ktw_workshop_id] => 6
[created] => 2014-11-28 06:08:44
[modified] => 2014-11-28 06:08:44
)
[1] => stdClass Object
(
[id] => 5
[start_date] => 2014-12-31
[end_date] => 2015-01-01
[status] => 1
[ktw_workshop_id] => 6
[created] => 2014-11-28 06:08:59
[modified] => 2014-11-28 06:08:59
)
[2] => stdClass Object
(
[id] => 6
[start_date] => 2015-01-02
[end_date] => 2015-01-03
[status] => 1
[ktw_workshop_id] => 6
[created] => 2014-11-28 06:09:14
[modified] => 2014-11-28 06:09:14
)
)
)
)
i want to print start_date and end _date ,please help me how can i get it.
thanks in advance.
This is very beginner level question.
foreach ($YourVariable as $arr_of_objs ) {
foreach ($arr_of_objs->workshop_dates as $obj) {
echo $obj->start_date;
echo $obj->end_date;
# code...
}
}
Try this -
$obj = //your object
$newArray = (array)$obj;//converting object to array
foreach ($newArray as $val) {
foreach ($val['workshop_dates'] as $value) {
echo $value['start_date']. ' ' .$value['end_date'];
}
}
Assuming the objects are implementing ArrayAccess. You would do:
foreach ($object as $obj) {
foreach($obj[workshop_dates] as $workshopdate) {
$startDate = $workshopdate ['start_date'];
$endDate = $workshopdate ['end_date'];
}
}

CakePHP Threaded "Find" with Associated Models

I am using a $this->find('threaded') in my CakePHP application and am trying to pull in an associated model within the find (HABTM). I have tried several methods, such as 'joins', 'recursive' and 'contains' all with no luck. I am using CakePHP 2.3.6
Here is my (working) code.
class EventsController extends AppController {
public function promoters($id = null) {
$options = array('conditions' => array('Event.id' => $id));
$event = $this->Event->find('first', $options);
$this->set('event', $event);
$this->loadModel('EventsPromoter');
$treelistConditions = array(
'conditions' => array(
'event_id' => $id
),
);
$promoterTree = $this->EventsPromoter->find('threaded', $treelistConditions);
$this->set('promoters', $promoterTree);
}
}
This results in the following array output
Array
(
[0] => Array
(
[EventsPromoter] => Array
(
[id] => 1
[promoter_id] => 1
[event_id] => 1
[parent_id] =>
[created] => 2013-07-26 00:30:09
[modified] => 2013-07-26 00:30:09
)
[children] => Array
(
[0] => Array
(
[EventsPromoter] => Array
(
[id] => 10
[promoter_id] => 4
[event_id] => 1
[parent_id] => 1
[created] => 0000-00-00 00:00:00
[modified] => 0000-00-00 00:00:00
)
[children] => Array
(
)
)
[1] => Array
(
[EventsPromoter] => Array
(
[id] => 13
[promoter_id] => 6
[event_id] => 1
[parent_id] => 1
[created] => 0000-00-00 00:00:00
[modified] => 0000-00-00 00:00:00
)
[children] => Array
(
)
)
)
)
[1] => Array
(
[EventsPromoter] => Array
(
[id] => 2
[promoter_id] => 2
[event_id] => 1
[parent_id] =>
[created] => 2013-07-26 00:30:09
[modified] => 2013-07-26 00:30:09
)
[children] => Array
(
[0] => Array
(
[EventsPromoter] => Array
(
[id] => 11
[promoter_id] => 5
[event_id] => 1
[parent_id] => 2
[created] => 0000-00-00 00:00:00
[modified] => 0000-00-00 00:00:00
)
[children] => Array
(
[0] => Array
(
[EventsPromoter] => Array
(
[id] => 6
[promoter_id] => 3
[event_id] => 1
[parent_id] => 11
[created] => 0000-00-00 00:00:00
[modified] => 0000-00-00 00:00:00
)
[children] => Array
(
)
)
)
)
[1] => Array
(
[EventsPromoter] => Array
(
[id] => 14
[promoter_id] => 7
[event_id] => 1
[parent_id] => 2
[created] => 2013-07-26 00:30:09
[modified] => 2013-07-26 00:30:09
)
[children] => Array
(
)
)
)
)
)
What I would like my code to output is the following
Array
(
[0] => Array
(
[EventsPromoter] => Array
(
[id] => 1
[promoter_id] => 1
[event_id] => 1
[parent_id] =>
[created] => 2013-07-26 00:30:09
[modified] => 2013-07-26 00:30:09
)
[Promoter] => Array
(
[promoter_id] => 1
[first_name] => 'Bob'
[last_name] => 'Smith'
)
[children] => Array
(
[0] => Array
(
[EventsPromoter] => Array
(
[id] => 10
[promoter_id] => 4
[event_id] => 1
[parent_id] => 1
[created] => 0000-00-00 00:00:00
[modified] => 0000-00-00 00:00:00
)
[Promoter] => Array
(
[promoter_id] => 4
[first_name] => 'Sally'
[last_name] => 'Sue'
)
[children] => Array
(
)
)
[1] => Array
(
[EventsPromoter] => Array
(
[id] => 13
[promoter_id] => 6
[event_id] => 1
[parent_id] => 1
[created] => 0000-00-00 00:00:00
[modified] => 0000-00-00 00:00:00
)
[Promoter] => Array
(
[promoter_id] => 6
[first_name] => 'Ben'
[last_name] => 'King'
)
[children] => Array
(
)
)
)
)
[1] => Array
(
[EventsPromoter] => Array
(
[id] => 2
[promoter_id] => 2
[event_id] => 1
[parent_id] =>
[created] => 2013-07-26 00:30:09
[modified] => 2013-07-26 00:30:09
)
[Promoter] => Array
(
[promoter_id] => 2
[first_name] => 'Jack'
[last_name] => 'Sparrow'
)
[children] => Array
(
[0] => Array
(
[EventsPromoter] => Array
(
[id] => 11
[promoter_id] => 5
[event_id] => 1
[parent_id] => 2
[created] => 0000-00-00 00:00:00
[modified] => 0000-00-00 00:00:00
)
[Promoter] => Array
(
[promoter_id] => 5
[first_name] => 'Jane'
[last_name] => 'Doe'
)
[children] => Array
(
[0] => Array
(
[EventsPromoter] => Array
(
[id] => 6
[promoter_id] => 3
[event_id] => 1
[parent_id] => 11
[created] => 0000-00-00 00:00:00
[modified] => 0000-00-00 00:00:00
)
[Promoter] => Array
(
[promoter_id] => 3
[first_name] => 'Mike'
[last_name] => 'Jones'
)
[children] => Array
(
)
)
)
)
[1] => Array
(
[EventsPromoter] => Array
(
[id] => 14
[promoter_id] => 7
[event_id] => 1
[parent_id] => 2
[created] => 2013-07-26 00:30:09
[modified] => 2013-07-26 00:30:09
)
[Promoter] => Array
(
[promoter_id] => 7
[first_name] => 'Spider'
[last_name] => 'Man'
)
[children] => Array
(
)
)
)
)
)
Nothing I have been trying is working, and this seems like something Cake should be able to handle fairly easily. Thanks in advance for any help!
I was taking a slightly wrong approach for what I was trying to accomplish. While I still think this should be possible from my EventsController class, I elected to make it in the EventsPromotersController HABTM class. The code is much simpler using this method
class EventsPromotersController extends AppController {
public function event($event_id = null) {
$options = array('conditions' => array('event_id' => $event_id));
$promoters = $this->EventsPromoter->find('threaded', $options);
$this->set('promoters', $promoters);
}
}

Merging array for parent category in Cakephp

I want to be able to group SpecificationCategory.name as parent category and Specifications under as children so that SpecificationCategory.name does not get repeated in the array.
Is there a way to do this in Cake?
Array
(
[0] => Array
(
[Specification] => Array
(
[id] => 15
[name] => AMD Phenom
[specification_category_id] => 1
[subsubcategory_id] => 1
[created] => 2012-10-16 08:18:27
[modified] => 2012-10-16 08:18:27
)
[SpecificationCategory] => Array
(
[id] => 1
[name] => Processor Type
[created] => 2012-10-15 13:50:03
[modified] => 2012-10-15 13:50:03
)
[Subsubcategory] => Array
(
[id] => 1
[name] => Laptops
[subcategory_id] => 1
[created] => 2012-06-24 02:23:40
[modified] => 2012-06-24 02:23:40
)
)
[1] => Array
(
[Specification] => Array
(
[id] => 12
[name] => AMD E350
[specification_category_id] => 1
[subsubcategory_id] => 1
[created] => 2012-10-16 08:18:02
[modified] => 2012-10-16 08:18:02
)
[SpecificationCategory] => Array
(
[id] => 1
[name] => Processor Type
[created] => 2012-10-15 13:50:03
[modified] => 2012-10-15 13:50:03
)
[Subsubcategory] => Array
(
[id] => 1
[name] => Laptops
[subcategory_id] => 1
[created] => 2012-06-24 02:23:40
[modified] => 2012-06-24 02:23:40
)
)
)
If your just trying to get a listing by SpecificationCategory I would just do the find from that model and the array would list all Specifications under each category. This assumes Specifications hasMany SpecificationCategory.

Categories