Cakephp Containable not attaching to Model - php

I've used containable tons of times but I can not figure for the life of me why it is not working correctly now.
I have 3 models Project, User, and Country.
Project belongsTo User
User belongsTo Country
here is the models
<?php
class User extends AppModel {
var $name = 'User';
var $displayField = 'username';
var $belongsTo = array(
'AccountType' => array(
'className' => 'AccountType',
'foreignKey' => 'account_type_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'PaymentType' => array(
'className' => 'PaymentType',
'foreignKey' => 'payment_type_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Country' => array(
'className' => 'Country',
'foreignKey' => 'country_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'InstantMessenger' => array(
'className' => 'InstantMessenger',
'foreignKey' => 'instant_messenger_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'TimeZone' => array(
'className' => 'TimeZone',
'foreignKey' => 'time_zone_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Language' => array(
'className' => 'Language',
'foreignKey' => 'language_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
);
}
<?php
class Project extends AppModel {
var $name = 'Project';
var $displayField = 'project_title';
var $belongsTo = array(
'User' => array(
'className' => 'User',
'conditions' => '',
'fields' => '',
'order' => ''
),
'ProjectType' => array(
'className' => 'ProjectType',
'foreignKey' => 'project_type_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'BiddingType' => array(
'className' => 'BiddingType',
'foreignKey' => 'bidding_type_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'ProjectStatus' => array(
'className' => 'ProjectStatus',
'foreignKey' => 'project_status',
'conditions' => '',
'fields' => '',
'order' => ''
),
'EmploymentType',
'PaymentType',
);
}
<?php
class Country extends AppModel {
var $name = 'Country';
var $displayField = 'name';
//The Associations below have been created with all possible keys, those that are not needed can be removed
var $hasMany = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'country_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
}
Now here is my code to try to attach a containable to project and add User
function smartbid($projid = null)
{
$this->loadModel('Content');
$content = $this->Content->findById(53);
$this->set('content',$content);
$this->Project->Behaviors->attach('Containable');
$options = array(
array(
'conditions'=>
array(
'Project.id'=>$projid
),
'contain'=>array(
'User'
)
)
);
$project = $this->Project->find('first',$options);
$this->set(compact('project'));
}
Now cakephp completely ignores my attached containable and returns this
Array
(
[Project] => Array
(
[id] => 1
[user_id] => 19
[status] => 1
[approval_status] => 0
[project_status] => 2
[approval_date] => 2012-02-08
[project_title] => Database Reporting
[project_type_id] => 3
[budget] => 100
[bidding_type_id] => 1
[employment_type_id] =>
[esl] => 1
[secrecy] => 0
[secrecy_file] =>
[description] => this is my first post
[performance] => 0
[cme] => 6
[files_share] =>
[project_deadline] => 1
[delivery_deadline] => 2012-02-16
[bidding_deadline] => 2012-02-27
[legal] => 1)Employer requires complete and fully-functional working program(s) in executable form as well as complete source code of all work done.
2) Deliverables must be in ready-to-run condition as follows (depending on the nature of the project and deliverables):
2a) If there are any server-side deliverables (intended to only exist in one place in the Employer's environment) then they must be installed by the Consultant in ready-to-run condition (unless specified elsewhere by the Employer).
2b) All other software (including but not limited to any desktop software or software the Employer intends to distribute) must include a software installation package that will install the software in ready-to-run condition on the platform(s) specified in this project (unless specified elsewhere by the Employer).
3) All deliverables will be considered 'work made for hire' under U.S. Copyright law. Employer will receive exclusive and complete copyrights to all work purchased.
3b) No part of the deliverable may contain any copyright restricted 3rd party components (including GPL, GNU, Copyleft, etc.) unless all copyright ramifications are explained AND AGREED TO by the Employer on the site per the Consultant's Worker Legal Agreement.
[close] => 0
[agree] => 1
[created] => 2012-02-06
[top_employer] => 0
[view_counter] => 41
[pause_deadline] =>
[payment_type_id] =>
[status_date] => 2012-02-08
[redeem_amount] =>
)
[User] => Array
(
[id] => 19
[username] => EmployerWarrior
[password] => 7c6a180b36896a0a8c02787eeafb0e4c
[account_type_id] => 2
[picture] =>
[resume] =>
[alert] => 0
[first_name] => Yaser
[last_name] => Ibrahim
[company_name] => Software Momentum, Inc.
[company_incorporated] => 1
[email] => Yaser43082#hotmail.com
[address] => 123 Somewhere
[apartment_number] =>
[city] => Some City
[state] => Some State
[country_id] => 1
[phone_city] => 614
[phone_country] => 1
[phone_number] => 1234567
[fax_city] =>
[fax_country] =>
[fax_number] =>
[instant_messenger_id] => 1
[im_username] =>
[postal] => 43082
[time_zone_id] => 58
[language_id] => 23
[esl] => 1
[us_resident] => 1
[ssnum] => 1234567
[have_ssnum] => 1
[work_permit_number] =>
[alien_number] =>
[work_permit] => 0
[green_card] => 0
[payment_type_id] => 4
[ip] =>
[created] => 2012-02-06 08:59:35
[top_employer] => 0
[top_consultant] => 0
[rating] => 0
[money_invested] => 0
[money_earned] => 0
[total_projects] => 0
[last_project] => 0
[active] => 0
[last_login] =>
[last_seen] => 2012-02-26 14:13:08
[is_logged_in] => 0
[time_format_id] => 1
[paypal_id] =>
[momentum_expiration] => 2014-02-12
)
[ProjectType] => Array
(
[id] => 3
[name] => Small Business Project
[min] => 100
[max] => 499.99
[order] => 4
)
[BiddingType] => Array
(
[id] => 1
[type] => Public Bidding
[percentage] => 15
)
[ProjectStatus] => Array
(
[id] => 2
[status] => Open Bids
[icon] => bid_open.png
[order] => 3
[default] => 1
)
[EmploymentType] => Array
(
[id] =>
[name] =>
)
[PaymentType] => Array
(
[id] =>
[type] =>
)
[BidWinner] => Array
(
[id] =>
[comment_group_id] =>
[bid_status_id] =>
[project_id] =>
[bid_amount] =>
[performance_guaranteed] =>
[isSmartBid] =>
[user_id] =>
[comment] =>
[isWinner] =>
[created] =>
)
[HRWWallet] => Array
(
[id] => 1
[user_id] => 19
[account_type_id] =>
[entity_id] => 1
[payment_type_id] => 1
[entity_type_id] => 1
[payment_to_id] =>
[payment_status_id] => 2
[payment_number] =>
[service_id] => 4
[created] => 2012-02-10 18:45:52
[description] => Payment for project
[credit] => 100
[debit] => 0
[billing_address] =>
[billing_city] =>
[billing_state] =>
[billing_country_id] =>
[billing_name] =>
[exp_year] =>
[exp_month] =>
[security_code] =>
)
[EmployerRating] => Array
(
[id] =>
[owner_id] =>
[project_id] =>
[rated_by_id] =>
[account_type_id] =>
[rating] =>
[comment] =>
[created] =>
)
[ConsultantRating] => Array
(
[id] =>
[owner_id] =>
[project_id] =>
[rated_by_id] =>
[account_type_id] =>
[rating] =>
[comment] =>
[created] =>
)
[Arbitration] => Array
(
[id] => 5
[project_id] => 1
[defendent_id] => 20
[plantiff_id] => 19
[magistrate_id] => 17
[arbitration_status_id] => 1
[verdict] =>
[created] => 2012-02-11 23:00:00
[end] =>
)
[Bid] => Array
(
[0] => Array
(
[id] => 1
[comment_group_id] => 1
[bid_status_id] => 1
[project_id] => 1
[bid_amount] => 75
[performance_guaranteed] => 10
[isSmartBid] => 0
[user_id] => 20
[comment] => Hi, I was writing about your project
[isWinner] =>
[created] => 2012-02-08 14:15:04
)
[1] => Array
(
[id] => 2
[comment_group_id] => 2
[bid_status_id] => 1
[project_id] => 1
[bid_amount] => 100
[performance_guaranteed] => 25
[isSmartBid] => 0
[user_id] => 18
[comment] => I can do this work
[isWinner] =>
[created] => 2012-02-08 14:16:39
)
[2] => Array
(
[id] => 5
[comment_group_id] => 2
[bid_status_id] => 1
[project_id] => 1
[bid_amount] => 45
[performance_guaranteed] => 10
[isSmartBid] => 1
[user_id] => 18
[comment] => This is a smart bid bid
[isWinner] => 0
[created] => 2012-02-25 15:40:54
)
)
[PaymentTransaction] => Array
(
[0] => Array
(
[id] => 1
[user_id] => 19
[account_type_id] =>
[entity_id] => 1
[payment_type_id] => 1
[entity_type_id] => 1
[payment_to_id] =>
[payment_status_id] => 2
[payment_number] =>
[service_id] => 4
[created] => 2012-02-10 18:45:52
[description] => Payment for project
[credit] => 100
[debit] => 0
[billing_address] =>
[billing_city] =>
[billing_state] =>
[billing_country_id] =>
[billing_name] =>
[exp_year] =>
[exp_month] =>
[security_code] =>
)
)
[WorkAcceptanceLog] => Array
(
)
[Comment] => Array
(
[0] => Array
(
[id] => 1
[comment_group_id] => 1
[project_id] => 1
[to_id] => 19
[from_id] => 20
[cc_id] =>
[isArbitration] =>
[no_contest] =>
[subject] => Re:
[comment] => Hi, I was writing about your project
[created] => 2012-02-08 14:15:04
[file_name] =>
[parent_id] =>
[last_message] =>
)
[1] => Array
(
[id] => 2
[comment_group_id] => 2
[project_id] => 1
[to_id] => 19
[from_id] => 18
[cc_id] =>
[isArbitration] =>
[no_contest] =>
[subject] => Re:
[comment] => I can do this work
[created] => 2012-02-08 14:16:39
[file_name] =>
[parent_id] =>
[last_message] =>
)
[2] => Array
(
[id] => 3
[comment_group_id] => 2
[project_id] => 1
[to_id] => 18
[from_id] => 19
[cc_id] =>
[isArbitration] =>
[no_contest] =>
[subject] => Broadcasted Message
[comment] => This is a broadcast to all consultants in regards to the project.
[created] => 2012-02-08 14:18:52
[file_name] =>
[parent_id] =>
[last_message] => 2012-02-08 14:18:51
)
[3] => Array
(
[id] => 4
[comment_group_id] => 1
[project_id] => 1
[to_id] => 20
[from_id] => 19
[cc_id] =>
[isArbitration] =>
[no_contest] =>
[subject] => Broadcasted Message
[comment] => This is a broadcast to all consultants in regards to the project.
[created] => 2012-02-08 14:18:52
[file_name] =>
[parent_id] =>
[last_message] => 2012-02-08 14:18:52
)
[4] => Array
(
[id] => 7
[comment_group_id] => 0
[project_id] => 1
[to_id] => 19
[from_id] => 27
[cc_id] => 20
[isArbitration] => 1
[no_contest] =>
[subject] => Arbitration
[comment] => What seems to be the issue ?
[created] => 2012-02-12 18:28:11
[file_name] =>
[parent_id] =>
[last_message] =>
)
[5] => Array
(
[id] => 8
[comment_group_id] => 5
[project_id] => 1
[to_id] => 17
[from_id] => 19
[cc_id] => 20
[isArbitration] => 1
[no_contest] =>
[subject] => Arbitration
[comment] => Well I would like to say I am not happy
[created] => 2012-02-12 19:35:51
[file_name] =>
[parent_id] =>
[last_message] =>
)
[6] => Array
(
[id] => 9
[comment_group_id] => 6
[project_id] => 1
[to_id] => 17
[from_id] => 19
[cc_id] => 20
[isArbitration] => 1
[no_contest] =>
[subject] => Arbitration
[comment] => I would like to make a complaint
[created] => 2012-02-12 22:07:08
[file_name] =>
[parent_id] =>
[last_message] =>
)
[7] => Array
(
[id] => 10
[comment_group_id] => 2
[project_id] => 1
[to_id] => 19
[from_id] => 18
[cc_id] =>
[isArbitration] =>
[no_contest] =>
[subject] => Re:Broadcasted Message
[comment] => This is a smart bid bid
[created] => 2012-02-25 15:40:54
[file_name] =>
[parent_id] =>
[last_message] =>
)
)
)
as you can see it ignores my attachment. what am i doing wrong.

