I'm trying to set an API wit a CMS. The api code works fine. When I use var_dump the data I get is given below. I just want to extract records from it.
string(9219) "{"Details":{"PageNo":1,"TotalRecords":21,"TotalPages":6,"MethodName":"GetEntity"},"Error":{"ErrorCode":"200","ErrorDescription":"Request Successfully Accommodated"},"Records":[{"RecordId":"79245","Deleted":"N","CancellationWithNoRefund":"N","ShowOnWeb":"Y","BookNowOverrideOnWeb":"","WaitingListByEventOrSession":"","Active":"Y","Archive":"","DinnerType":"","StandardDay":"","EvacuationAssistanceRequired":"","IncludesMeals":"","FieldTrip":"","CpdAssignedToDelegate":"","Master":"","EventMaster":"","EnableApologies":"","MemberOnly":"N","AllowTableBooking":"","ExamDate":"","ExpiryDate":"","ArrivalDate":"","DepartDate":"","CutOffDate":"2021-12-20 00:00:00.000","BookingDeadline":"","StartDate":"2021-12-21 00:00:00.000","EndDate":"2021-12-21 00:00:00.000","DateDeleted":"","DateModified":"20/07/2021 14:53:14","DateCreated":"20/07/2021 13:30:11","NoOfDays":"1","AccreditionPoints":"","TotalTba":"0","MaximumSeats":"64","MinimumSeats":"1","TotalBookings":"1","TotalCancellations":"0","TotalRemoved":"","SeatsAvailable":"63","TotalOnWaitingList":"0","WaitingLimitPercentage":"12.5","WaitingLimitNumber":"8","EventCpdHours":"","MaximumAdditionalDelegates":"4","CommitteeName":"","SpeakerTutorOrganisationName":"","EventCode":"","ExpiryDaysName":"","ResponsibilityName":"","JoiningInstructions":"Further instructions will be emailed out ","RegionName":"Southe","Location":"","PromotionalCodeName":"","EventUrl":"","CampaignAppealName":"","CostCentreName":"","InternalId":"","SpeakerTutorName":"","LedgerAccountName":"","MainContactName":"","VatRateName":"Standard 20%","EventTypeName":"Golf Day","EventStatusName":"Open","VenueName":"Foxhills Golf Club & Resort","RegistrationTime":"","DeletedBy":"","EventName":"Golf Day 2021 SL","FomalTitle":"Golf Day 2021 SL","SourceFile":"","EventId":"Golf Day SL ","CreatedBy":"Sarah Lepak","ModifiedBy":"Sarah Lepak","LongDescription":"","Remarks":"","BookNowOverrideMessage":"","AccommodationNotes":"","NotesForWeb":"SL test golf day 2021","TCForWeb":"T's & C's here","ShortNotesForWeb":"","Committee":"","Responsibility":"","PromotionalCode":"","Region":"19053","SpeakerTutorOrganisation":"","ExpiryDays":"","CampaignAppeal":"","CostCentre":"","MainContact":"","Venue":"79240","EventStatus":"241","EventType":"227","LedgerAccount":"","VatRate":"19112","SpeakerTutor":"","StartTime":"10:30","EndTime":"16:00","WaitingListBy":"Event","CpdBy":"","SiteLayout":""},{"RecordId":"79244","Deleted":"N","CancellationWithNoRefund":"N","ShowOnWeb":"Y","BookNowOverrideOnWeb":"","WaitingListByEventOrSession":"","Active":"Y","Archive":"","DinnerType":"","StandardDay":"","EvacuationAssistanceRequired":"","IncludesMeals":"","FieldTrip":"","CpdAssignedToDelegate":"","Master":"","EventMaster":"","EnableApologies":"","MemberOnly":"N","AllowTableBooking":"","ExamDate":"","ExpiryDate":"","ArrivalDate":"","DepartDate":"","CutOffDate":"2021-09-20 00:00:00.000","BookingDeadline":"","StartDate":"2021-09-21 00:00:00.000","EndDate":"2021-09-21 00:00:00.000","DateDeleted":"","DateModified":"20/07/2021 13:30:03","DateCreated":"20/07/2021 13:30:01","NoOfDays":"1","AccreditionPoints":"","TotalTba":"0","MaximumSeats":"64","MinimumSeats":"1","TotalBookings":"0","TotalCancellations":"0","TotalRemoved":"","SeatsAvailable":"64","TotalOnWaitingList":"0","WaitingLimitPercentage":"78.13","WaitingLimitNumber":"50","EventCpdHours":"","MaximumAdditionalDelegates":"4","CommitteeName":"","SpeakerTutorOrganisationName":"","EventCode":"","ExpiryDaysName":"","ResponsibilityName":"","JoiningInstructions":"","RegionName":"Southe","Location":"","PromotionalCodeName":"","EventUrl":"","CampaignAppealName":"","CostCentreName":"","InternalId":"","SpeakerTutorName":"","LedgerAccountName":"","MainContactName":"","VatRateName":"Standard 20%","EventTypeName":"Golf Day","EventStatusName":"Open","VenueName":"Foxhills Golf Club & Resort","RegistrationTime":"","DeletedBy":"","EventName":"CB Golf Experience 2021","FomalTitle":"CB Golf Experience 2021","SourceFile":"","EventId":"CBGE21","CreatedBy":"Calvin Barnett","ModifiedBy":"Calvin Barnett","LongDescription":"","Remarks":"","BookNowOverrideMessage":"","AccommodationNotes":"","NotesForWeb":"Lorem ipsum Lorem ipsum","TCForWeb":"Cancellations more than 14 days ahead of the event will incur an administration fee of 10% per person deducted from their refund\r\n28 days ahead or less - a 50% refund will be given\r\n14 days ahead or less – no refunds will be given","ShortNotesForWeb":"","Committee":"","Responsibility":"","PromotionalCode":"","Region":"19053","SpeakerTutorOrganisation":"","ExpiryDays":"","CampaignAppeal":"","CostCentre":"","MainContact":"","Venue":"79240","EventStatus":"241","EventType":"227","LedgerAccount":"","VatRate":"19112","SpeakerTutor":"","StartTime":"14:00","EndTime":"17:00","WaitingListBy":"Event","CpdBy":"","SiteLayout":""},{"RecordId":"79243","Deleted":"N","CancellationWithNoRefund":"N","ShowOnWeb":"N","BookNowOverrideOnWeb":"","WaitingListByEventOrSession":"","Active":"Y","Archive":"","DinnerType":"","StandardDay":"","EvacuationAssistanceRequired":"","IncludesMeals":"","FieldTrip":"","CpdAssignedToDelegate":"","Master":"","EventMaster":"","EnableApologies":"","MemberOnly":"N","AllowTableBooking":"","ExamDate":"","ExpiryDate":"","ArrivalDate":"","DepartDate":"","CutOffDate":"","BookingDeadline":"","StartDate":"2022-08-30 00:00:00.000","EndDate":"2022-08-30 00:00:00.000","DateDeleted":"","DateModified":"20/07/2021 14:48:13","DateCreated":"20/07/2021 13:29:59","NoOfDays":"1","AccreditionPoints":"","TotalTba":"0","MaximumSeats":"65","MinimumSeats":"1","TotalBookings":"1","TotalCancellations":"0","TotalRemoved":"","SeatsAvailable":"64","TotalOnWaitingList":"0","WaitingLimitPercentage":"","WaitingLimitNumber":"","EventCpdHours":"","MaximumAdditionalDelegates":"4","CommitteeName":"","SpeakerTutorOrganisationName":"","EventCode":"","ExpiryDaysName":"","ResponsibilityName":"","JoiningInstructions":"","RegionName":"Eastmids","Location":"West lobby","PromotionalCodeName":"","EventUrl":"","CampaignAppealName":"","CostCentreName":"","InternalId":"","SpeakerTutorName":"","LedgerAccountName":"","MainContactName":"","VatRateName":"Standard 20%","EventTypeName":"Golf Day","EventStatusName":"Open","VenueName":"MilYork Test Venue","RegistrationTime":"","DeletedBy":"","EventName":"MY Golf Day 2022","FomalTitle":"MY Golf Day 2022","SourceFile":"","EventId":"MYGD22","CreatedBy":"Dawn Hall","ModifiedBy":"Dawn Hall","LongDescription":"","Remarks":"","BookNowOverrideMessage":"","AccommodationNotes":"","NotesForWeb":"Park in West wing carpark","TCForWeb":"This is a CRM test.","ShortNotesForWeb":"","Committee":"","Responsibility":"","PromotionalCode":"","Region":"19046","SpeakerTutorOrganisation":"","ExpiryDays":"","CampaignAppeal":"","CostCentre":"","MainContact":"","Venue":"77113","EventStatus":"241","EventType":"227","LedgerAccount":"","VatRate":"19112","SpeakerTutor":"","StartTime":"08:00","EndTime":"19:00","WaitingListBy":"Session","CpdBy":"","SiteLayout":""},{"RecordId":"79242","Deleted":"N","CancellationWithNoRefund":"N","ShowOnWeb":"Y","BookNowOverrideOnWeb":"","WaitingListByEventOrSession":"","Active":"Y","Archive":"","DinnerType":"","StandardDay":"","EvacuationAssistanceRequired":"","IncludesMeals":"","FieldTrip":"","CpdAssignedToDelegate":"","Master":"","EventMaster":"","EnableApologies":"","MemberOnly":"N","AllowTableBooking":"","ExamDate":"","ExpiryDate":"","ArrivalDate":"","DepartDate":"","CutOffDate":"2021-09-08 00:00:00.000","BookingDeadline":"","StartDate":"2021-09-08 00:00:00.000","EndDate":"2021-09-08 00:00:00.000","DateDeleted":"","DateModified":"20/07/2021 13:29:29","DateCreated":"20/07/2021 13:29:28","NoOfDays":"1","AccreditionPoints":"","TotalTba":"0","MaximumSeats":"64","MinimumSeats":"1","TotalBookings":"0","TotalCancellations":"0","TotalRemoved":"","SeatsAvailable":"64","TotalOnWaitingList":"0","WaitingLimitPercentage":"18.75","WaitingLimitNumber":"12","EventCpdHours":"","MaximumAdditionalDelegates":"4","CommitteeName":"","SpeakerTutorOrganisationName":"","EventCode":"","ExpiryDaysName":"","ResponsibilityName":"","JoiningInstructions":"First come first serve basis","RegionName":"Southe","Location":"","PromotionalCodeName":"","EventUrl":"","CampaignAppealName":"","CostCentreName":"","InternalId":"","SpeakerTutorName":"","LedgerAccountName":"","MainContactName":"","VatRateName":"Standard 20%","EventTypeName":"Golf Day","EventStatusName":"Open","VenueName":"Foxhills Golf Club & Resort","RegistrationTime":"","DeletedBy":"","EventName":"Annual Golf Day 2021 - CL Version","FomalTitle":"Annual Golf Day 2021 - CL Version","SourceFile":"","EventId":"CL- GD21","CreatedBy":"Charlie Lawrence","ModifiedBy":"Charlie Lawrence","LongDescription":"","Remarks":"","BookNowOverrideMessage":"","AccommodationNotes":"","NotesForWeb":"Annual Golf Day 2021","TCForWeb":"","ShortNotesForWeb":"","Committee":"","Responsibility":"","PromotionalCode":"","Region":"19053","SpeakerTutorOrganisation":"","ExpiryDays":"","CampaignAppeal":"","CostCentre":"","MainContact":"","Venue":"79240","EventStatus":"241","EventType":"227","LedgerAccount":"","VatRate":"19112","SpeakerTutor":"","StartTime":"08:00","EndTime":"16:00","WaitingListBy":"Session","CpdBy":"","SiteLayout":""}]}"
The API is returning a JSON string. Please try
$result = json_decode(curl_exec($curl));
$result is a php array.
Getting this reposes from the answer you provided.
How can I get the records only.
stdClass Object ( [Details] => stdClass Object ( [PageNo] => 1 [TotalRecords] => 21 [TotalPages] => 6 [MethodName] => GetEntity ) [Error] => stdClass Object ( [ErrorCode] => 200 [ErrorDescription] => Request Successfully Accommodated ) [Records] => Array ( [0] => stdClass Object ( [RecordId] => 79245 [Deleted] => N [CancellationWithNoRefund] => N [ShowOnWeb] => Y [BookNowOverrideOnWeb] => [WaitingListByEventOrSession] => [Active] => Y [Archive] => [DinnerType] => [StandardDay] => [EvacuationAssistanceRequired] => [IncludesMeals] => [FieldTrip] => [CpdAssignedToDelegate] => [Master] => [EventMaster] => [EnableApologies] => [MemberOnly] => N [AllowTableBooking] => [ExamDate] => [ExpiryDate] => [ArrivalDate] => [DepartDate] => [CutOffDate] => 2021-12-20 00:00:00.000 [BookingDeadline] => [StartDate] => 2021-12-21 00:00:00.000 [EndDate] => 2021-12-21 00:00:00.000 [DateDeleted] => [DateModified] => 20/07/2021 14:53:14 [DateCreated] => 20/07/2021 13:30:11 [NoOfDays] => 1 [AccreditionPoints] => [TotalTba] => 0 [MaximumSeats] => 64 [MinimumSeats] => 1 [TotalBookings] => 1 [TotalCancellations] => 0 [TotalRemoved] => [SeatsAvailable] => 63 [TotalOnWaitingList] => 0 [WaitingLimitPercentage] => 12.5 [WaitingLimitNumber] => 8 [EventCpdHours] => [MaximumAdditionalDelegates] => 4 [CommitteeName] => [SpeakerTutorOrganisationName] => [EventCode] => [ExpiryDaysName] => [ResponsibilityName] => [JoiningInstructions] => Further instructions will be emailed out [RegionName] => Southe [Location] => [PromotionalCodeName] => [EventUrl] => [CampaignAppealName] => [CostCentreName] => [InternalId] => [SpeakerTutorName] => [LedgerAccountName] => [MainContactName] => [VatRateName] => Standard 20% [EventTypeName] => Golf Day [EventStatusName] => Open [VenueName] => Foxhills Golf Club & Resort [RegistrationTime] => [DeletedBy] => [EventName] => Golf Day 2021 SL [FomalTitle] => Golf Day 2021 SL [SourceFile] => [EventId] => Golf Day SL [CreatedBy] => Sarah Lepak [ModifiedBy] => Sarah Lepak [LongDescription] => [Remarks] => [BookNowOverrideMessage] => [AccommodationNotes] => [NotesForWeb] => SL test golf day 2021 [TCForWeb] => T's & C's here [ShortNotesForWeb] => [Committee] => [Responsibility] => [PromotionalCode] => [Region] => 19053 [SpeakerTutorOrganisation] => [ExpiryDays] => [CampaignAppeal] => [CostCentre] => [MainContact] => [Venue] => 79240 [EventStatus] => 241 [EventType] => 227 [LedgerAccount] => [VatRate] => 19112 [SpeakerTutor] => [StartTime] => 10:30 [EndTime] => 16:00 [WaitingListBy] => Event [CpdBy] => [SiteLayout] => ) [1] => stdClass Object ( [RecordId] => 79244 [Deleted] => N [CancellationWithNoRefund] => N [ShowOnWeb] => Y [BookNowOverrideOnWeb] => [WaitingListByEventOrSession] => [Active] => Y [Archive] => [DinnerType] => [StandardDay] => [EvacuationAssistanceRequired] => [IncludesMeals] => [FieldTrip] => [CpdAssignedToDelegate] => [Master] => [EventMaster] => [EnableApologies] => [MemberOnly] => N [AllowTableBooking] => [ExamDate] => [ExpiryDate] => [ArrivalDate] => [DepartDate] => [CutOffDate] => 2021-09-20 00:00:00.000 [BookingDeadline] => [StartDate] => 2021-09-21 00:00:00.000 [EndDate] => 2021-09-21 00:00:00.000 [DateDeleted] => [DateModified] => 20/07/2021 13:30:03 [DateCreated] => 20/07/2021 13:30:01 [NoOfDays] => 1 [AccreditionPoints] => [TotalTba] => 0 [MaximumSeats] => 64 [MinimumSeats] => 1 [TotalBookings] => 0 [TotalCancellations] => 0 [TotalRemoved] => [SeatsAvailable] => 64 [TotalOnWaitingList] => 0 [WaitingLimitPercentage] => 78.13 [WaitingLimitNumber] => 50 [EventCpdHours] => [MaximumAdditionalDelegates] => 4 [CommitteeName] => [SpeakerTutorOrganisationName] => [EventCode] => [ExpiryDaysName] => [ResponsibilityName] => [JoiningInstructions] => [RegionName] => Southe [Location] => [PromotionalCodeName] => [EventUrl] => [CampaignAppealName] => [CostCentreName] => [InternalId] => [SpeakerTutorName] => [LedgerAccountName] => [MainContactName] => [VatRateName] => Standard 20% [EventTypeName] => Golf Day [EventStatusName] => Open [VenueName] => Foxhills Golf Club & Resort [RegistrationTime] => [DeletedBy] => [EventName] => CB Golf Experience 2021 [FomalTitle] => CB Golf Experience 2021 [SourceFile] => [EventId] => CBGE21 [CreatedBy] => Calvin Barnett [ModifiedBy] => Calvin Barnett [LongDescription] => [Remarks] => [BookNowOverrideMessage] => [AccommodationNotes] => [NotesForWeb] => Lorem ipsum Lorem ipsum [TCForWeb] => Cancellations more than 14 days ahead of the event will incur an administration fee of 10% per person deducted from their refund 28 days ahead or less - a 50% refund will be given 14 days ahead or less – no refunds will be given [ShortNotesForWeb] => [Committee] => [Responsibility] => [PromotionalCode] => [Region] => 19053 [SpeakerTutorOrganisation] => [ExpiryDays] => [CampaignAppeal] => [CostCentre] => [MainContact] => [Venue] => 79240 [EventStatus] => 241 [EventType] => 227 [LedgerAccount] => [VatRate] => 19112 [SpeakerTutor] => [StartTime] => 14:00 [EndTime] => 17:00 [WaitingListBy] => Event [CpdBy] => [SiteLayout] => ) [2] => stdClass Object ( [RecordId] => 79243 [Deleted] => N [CancellationWithNoRefund] => N [ShowOnWeb] => N [BookNowOverrideOnWeb] => [WaitingListByEventOrSession] => [Active] => Y [Archive] => [DinnerType] => [StandardDay] => [EvacuationAssistanceRequired] => [IncludesMeals] => [FieldTrip] => [CpdAssignedToDelegate] => [Master] => [EventMaster] => [EnableApologies] => [MemberOnly] => N [AllowTableBooking] => [ExamDate] => [ExpiryDate] => [ArrivalDate] => [DepartDate] => [CutOffDate] => [BookingDeadline] => [StartDate] => 2022-08-30 00:00:00.000 [EndDate] => 2022-08-30 00:00:00.000 [DateDeleted] => [DateModified] => 20/07/2021 14:48:13 [DateCreated] => 20/07/2021 13:29:59 [NoOfDays] => 1 [AccreditionPoints] => [TotalTba] => 0 [MaximumSeats] => 65 [MinimumSeats] => 1 [TotalBookings] => 1 [TotalCancellations] => 0 [TotalRemoved] => [SeatsAvailable] => 64 [TotalOnWaitingList] => 0 [WaitingLimitPercentage] => [WaitingLimitNumber] => [EventCpdHours] => [MaximumAdditionalDelegates] => 4 [CommitteeName] => [SpeakerTutorOrganisationName] => [EventCode] => [ExpiryDaysName] => [ResponsibilityName] => [JoiningInstructions] => [RegionName] => Eastmids [Location] => West lobby [PromotionalCodeName] => [EventUrl] => [CampaignAppealName] => [CostCentreName] => [InternalId] => [SpeakerTutorName] => [LedgerAccountName] => [MainContactName] => [VatRateName] => Standard 20% [EventTypeName] => Golf Day [EventStatusName] => Open [VenueName] => MilYork Test Venue [RegistrationTime] => [DeletedBy] => [EventName] => MY Golf Day 2022 [FomalTitle] => MY Golf Day 2022 [SourceFile] => [EventId] => MYGD22 [CreatedBy] => Dawn Hall [ModifiedBy] => Dawn Hall [LongDescription] => [Remarks] => [BookNowOverrideMessage] => [AccommodationNotes] => [NotesForWeb] => Park in West wing carpark [TCForWeb] => This is a CRM test. [ShortNotesForWeb] => [Committee] => [Responsibility] => [PromotionalCode] => [Region] => 19046 [SpeakerTutorOrganisation] => [ExpiryDays] => [CampaignAppeal] => [CostCentre] => [MainContact] => [Venue] => 77113 [EventStatus] => 241 [EventType] => 227 [LedgerAccount] => [VatRate] => 19112 [SpeakerTutor] => [StartTime] => 08:00 [EndTime] => 19:00 [WaitingListBy] => Session [CpdBy] => [SiteLayout] => ) [3] => stdClass Object ( [RecordId] => 79242 [Deleted] => N [CancellationWithNoRefund] => N [ShowOnWeb] => Y [BookNowOverrideOnWeb] => [WaitingListByEventOrSession] => [Active] => Y [Archive] => [DinnerType] => [StandardDay] => [EvacuationAssistanceRequired] => [IncludesMeals] => [FieldTrip] => [CpdAssignedToDelegate] => [Master] => [EventMaster] => [EnableApologies] => [MemberOnly] => N [AllowTableBooking] => [ExamDate] => [ExpiryDate] => [ArrivalDate] => [DepartDate] => [CutOffDate] => 2021-09-08 00:00:00.000 [BookingDeadline] => [StartDate] => 2021-09-08 00:00:00.000 [EndDate] => 2021-09-08 00:00:00.000 [DateDeleted] => [DateModified] => 20/07/2021 13:29:29 [DateCreated] => 20/07/2021 13:29:28 [NoOfDays] => 1 [AccreditionPoints] => [TotalTba] => 0 [MaximumSeats] => 64 [MinimumSeats] => 1 [TotalBookings] => 0 [TotalCancellations] => 0 [TotalRemoved] => [SeatsAvailable] => 64 [TotalOnWaitingList] => 0 [WaitingLimitPercentage] => 18.75 [WaitingLimitNumber] => 12 [EventCpdHours] => [MaximumAdditionalDelegates] => 4 [CommitteeName] => [SpeakerTutorOrganisationName] => [EventCode] => [ExpiryDaysName] => [ResponsibilityName] => [JoiningInstructions] => First come first serve basis [RegionName] => Southe [Location] => [PromotionalCodeName] => [EventUrl] => [CampaignAppealName] => [CostCentreName] => [InternalId] => [SpeakerTutorName] => [LedgerAccountName] => [MainContactName] => [VatRateName] => Standard 20% [EventTypeName] => Golf Day [EventStatusName] => Open [VenueName] => Foxhills Golf Club & Resort [RegistrationTime] => [DeletedBy] => [EventName] => Annual Golf Day 2021 - CL Version [FomalTitle] => Annual Golf Day 2021 - CL Version [SourceFile] => [EventId] => CL- GD21 [CreatedBy] => Charlie Lawrence [ModifiedBy] => Charlie Lawrence [LongDescription] => [Remarks] => [BookNowOverrideMessage] => [AccommodationNotes] => [NotesForWeb] => Annual Golf Day 2021 [TCForWeb] => [ShortNotesForWeb] => [Committee] => [Responsibility] => [PromotionalCode] => [Region] => 19053 [SpeakerTutorOrganisation] => [ExpiryDays] => [CampaignAppeal] => [CostCentre] => [MainContact] => [Venue] => 79240 [EventStatus] => 241 [EventType] => 227 [LedgerAccount] => [VatRate] => 19112 [SpeakerTutor] => [StartTime] => 08:00 [EndTime] => 16:00 [WaitingListBy] => Session [CpdBy] => [SiteLayout] => ) ) )
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');