This is a fairly old question, but for what its worth.
Here is the documentation for the Containable Behavior.
It states that, to load the behavior on the fly, you should use:
$this->Model->Behaviors->load('Containable');
I believe the difference is merely due to the fact that attach and detach have been deprecated.
Also, why not just set the $actAs property in your model, or even in AppModel?
class AppModel extends Model {
public $actAs = array('Containable');
// public $recursive = 0;
//...
}
The relation with the User model defined in the Project model is missing the foreignKey field, which may cause trouble. I assume Cake defaults that to user_id which should of course be the name of the column in the projects table.
Other than that, your use of the contain options seems ok.

Try this:
$this->Project->Behaviors->attach('Containable');
$this->Project->contain(array(
'conditions' => array('Project.id' => $projid),
'User'));
$project = $this->Project->find('first');
$this->Project->Behaviors->detach('Containable');

Related

count and addition the array values in array php

I have one array data output coming below format. i want to add total adults count with in the array.My out is below please find.
Array
(
[0] => stdClass Object
(
[id] => 4534
[api] => expedia
[AL_RefNo] => H190100000062
[modify_refno] => H190100000062_1
[Hotel_RefNo] => 325758353
[Booking_RefNo] => 1234
[affiliateConfirmationId] => OMEIR-1P3IWK2G8UXTIT5E2ELI2T2H1QI4H7
[room_no] => 1
[room_type] => Deluxe Double or Twin Room
[arrivalDate] => 02/20/2019
[departureDate] => 02/21/2019
[nights] => 1
[adults] => 1
[childs] => 2
[childs_ages] => 6,8
[bedTypeId] =>
[rateKey] => 26963a10-0e8d-41e0-ad55-478b8b2280fb
[booking_status] => Confirmed
[first_name] => hjgkjug
[middle_name] =>
[last_name] => jh
[averageBaseRate] => 48.46
[averageRate] => 48.46
[commissionableUsdTotal] => 48.46
[currency_val] => 1
[Currency] => AED
[Xml_Currency] => USD
[eanCompensationOffline] => 0
[eanCompensationOnline] => 0
[maxNightlyRate] => 48.46
[nightlyRateTotal] => 48.46
[grossProfitOffline] => 0
[grossProfitOnline] => 0
[TotalBasePrice] => 61
[TotalEqualBasePrice] =>
[TotalEqualTax] =>
[TotalTax] => 13
[markup_type] =>
[markup_percentage] =>
[markup_amount] =>
[markup_value_amount] => 0
[markup_value_percentage] => 10.0000
[extra_markup] => 0
[extra_markup_percentage] => 0
[markup_effective_to] => 2019-02-27
[markup_per_night] => No
[customer_markup] => 6.107
[ota_discount_amount] => 0.00
[ota_discount_type] =>
[ota_discount_cal_amount] => 0.00
[total] => 70.53585
[dailyPrice] =>
[surchargeTotal] => 12.61
[NightlyRatesPerRoomsize] => 1
[NightlyRatePromo] => false
[baseRate] => 48.46
[rate] => 48.46
[surchargesSize] => 1
[surchargeType] => TaxAndServiceFee
[surchargeAmount] => 12.61
[ratePlanType] =>
[processedWithConfirmation] => true
[booking_date] => 2019-01-17 15:01:01
[remarks] => Refundable
[room_type_code] =>
[rateIdentifier] =>
[status] =>
[roomTotalPrice] =>
[serviceDate] =>
[dailypriceType] =>
[mealBasisCodeDay] =>
[mealIdDay] =>
[mealTypeDay] =>
[descriptionDay] =>
[roomDescription] =>
[roomCategory] =>
[transactionID] =>
[payment_charge] =>
[room_code] =>
[description] =>
[commission] =>
[gross_price] =>
[nett_price] =>
[Cancellation_Charge] =>
[Cancel_Till_Date] =>
[Cancelled_By] =>
[rateClass] =>
[rateComments] =>
[paymentType] =>
[packaging] =>
[cancel_amount] =>
[cancel_from_date] =>
[actual_hotel_confirmation_number] =>
[meal_type] => Free Wireless Internet|Free Breakfast
[supplier_price] =>
[sell_price] =>
[client_price] =>
[total_sell_price] =>
[ota_booking_status] =>
[Cancellation_Status] =>
[Cancellation_Charge_Amount] =>
[Cancelled_Markup] =>
[Cancelled_Extra_Markup] =>
[Refundable_Amont] =>
[room_daily_rates] => [{"offset":1,"providerCost":48.46,"baseRate":48.46,"promo":"false","checkIn":"20-02-2019","totalTax":12.61,"inputVat":0,"markup":6.107,"eMarkup":0,"discount":"","outputVat":3.6642,"totalAmount":70.8412,"status":"A"}]
[vat_effective_to] => 2050-02-01
[vat_price] => 3.36
[vat_percentage] => 5
[input_vat_percentage] => 0
[input_vat_price] => 0
[cost_components] => ["Base Price","Markup"]
[register_supplier] => Yes
[inclusive_vat] => No
[gcc_supplier] =>
[price_rate_with_triple_plus] =>
[hotel_service_percentage] =>
[tourism_fee_percentage] =>
[municipality_fee_percentage] =>
[hotel_service_price] =>
[tourism_fee_price] =>
[municipality_fee_price] =>
[direct_hotel_booking] => No
[supplier_cancellation_charge] =>
[vat_cancellation_charge] =>
[modify_booking_status] =>
[parent_modify_refno] =>
[refundable_status] => Refundable
[modify_status] => Yes
[updated_on] => 2019-01-17 19:56:55
)
[1] => stdClass Object
(
[id] => 4535
[api] => expedia
[AL_RefNo] => H190100000062
[modify_refno] => H190100000062_1
[Hotel_RefNo] => 325758353
[Booking_RefNo] => 1235
[affiliateConfirmationId] => OMEIR-1P3IWK2G8UXTIT5E2ELI2T2H1QI4H7
[room_no] => 2
[room_type] => Deluxe Double or Twin Room
[arrivalDate] => 02/20/2019
[departureDate] => 02/21/2019
[nights] => 1
[adults] => 2
[childs] => 1
[childs_ages] => 10
[bedTypeId] =>
[rateKey] => 5baad87e-8d89-43fc-8553-357e885e7f0c
[booking_status] => Confirmed
[first_name] => hjgkjug
[middle_name] =>
[last_name] => jh
[averageBaseRate] => 48.46
[averageRate] => 48.46
[commissionableUsdTotal] => 48.46
[currency_val] => 1
[Currency] => AED
[Xml_Currency] => USD
[eanCompensationOffline] => 0
[eanCompensationOnline] => 0
[maxNightlyRate] => 48.46
[nightlyRateTotal] => 48.46
[grossProfitOffline] => 0
[grossProfitOnline] => 0
[TotalBasePrice] => 61
[TotalEqualBasePrice] =>
[TotalEqualTax] =>
[TotalTax] => 13
[markup_type] =>
[markup_percentage] =>
[markup_amount] =>
[markup_value_amount] => 0
[markup_value_percentage] => 10.0000
[extra_markup] => 0
[extra_markup_percentage] => 0
[markup_effective_to] => 2019-02-27
[markup_per_night] => No
[customer_markup] => 6.107
[ota_discount_amount] => 0.00
[ota_discount_type] =>
[ota_discount_cal_amount] => 0.00
[total] => 70.53585
[dailyPrice] =>
[surchargeTotal] => 12.61
[NightlyRatesPerRoomsize] => 1
[NightlyRatePromo] => false
[baseRate] => 48.46
[rate] => 48.46
[surchargesSize] => 1
[surchargeType] => TaxAndServiceFee
[surchargeAmount] => 12.61
[ratePlanType] =>
[processedWithConfirmation] => true
[booking_date] => 2019-01-17 15:01:01
[remarks] => Refundable
[room_type_code] =>
[rateIdentifier] =>
[status] =>
[roomTotalPrice] =>
[serviceDate] =>
[dailypriceType] =>
[mealBasisCodeDay] =>
[mealIdDay] =>
[mealTypeDay] =>
[descriptionDay] =>
[roomDescription] =>
[roomCategory] =>
[transactionID] =>
[payment_charge] =>
[room_code] =>
[description] =>
[commission] =>
[gross_price] =>
[nett_price] =>
[Cancellation_Charge] =>
[Cancel_Till_Date] =>
[Cancelled_By] =>
[rateClass] =>
[rateComments] =>
[paymentType] =>
[packaging] =>
[cancel_amount] =>
[cancel_from_date] =>
[actual_hotel_confirmation_number] =>
[meal_type] => Free Wireless Internet|Free Breakfast
[supplier_price] =>
[sell_price] =>
[client_price] =>
[total_sell_price] =>
[ota_booking_status] =>
[Cancellation_Status] =>
[Cancellation_Charge_Amount] =>
[Cancelled_Markup] =>
[Cancelled_Extra_Markup] =>
[Refundable_Amont] =>
[room_daily_rates] => [{"offset":1,"providerCost":48.46,"baseRate":48.46,"promo":"false","checkIn":"20-02-2019","totalTax":12.61,"inputVat":0,"markup":6.107,"eMarkup":0,"discount":"","outputVat":3.6642,"totalAmount":70.8412,"status":"A"}]
[vat_effective_to] => 2050-02-01
[vat_price] => 3.36
[vat_percentage] => 5
[input_vat_percentage] => 0
[input_vat_price] => 0
[cost_components] => ["Base Price","Markup"]
[register_supplier] => Yes
[inclusive_vat] => No
[gcc_supplier] =>
[price_rate_with_triple_plus] =>
[hotel_service_percentage] =>
[tourism_fee_percentage] =>
[municipality_fee_percentage] =>
[hotel_service_price] =>
[tourism_fee_price] =>
[municipality_fee_price] =>
[direct_hotel_booking] => No
[supplier_cancellation_charge] =>
[vat_cancellation_charge] =>
[modify_booking_status] =>
[parent_modify_refno] =>
[refundable_status] => Refundable
[modify_status] => Yes
[updated_on] => 2019-01-17 19:56:55
)
)
Here in array object adults is total 1+2 =3 and childs is total 2+1=3.
i tried below code not working
foreach($room_details as $adultcount){
echo $adultcount->adults;
echo $adultcount->childs;
}
can any one please check and tell me where is the mistake in this code. i tried so many times not working below code.
Try something like this:
$adult_count = 0;
$child_count = 0;
foreach($room_details as $count){
$adult_count += $count->adults;
$child_count += $count->childs;
}
echo $adult_count;
echo $child_count;

how to print multiple array in joomla

This is the cart array in the Virtuemart 2.0.22a ..
this is stored in "$cart"
how to print [virtuemart_product_id] => 21 at 4.
$cart=
VirtueMartCart Object
(
[products] => Array
(
[21] => stdClass Object
(
[virtuemart_manufacturer_id] => Array
(
)
[slug] => stylish-shirt
[published] => 1
[virtuemart_product_price] =>
[virtuemart_product_id] => 21
[virtuemart_shoppergroup_id] =>
[product_price] => 450.00000
[override] => 0
[product_override_price] => 0.00000
[product_tax_id] => -1
[product_discount_id] => -1
[product_currency] => 68
[virtuemart_vendor_id] => 1
[product_parent_id] => 0
[product_sku] =>
[product_name] => Stylish Shirt
[product_s_desc] =>
[product_weight] =>
[product_weight_uom] => KG
[product_length] =>
[product_width] =>
[product_height] =>
[product_lwh_uom] => M
[product_in_stock] => 0
[product_ordered] => 0
[product_sales] => 0
[product_unit] => KG
[product_packaging] =>
[min_order_level] =>
[max_order_level] =>
[virtuemart_media_id] => Array
(
[0] => 21
)
[step_order_level] =>
[image] => VmImage Object
(
[media_attributes] => 0
[setRole] =>
[file_name] => 3
[file_extension] => jpg
[virtuemart_media_id] => 21
[_foldersToTest:VmMediaHandler:private] => Array
(
[0] => E:\wamp\www\ecomm\images\stories\virtuemart\product\
[1] => E:\wamp\www\ecomm\images\stories\virtuemart\product\resized\
)
[_actions:VmMediaHandler:private] => Array
(
)
[_mLocation:VmMediaHandler:private] => Array
(
)
[_hidden:VmMediaHandler:private] => Array
(
)
[theme_url] => http://localhost/ecomm/components/com_virtuemart/
[virtuemart_vendor_id] => 1
[file_title] => 3.jpg
[file_description] =>
[file_meta] =>
[file_mimetype] => image/jpeg
[file_type] => product
[file_url] => images/stories/virtuemart/product/3.jpg
[file_url_thumb] => images/stories/virtuemart/product/resized/3_90x90.jpg
[published] => 1
[file_is_downloadable] => 0
[file_is_forSale] => 0
[file_is_product_image] => 0
[shared] => 0
[file_params] =>
[file_lang] =>
[_translatable] =>
[_tablePreFix] =>
[created_on] => 2013-08-12 12:32:19
[created_by] => 572
[modified_on] => 2013-08-12 12:38:50
[modified_by] => 572
[file_url_folder] => images/stories/virtuemart/product/
[file_path_folder] => images\stories\virtuemart\product\
[file_url_folder_thumb] => images/stories/virtuemart/product/resized/
[media_role] => file_is_displayable
[file_name_thumb] => 3_90x90
)
[categories] => Array
(
[0] => 6
)
[virtuemart_category_id] => 6
[category_name] => Shirts
[link] => /ecomm/index.php/component/virtuemart/shirts/stylish-shirt-detail?Itemid=0
[packaging] =>
[quantity] => 1
)
)
[_inCheckOut] =>
[_dataValidated] =>
[_blockConfirm] =>
[_confirmDone] =>
[_redirect] =>
[_redirect_disabled] =>
[_lastError] =>
[vendorId] => 1
[lastVisitedCategoryId] => 0
[virtuemart_shipmentmethod_id] => 0
[virtuemart_paymentmethod_id] => 1
[automaticSelectedShipment] => 1
[automaticSelectedPayment] => 1
[BT] => 0
[ST] => 0
[tosAccepted] =>
[customer_comment] =>
[couponCode] =>
[order_language] =>
[cartData] => Array
(
[VatTax] => Array
(
)
[duty] => 1
[payment] => 0
[paymentName] =>
Finally i got the output.. after lot of struggles
foreach($cart->products as $cur)
{
echo $cur->virtuemart_product_id;
}

Array comparion for multidimensinal array in php [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
recursive array_diff()?
Array 1 =>
pr($plan_data);
Array
(
[0] => Array
(
[AveragePrice] => 9.631161
[EFLUrl] => http://www.championenergyservices.com/register/EFL_API.asp?rateid=161456
[EarlyTerminationFee] => 150
[HurricaneRecovery] => 0.132
[MeterSurcharge] => 3.05
[OffCycle] => 5
[PUCAssessment] => 0.00167
[PlanDescription] => Savings Champ-6
[PlanId] => 57
[PlanIssueDate] => 12/10/2012
[PlanMonthlyFee] => 0
[PlanName] => PN1058
[PlanRate] => 9.3
[PlanRenewablePercent] => 7.2
[PlanTerm] => 6
[PriorityMoveIn] => 36
[ProviderDisplayName] => CenterPoint Energy
[ProviderId] => 21
[ProviderInternalName] => CNP_COAST
[RateId] => 161456
[RegularMoveIn] => 16
[TDSPPassThrough] => 0.03791
[TOCUrl] => http://www.championenergyservices.com/register/termsandconditions.asp?rateid=161456
[YRACUrl] => http://www.championenergyservices.com/register/\affiliatefiles\YRAC.PDF
[provider] => ces
[ProductType] => Fixed
[Rep] => Champion Energy Services
[Zone] => 77479
)
[1] => Array
(
[AveragePrice] => 10.1311693
[EFLUrl] => http://www.championenergyservices.com/register/EFL_API.asp?rateid=161458
[EarlyTerminationFee] => 150
[HurricaneRecovery] => 0.132
[MeterSurcharge] => 3.05
[OffCycle] => 5
[PUCAssessment] => 0.00167
[PlanDescription] => Savings Champ-12
[PlanId] => 59
[PlanIssueDate] => 12/10/2012
[PlanMonthlyFee] => 0
[PlanName] => PN1060
[PlanRate] => 9.8
[PlanRenewablePercent] => 7.2
[PlanTerm] => 12
[PriorityMoveIn] => 36
[ProviderDisplayName] => CenterPoint Energy
[ProviderId] => 21
[ProviderInternalName] => CNP_COAST
[RateId] => 161458
[RegularMoveIn] => 16
[TDSPPassThrough] => 0.03791
[TOCUrl] => http://www.championenergyservices.com/register/termsandconditions.asp?rateid=161458
[YRACUrl] => http://www.championenergyservices.com/register/\affiliatefiles\YRAC.PDF
[provider] => ces
[ProductType] => Fixed
[Rep] => Champion Energy Services
[Zone] => 77479
)
[2] => Array
(
[AveragePrice] => 10.4311743
[EFLUrl] => http://www.championenergyservices.com/register/EFL_API.asp?rateid=161459
[EarlyTerminationFee] => 150
[HurricaneRecovery] => 0.132
[MeterSurcharge] => 3.05
[OffCycle] => 5
[PUCAssessment] => 0.00167
[PlanDescription] => Green Power-12
[PlanId] => 60
[PlanIssueDate] => 12/10/2012
[PlanMonthlyFee] => 0
[PlanName] => PN1061
[PlanRate] => 10.1
[PlanRenewablePercent] => 100
[PlanTerm] => 12
[PriorityMoveIn] => 36
[ProviderDisplayName] => CenterPoint Energy
[ProviderId] => 21
[ProviderInternalName] => CNP_COAST
[RateId] => 161459
[RegularMoveIn] => 16
[TDSPPassThrough] => 0.03791
[TOCUrl] => http://www.championenergyservices.com/register/termsandconditions.asp?rateid=161459
[YRACUrl] => http://www.championenergyservices.com/register/\affiliatefiles\YRAC.PDF
[provider] => ces
[ProductType] => Fixed
[Rep] => Champion Energy Services
[Zone] => 77479
)
)
Array 2 =>
pr($temp_val);
Array
(
[0] => Array
(
[id] => 6
[PlanId] => 60
[PlanName] => Bounce 12 + A/C Protection
[PlanDescription] => Bounce 12 + A/C Protection - CNP
[PlanTerm] => 12
[PlanRate] =>
[RateId] =>
[PlanIssueDate] =>
[PlanMonthlyFee] =>
[EarlyTerminationFee] => 200.00000
[AveragePrice] => 12.00000
[HurricaneRecovery] =>
[PlanRenewablePercent] =>
[ProviderDisplayName] =>
[ProviderId] => 1
[provider] => bounce
[ProductZoneId] => 353
[Zone] => 77479
[ProviderInternalName] =>
[RegularMoveIn] =>
[PriorityMoveIn] =>
[OffCycle] =>
[TDSPPassThrough] =>
[PUCAssessment] =>
[EFLUrl] =>
[EFLLinkUrl] => http://www.bounceenergy.com/efls/bounce12.pdf
[TOCUrl] =>
[TOCLUrl] => http://www.bounceenergy.com/terms-of-service-fixed.pdf
[YRACUrl] =>
[YRACLUrl] => http://www.bounceenergy.com/yraac.pdf
[REP_Name] =>
[REP_PUCT] =>
[customer_service_email] =>
[toll_free_number] =>
[status] => active
[created] => 2012-12-14 12:40:05
[modified] => 2012-12-14
)
[1] => Array
(
[id] => 18
[PlanId] => 17
[PlanName] => Online Only - 12
[PlanDescription] => Online Only - 12
[PlanTerm] => 12
[PlanRate] =>
[RateId] => 386
[PlanIssueDate] =>
[PlanMonthlyFee] => 100.00000
[EarlyTerminationFee] => 175.00000
[AveragePrice] => 10.00000
[HurricaneRecovery] =>
[PlanRenewablePercent] =>
[ProviderDisplayName] =>
[ProviderId] => 2
[provider] => fulcrum
[ProductZoneId] =>
[Zone] => 77479
[ProviderInternalName] =>
[RegularMoveIn] =>
[PriorityMoveIn] =>
[OffCycle] =>
[TDSPPassThrough] =>
[PUCAssessment] =>
[EFLUrl] =>
[EFLLinkUrl] =>
[TOCUrl] =>
[TOCLUrl] =>
[YRACUrl] =>
[YRACLUrl] =>
[REP_Name] =>
[REP_PUCT] =>
[customer_service_email] =>
[toll_free_number] =>
[status] => active
[created] => 2012-12-14 12:40:15
[modified] => 2012-12-14
)
)
I want to compare this two array and if any key value is different i want to take it an different array..
$result_val= array_diff_assoc($plan_data, $temp_val);
Please help me out !!
Try something like this:
function array_diff_assoc($a, $b) {
$result = array();
foreach ($a as $k => $v) {
if ($b[$k] != $v) {
$result[$k] = [$v, $b[$k]];
}
}
return $result;
}

cakephp how to do a nested join

i have the following cakephp binding relationships set up. they are working find but how to get the comment's user record nested in the results as well?
$this->Posts->bindModel(array(
'hasOne' => array(
'User' => array(
'foreignKey' => false,
'type' => 'INNER',
'conditions' => array('Posts.user_id = Users.id')
)
),
'hasMany' => array(
'Comment' => array(
'foreignKey' => 'post_id',
'conditions' => array('Comment.active' => 1)
)
)
));
this works great to get a result like:
[1] => Array
(
[Posts] => Array
(
[title] => test post
[body] => test body
[published] =>
[id] => 15
)
[User] => Array
(
[id] => 7
[username] => admin
[password] => d0557b9de8bb6f7fb3248a017c7b67a6
[email] => frankhinchey#gmail.com
[group_id] => 1
[created] => 2011-11-21 15:19:09
)
[Comment] => Array
(
[0] => Array
(
[id] => 10
[user_id] => 7
[post_id] => 15
[text] => testdfasdfdsfasdfasdfasdfasd
[active] => 1
[created] => 2011-12-02 20:50:57
[published] => 2011-12-05 13:58:25
)
[1] => Array
(
[id] => 11
[user_id] => 7
[post_id] => 15
[text] => this is a test comment
[active] => 1
[created] => 2011-12-02 21:31:56
[published] => 2011-12-03 11:34:32
)
)
)
)
my question is how to also get the related user on the comment? is there a way to nest in my query the hasone relationship between comment and user?
Can you use contain within bindModel? Never tried it before... but worth a shot.
$this->Posts->bindModel(array(
'hasOne' => array(
'User' => array(
'foreignKey' => false,
'type' => 'INNER',
'conditions' => array('Posts.user_id = Users.id')
)
),
'hasMany' => array(
'Comment' => array(
'foreignKey' => 'post_id',
'conditions' => array('Comment.active' => 1),
'contain' => array('User'),
)
)
));
Actually now that I read your question I'm not really sure what you want. Do you want the user_id of who the person is commenting on? Can you just elaborate on what you want a little more.

PHP Arrays, appending count of array items recursively to an array

Pointless Dribble
Okay This is another weird one from me, i want to thank OIS for helping me out on my last question... which deals with this same kind of funky array manipulation... i studied that code in depth and i feel it has helped me become better with recursive array manipulative functions. However, once again i find my self in another tough spot
Actual Problem
I am trying to write a recursive manipulative function such as this. Except for getting the depth of each array element. It will add incremental count to each array element with a certain depth. The easiest way to see what I'm trying to do is to view the "sample array" and "Desired result Array"... i feel like I'm getting better at understanding these kind of recursive functions. but this one is giving me hell, thanks in advance for any kind of help you can give me with this.
Please disregard the [depth] result of the sample array i already have a function that adds this.
Thanks again,
-- YouDontMeanMuch
Sample Array
array (
52 =>
array (
'title' => 'Website Navigation',
'path' => '',
'type' => '115',
'pid' => 0,
'hasChildren' => 1,
'children' =>
array (
53 =>
array (
'title' => 'Home',
'path' => '',
'type' => '118',
'pid' => 52,
'hasChildren' => 0,
),
54 =>
array (
'title' => 'Features',
'path' => 'features',
'type' => '374',
'pid' => 52,
'hasChildren' => 1,
'children' =>
array (
59 =>
array (
'title' => 'artistic',
'path' => 'features/artistic',
'type' => '374',
'pid' => 54,
'hasChildren' => 1,
'children' =>
array (
63 =>
array (
'title' => 'galleries',
'path' => 'features/artistic/galleries',
'type' => '374',
'pid' => 59,
'hasChildren' => 1,
'children' =>
array (
65 =>
array (
'title' => 'graphics',
'path' => 'features/artistic/galleries/graphics',
'type' => '118',
'pid' => 63,
'hasChildren' => 0,
),
67 =>
array (
'title' => 'mixed medium',
'path' => 'features/artistic/galleries/mixed-medium',
'type' => '118',
'pid' => 63,
'hasChildren' => 0,
),
64 =>
array (
'title' => 'overview',
'path' => 'features/artistic/galleries',
'type' => '118',
'pid' => 63,
'hasChildren' => 0,
),
68 =>
array (
'title' => 'photography',
'path' => 'features/artistic/galleries/photography',
'type' => '118',
'pid' => 63,
'hasChildren' => 0,
),
66 =>
array (
'title' => 'traditional',
'path' => 'features/artistic/galleries/traditional',
'type' => '118',
'pid' => 63,
'hasChildren' => 0,
),
),
),
62 =>
array (
'title' => 'overview',
'path' => 'features/artistic',
'type' => '118',
'pid' => 59,
'hasChildren' => 0,
),
69 =>
array (
'title' => 'tutorials',
'path' => 'features/artistic/tutorials',
'type' => '374',
'pid' => 59,
'hasChildren' => 1,
'children' =>
array (
71 =>
array (
'title' => 'by category',
'path' => 'features/artistic/tutorials/by-category/',
'type' => '118',
'pid' => 69,
'hasChildren' => 0,
),
72 =>
array (
'title' => 'by date',
'path' => 'features/artistic/tutorials/by-date/',
'type' => '118',
'pid' => 69,
'hasChildren' => 0,
),
70 =>
array (
'title' => 'overview',
'path' => 'features/artistic/tutorials',
'type' => '118',
'pid' => 69,
'hasChildren' => 0,
),
),
),
),
),
58 =>
array (
'title' => 'overview',
'path' => 'features',
'type' => '118',
'pid' => 54,
'hasChildren' => 0,
),
61 =>
array (
'title' => 'projects / labs',
'path' => 'features/projects-labs/',
'type' => '374',
'pid' => 54,
'hasChildren' => 0,
),
60 =>
array (
'title' => 'web development',
'path' => 'features/web-development',
'type' => '374',
'pid' => 54,
'hasChildren' => 1,
'children' =>
array (
74 =>
array (
'title' => 'articles',
'path' => 'features/web-development/articles/',
'type' => '374',
'pid' => 60,
'hasChildren' => 0,
),
73 =>
array (
'title' => 'overview',
'path' => 'features/web-development',
'type' => '118',
'pid' => 60,
'hasChildren' => 0,
),
75 =>
array (
'title' => 'tutorials',
'path' => 'features/web-development/tutorials',
'type' => '374',
'pid' => 60,
'hasChildren' => 0,
),
),
),
),
),
55 =>
array (
'title' => 'Activity',
'path' => 'activity',
'type' => '374',
'pid' => 52,
'hasChildren' => 0,
),
56 =>
array (
'title' => 'Blog',
'path' => 'blog',
'type' => '374',
'pid' => 52,
'hasChildren' => 0,
),
57 =>
array (
'title' => 'About',
'path' => 'about',
'type' => '374',
'pid' => 52,
'hasChildren' => 1,
'children' =>
array (
76 =>
array (
'title' => 'the author',
'path' => 'about/the-author',
'type' => '118',
'pid' => 57,
'hasChildren' => 0,
),
77 =>
array (
'title' => 'the website',
'path' => 'about/the-website',
'type' => '118',
'pid' => 57,
'hasChildren' => 0,
),
),
),
),
),
)
Desired result Array Notice the [count] index
Array
(
[53] => Array
(
[title] => Home
[path] =>
[type] => 118
[pid] => 52
[mid] => 53
[hasChildren] => 0
[depth] => 1
[count] => 1
)
[54] => Array
(
[title] => Features
[path] => features
[type] => 374
[pid] => 52
[mid] => 54
[hasChildren] => 1
[depth] => 1
[count] => 2
[children] => Array
(
[59] => Array
(
[title] => artistic
[path] => features/artistic
[type] => 374
[pid] => 54
[mid] => 59
[hasChildren] => 1
[depth] => 2
[count] => 1
[children] => Array
(
[63] => Array
(
[title] => galleries
[path] => features/artistic/galleries
[type] => 374
[pid] => 59
[mid] => 63
[hasChildren] => 1
[depth] => 3
[count] => 1
[children] => Array
(
[65] => Array
(
[title] => graphics
[path] => features/artistic/galleries/graphics
[type] => 118
[pid] => 63
[mid] => 65
[hasChildren] => 0
[depth] => 4
[count] => 1
)
[67] => Array
(
[title] => mixed medium
[path] => features/artistic/galleries/mixed-medium
[type] => 118
[pid] => 63
[mid] => 67
[hasChildren] => 0
[depth] => 4
[count] => 2
)
[64] => Array
(
[title] => overview
[path] => features/artistic/galleries
[type] => 118
[pid] => 63
[mid] => 64
[hasChildren] => 0
[depth] => 4
[count] => 3
)
[68] => Array
(
[title] => photography
[path] => features/artistic/galleries/photography
[type] => 118
[pid] => 63
[mid] => 68
[hasChildren] => 0
[depth] => 4
[count] => 4
)
[66] => Array
(
[title] => traditional
[path] => features/artistic/galleries/traditional
[type] => 118
[pid] => 63
[mid] => 66
[hasChildren] => 0
[depth] => 4
[count] => 5
)
)
)
[62] => Array
(
[title] => overview
[path] => features/artistic
[type] => 118
[pid] => 59
[mid] => 62
[hasChildren] => 0
[depth] => 3
[count] => 2
)
[69] => Array
(
[title] => tutorials
[path] => features/artistic/tutorials
[type] => 374
[pid] => 59
[mid] => 69
[hasChildren] => 1
[depth] => 3
[count] => 3
[children] => Array
(
[71] => Array
(
[title] => by category
[path] => features/artistic/tutorials/by-category/
[type] => 118
[pid] => 69
[mid] => 71
[hasChildren] => 0
[depth] => 4
[count] => 1
)
[72] => Array
(
[title] => by date
[path] => features/artistic/tutorials/by-date/
[type] => 118
[pid] => 69
[mid] => 72
[hasChildren] => 0
[depth] => 4
[count] => 2
)
[70] => Array
(
[title] => overview
[path] => features/artistic/tutorials
[type] => 118
[pid] => 69
[mid] => 70
[hasChildren] => 0
[depth] => 4
[count] => 3
)
)
)
)
)
[58] => Array
(
[title] => overview
[path] => features
[type] => 118
[pid] => 54
[mid] => 58
[hasChildren] => 0
[depth] => 2
[count] => 2
)
[61] => Array
(
[title] => projects / labs
[path] => features/projects-labs/
[type] => 374
[pid] => 54
[mid] => 61
[hasChildren] => 0
[depth] => 2
[count] => 3
)
[60] => Array
(
[title] => web development
[path] => features/web-development
[type] => 374
[pid] => 54
[mid] => 60
[hasChildren] => 1
[depth] => 2
[count] => 4
[children] => Array
(
[74] => Array
(
[title] => articles
[path] => features/web-development/articles/
[type] => 374
[pid] => 60
[mid] => 74
[hasChildren] => 0
[depth] => 3
[count] => 1
)
[73] => Array
(
[title] => overview
[path] => features/web-development
[type] => 118
[pid] => 60
[mid] => 73
[hasChildren] => 0
[depth] => 3
[count] => 2
)
[75] => Array
(
[title] => tutorials
[path] => features/web-development/tutorials
[type] => 374
[pid] => 60
[mid] => 75
[hasChildren] => 0
[depth] => 3
[count] => 3
)
I think this should work... I wasn't able to test on your example array but it seems to work on a smaller array I made.
Edit: Changed the function now that you've removed the 'depth' keys from your example array. Now it finds the depth on its own. I've also added my test code and output:
<?php
function array_depth_count(&$array, $count=array(), $depth=1) {
foreach ($array as &$value) {
if (is_array($value)) {
$value['count'] = ++$count[$depth];
array_depth_count($value, $count, $depth + 1);
}
}
}
$a = array(array(array(array(0),array(0),array(),array()),0,array()));
echo "Before\n";
print_r($a);
array_depth_count($a);
echo "\n\nAfter\n";
print_r($a);
?>
Output:
Before
Array
(
[0] => Array
(
[0] => Array
(
[0] => Array
(
[0] => 0
)
[1] => Array
(
[0] => 0
)
[2] => Array
(
)
[3] => Array
(
)
)
[1] => 0
[2] => Array
(
)
)
)
After
Array
(
[0] => Array
(
[0] => Array
(
[0] => Array
(
[0] => 0
[count] => 1
)
[1] => Array
(
[0] => 0
[count] => 2
)
[2] => Array
(
[count] => 3
)
[3] => Array
(
[count] => 4
)
[count] => 1
)
[1] => 0
[2] => Array
(
[count] => 2
)
[count] => 1
)
)
I really want to say this will work
function deep(&$layer)
{
$count = 1;
$keys = array_keys($layer);
foreach($keys as $key)
if(is_array($layer[$key]))
deep($layer[$key]);
$layer['depth'] = $count++;
}
(Tested and works fine for me)
(Another case of me misunderstanding the question. This should be what you want)

Categories