CakePHP - validation returning false - php

validates() getting failed, but the validationErrors is empty in CakePHP 2.x, even I have user unlockedActions for this method but still getting this error, while inserting its working fine. Only edit is not working.
This my controller code:
if (!empty($this->data['UserProfileName']['new']['new_profile_id'])){
// $this->data['UserProfileName']['old_profile_id'] = $this->data['UserProfileName']['profile_id'];
$new_data['UserProfileName']['profile_id'] = $this->data['UserProfileName']['new']['new_profile_id'];
$new_data['UserProfileName']['user_profile_id']=$userProfileId;
$this->UserProfileName->create();
$this->UserProfileName->set($new_data);
}
$this->UserProfileContact->set($this->data);
if ($this->UserProfileName->validates() && $this->UserProfileContact->validates()) {
} else {
$errors = $this->UserProfileName->validationErrors;
$errors = $this->UserProfileContact->validationErrors;
pr($this->UserProfile->validationErrors);
pr($errors);
}
The form input $this->data is:
Array
(
[UserProfile] => Array
(
[id] => 1
[expiry_date] => 2017-06-30
[is_remarriage] => 0
[is_featured] => 1
[featured_date] => 2015-06-30
[featured_expity_date] => 2015-07-15
[language_id] => 1
[name] => Profile1
[gender_id] => 1
[date_of_birth] => 1988-06-30
[time_of_birth] => Array
(
[hour] => 05
[min] => 11
[meridian] => pm
)
[place_of_birth] => Trichy
[religion_id] => 1
[caste_id] => 3
[sub_caste_id] => 2
[community_id] => 3
[gothram_id] => 3
[star_id] => 5
[rasi_id] => 5
[food_habbit_id] => 2
[height] => 145
[height_type_id] => 1
[weight] => 50
[complexion_id] => 2
[blood_group_id] => 7
[disability_id] =>
[other_disability] =>
[talents] => Singing
[hobbies] => Handicrafts
[languages_konwn] => Tamil, English,Hindi
[qualification_id] => 1
[other_qualification] =>
[employment_type_id] => 5
[job_details] =>
[income] =>
[income_type_id] => 1
[parents_alive_type_id] => 2
[father_name] => Fname
[father_job] => Business
[mother_name] => Mname
[mother_job] => house wife
[mother_caste_id] => 3
[brothers_elder] => 2
[brothers_younger] =>
[brothers_married] => 1
[sisters_elder] =>
[sisters_younger] =>
[sisters_married] =>
[family_status_id] => 2
[marital_status_id] =>
[date_of_marriage] =>
[date_of_divorce] =>
[lived_together_duration] =>
[cilidrean_details] =>
[other_info] =>
[is_show_photo] => 1
)
[UserProfileName] => Array
(
[0] => Array
(
[id] => 1
[profile_id] => Profile1001
)
[new] => Array
(
[new_profile_id] =>
)
)
[PropertyType] => Array
(
[PropertyType] => Array
(
[0] => 1
[1] => 4
)
)
[UserProfileExpectation] => Array
(
[id] => 1
[qualification_id] => 2
[job_requirement_type_id] => 1
[preferred_place_of_job] => With in Tamil nadu
[min_income] => 900000/ann
[caste_id] => 3
[sub_caste_id] => 1
[community_id] => 1
[food_habbit_id] => 2
[marital_status_id] => 1
[is_horoscope_matching_required] => 1
[is_accept_disablity] => 0
[other_expectation] =>
)
[UserProfileHoroscopeDetail] => Array
(
[id] => 1
[balance_dasa_name] => sun
[balance_dasa_years] => 12
[balance_dasa_months] => 9
[balance_dasa_days] => 25
[rasi_1] => sss
[rasi_2] => hggf
[rasi_3] => ffgd
[rasi_4] =>
[rasi_12] =>
[rasi_5] =>
[rasi_11] =>
[rasi_6] => dfgd
[rasi_10] =>
[rasi_9] => fgdfd
ghg
fgf
[rasi_8] =>
[rasi_7] =>
[amsam_1] =>
[amsam_2] => fg
[amsam_3] =>
[amsam_4] =>
[amsam_12] => fghfg
[amsam_5] => fghfg
[amsam_11] => fgf
[amsam_6] =>
[amsam_10] =>
[amsam_9] =>
[amsam_8] => fghf
[amsam_7] =>
)
[UserProfileContact] => Array
(
[email] => jayashree+profile25#jbcs.co.in
[permanent_address] => fhgfhg
[permanent_country_id] => 1
[permanent_zone_id] => 1
[permanent_city_id] => 1
[local_address] =>
[local_country_id] => 1
[local_zone_id] => 1
[local_city_id] => 1
[phone_1] => 2134657898
[phone_2] =>
[phone_3] =>
[phone_4] =>
)
[images] => Array
(
[1] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)
[2] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)
[3] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)
)
)`
It always goes to else part, but when I print the error array it's empty.

Try this and modify according your requirement.
if(!empty($this->data))
{
$this->User->set( $this->data['User'] );
$this->Contractor->set( $this->data['Contractor'] );
if ($this->User->validates() && $this->Contractor->validates())
{
$this->data['User']['passwd'] = $this->Auth->password($this->data['User']['new_passwd']);
$this->data['User']['created'] = date("Y-m-d H:i:s");
$user = $this->data['User'];
$contractor = $this->data['Contractor'];
//pr($this->data);die;
if( $this->User->save( $user ) )
{
$newId = $this->User->getLastInsertId();
$contractor['user_id'] = $newId;
if($this->Contractor->save($contractor))
{
$this->redirect('/contractors/index') ;
}
}
}else{
$this->validateErrors($this->User);
$this->validateErrors($this->Contractor);
$this->render();
}
}

I have solved the issue by change the validation rule
in validation rule i've used
'required' => 'create',
and changed to
'on' => 'create',
now its working.

Related

Multiply data in array

I'm keeping data in Array, I want to multiply these data with each other, but I was not successful. I found the Array_product function but I could not run it successfully. What do you think the problem is?
$kuponlar = $_SESSION['kuponlar'];
$maclar = $kuponlar['maclar'];
The data I want to multiply:
echo array_product($maclar['oran']));
array_product does not work when I want to do. Is there a recommendation that the problem could not find?
Array
(
[maclar] => Array
(
[5ca4fb869b043] => stdClass Object
(
[mac_id] => 881
[mac_kod] => 657
[mac_lig] => HIR
[mac_zaman] => 04.04.2019
[mac_saat] => 19:00
[mac_slug] => rudes/istra/657
[mac_handikap] => 1
[ev_logo] => 12644
[deplasman_logo] => 6776
[iddaa_id] => 1308487
[evsahibi] => Rudes
[deplasman] => Istra
[ulke] => Hırvatistan 1. Ligi
[mac_tarihi] => 04.04.2019 19:00:00
[sonuc] =>
[live] => 0
[mac_uniq] => 5ca4fb869b043
[count] => 1
[tahmin] => Ev Kazanır
[oran] => 2.85
[durum] => 0
)
[5ca4fb869bf78] => stdClass Object
(
[mac_id] => 882
[mac_kod] => 658
[mac_lig] => HOL
[mac_zaman] => 04.04.2019
[mac_saat] => 19:30
[mac_slug] => psv/zwolle/658
[mac_handikap] => -1
[ev_logo] => 2836
[deplasman_logo] => 2869
[iddaa_id] => 1306687
[evsahibi] => PSV
[deplasman] => Zwolle
[ulke] => Hollanda Eredivisie Ligi
[mac_tarihi] => 04.04.2019 19:30:00
[sonuc] =>
[live] => 0
[mac_uniq] => 5ca4fb869bf78
[count] => 1
[tahmin] => Ev Kazanır
[oran] => 1.10
[durum] => 0
)
[5ca4fb869cde3] => stdClass Object
(
[mac_id] => 883
[mac_kod] => 660
[mac_lig] => İTA
[mac_zaman] => 04.04.2019
[mac_saat] => 20:00
[mac_slug] => sassuolo/chievo/660
[mac_handikap] =>
[ev_logo] => 665
[deplasman_logo] => 578
[iddaa_id] => 1333704
[evsahibi] => Sassuolo
[deplasman] => Chievo
[ulke] => İtalya Serie A Ligi
[mac_tarihi] => 04.04.2019 20:00:00
[sonuc] =>
[live] => 0
[mac_uniq] => 5ca4fb869cde3
[count] => 1
[tahmin] => Beraberlik
[oran] => 3.20
[durum] => 0
)
)
[summary] => Array
(
[total] => 1
[count] => 0
)
)
You need to multiply the property oran of each object in your array:
$maclar = $kuponlar['maclar'];
$mul = 1;
foreach($maclar as $key => $value){
$mul *= $value->oran;
}
You don't have 'oran' index in $maclar array, at first you should make an array of 'oran' then use array_product on that array.
for example:
foreach($maclar as $key=>$object){
$oran[] = $object->oran;
}
echo array_product($oran);

how to convert data type from result_object codeigniter

I have an array of objects from the query as follows :
Array
(
[0] => stdClass Object
(
[row_number] => 1
[cash_id] => 30938
[closing_id] =>
[is_closed] => 0
[cash_date] => 2018-04-03
[store_id] => 13
[store_code] => 504
[store_account] => ST0013
[store_vendor] => ES0013
[store_dwds] => 01R-0101A006S0013
[store_name] => KARTIKA CHANDRA
[area_id] => 11
[area_code] => A11
[area_name] => Area 11
[region_id] => 1
[region_code] => R01
[region_name] => Region 1
[closing_date] =>
[closing_type] =>
[closing_type_desc] =>
[cash_amount] => 6000000.0000
[closing_amount] =>
[update_time] =>
[update_by_username] =>
[update_by_first_name] =>
[update_by_last_name] =>
[update_by_email] =>
)
[1] => stdClass Object
(
[row_number] => 1
[cash_id] => 30938
[closing_id] =>
[is_closed] => 0
[cash_date] => 2018-04-03
[store_id] => 13
[store_code] => 504
[store_account] => ST0013
[store_vendor] => ES0013
[store_dwds] => 01R-0101A006S0013
[store_name] => KARTIKA CHANDRA
[area_id] => 11
[area_code] => A11
[area_name] => Area 11
[region_id] => 1
[region_code] => R01
[region_name] => Region 1
[closing_date] =>
[closing_type] =>
[closing_type_desc] =>
[cash_amount] => 6000000.0000
[closing_amount] =>
[update_time] =>
[update_by_username] =>
[update_by_first_name] =>
[update_by_last_name] =>
[update_by_email] =>
)
)
how do i change the is_closed object into a boolean data type ?
thanks,
You'll have to cast it to a boolean in your loop when you use it.
array_walk($Result, function ($item) {
$item->is_closed = (bool) $item->is_closed;
});

How to get the value from array php

Here is my value for print_r($_GET);
the Output is
Array(
[prevurl() ] => Array(
[taxirate] => 3500[Source] => Land[T] => Yes[TId] => 10[dtaxirate] => 4500[TD] => Yes[TDId] => 14[modeset] => minivan[minivanrate] => 400[Minivan] => Yes[MinivanId] => 6[FirstSearch] => FirstSearch[returnTrip] => yes[return -one] => No[Trip] => OneWay[TravelFrom] => Destination[TravelTo] => Pak[TravelDay] => 2015 - 08 - 16[TotalCount] => 1[Mode] => [Both] => [BothReturn] => 2015 - 08 - 17[Adults] => 1[Childs] => [Kids] => [Babies] =>
)
)
I tried
echo $_GET['prevurl']['taxirate']; but it is not working.
How can i get the value of taxirate
<input type="hidden" value="Array
(
[taxirate] => 3500
[Source] => Land
[T] => Yes
[TId] => 10
[dtaxirate] => 4500
[TD] => Yes
[TDId] => 14
[modeset] => minivan
[minivanrate] => 400
[Minivan] => Yes
[MinivanId] => 6
[FirstSearch] => FirstSearch
[returnTrip] => yes
[return-one] => No
[Trip] => OneWay
[TravelFrom] => Hat Yai Airport
[TravelTo] => Pak Bara
[TravelDay] => 2015-08-16
[TotalCount] => 1
[Mode] =>
[Both] =>
[BothReturn] => 2015-08-17
[Adults] => 1
[Childs] =>
[Kids] =>
[Babies] =>
)
" name="prevurl">
Update :
Note :
Here is my input in the previous page
<input type="hidden" value="Array
(
[taxirate] => 3500
[Source] => Land
[T] => Yes
[TId] => 10
[dtaxirate] => 4500
[TD] => Yes
[TDId] => 14
[modeset] => minivan
[minivanrate] => 400
[Minivan] => Yes
[MinivanId] => 6
[FirstSearch] => FirstSearch
[returnTrip] => yes
[return-one] => No
[Trip] => OneWay
[TravelFrom] => Hat Yai Airport
[TravelTo] => Pak Bara
[TravelDay] => 2015-08-16
[TotalCount] => 1
[Mode] =>
[Both] =>
[BothReturn] => 2015-08-17
[Adults] => 1
[Childs] =>
[Kids] =>
[Babies] =>
)
" name="prevurl()">
Actually the input was an array
Assuming the array value is stored in a variable, I would try:
<?php
foreach ($array_data as $key=>$value)
{
if($key == "prevurl")
{
foreach ($value as $key1=>$value1)
{
switch($key1)
{
case "taxirate":
$taxirate = $value1;
break;
}
}
}
}
?>
But I agree with Rasclatt. That array is odd looking/something weird with it.
Edit: Your original question looked like a multidimensional array, but your edit doesn't look multidimensional. My answer was from your original code.
just change your hidden input fields name to name="prevurl". And get your value of taxirate as:
$_GET['prevurl']['taxirate'];

how to find nearest lower and upper value of sp?

Example:
Array
(
[0] => stdClass Object
(
[Big] => 1.32
[FAN_MODEL] => AFPV3G-500-2800
[FAN_DIA] => 500
[FAN_RPM] => 2800
[FAN_SERIES_NAME] => AFPV3G
[BigVALUE] => 26.00
[FAN_CMH] => 10000
[BigPEAK_POWER] => 800.00
[Bigoutlet_velocity] => 14.15
[velocity_pressure] => 12.253
[Bigtotal_velocity] => 13.57
[SP1] => 8
[SP2] => 5
[SP3] => 7
[SP4] => 7
[SP5] => 7
[SP6] => 7
[SP7] => 7
[SP8] => 7
[SP9] => 7
[SP10] => 7
[Bigtotal_eff] => 0.33
[static_eff] => 0.03
[BigBKW] => 1.120
)
[1] => stdClass Object
(
[STATIC_PRESSURE] => 0.34
[FAN_DIA] => 630
[FAN_RPM] => 1460
[FAN_MODEL] =>
[FAN_SERIES_NAME] => AFPV3G
[BLADE_ANGLE_VALUE] => 25.00
[FAN_CMH] => 10000
[EQU_PEAK_POWER] => 3601.86
[outlet_velocity] => 8.92
[velocity_pressure] => 4.862
[total_velocity] => 5.20
[SP2] => 14
[SP3] => 42
[SP4] => 41
[SP5] => 1
[SP6] => 4
[SP7] => 4
[SP8] => 4
[SP9] => 4
[SP10] => 1
[total_eff] => 0.29
[static_eff] => 0.19
[BKW] => 0.486
[Big] => 3.86
[BigVALUE] => 26.00
[BigPEAK_POWER] => 360.19
[Bigoutlet_velocity] => 8.92
[Bigtotal_velocity] => 8.72
[SP1] => 1
[Bigtotal_eff] => 0.43
[BigBKW] => 0.547
)
[2] => stdClass Object
(
[SP1] => 1
[FAN_MODEL] =>
[Big] => 3.86
[FAN_DIA] => 630
[FAN_RPM] => 1460
[FAN_SERIES_NAME] => AFPV3G
[BigVALUE] => 26.00
[FAN_CMH] => 10000
[BigPEAK_POWER] => 360.19
[Bigoutlet_velocity] => 8.92
[velocity_pressure] => 4.862
[Bigtotal_velocity] => 8.72
[SP2] => 14
[SP3] => 42
[SP4] => 41
[SP5] => 1
[SP6] => 4
[SP7] => 4
[SP8] => 4
[SP9] => 4
[SP10] => 1
[Bigtotal_eff] => 0.43
[static_eff] => 0.19
[BigBKW] => 0.547
)
[3] => stdClass Object
(
[Big] => 23.69
[FAN_MODEL] =>
[FAN_DIA] => 710
[FAN_RPM] => 1450
[FAN_SERIES_NAME] => AFPV3G
[BigVALUE] => 25.00
[FAN_CMH] => 10000
[BigPEAK_POWER] => 6414.48
[Bigoutlet_velocity] => 7.02
[velocity_pressure] => 3.014
[Bigtotal_velocity] => 26.70
[SP1] => 3
[SP2] => 4
[SP3] => 5
[SP4] => 6
[SP5] => 7
[SP6] => 3
[SP7] => 2
[SP8] => 1
[SP9] => 2
[SP10] => 3
[Bigtotal_eff] => 0.62
[static_eff] => 0.55
[BigBKW] => 1.180
)
)
i have to find nearest value in each set of sp1 to sp10 for array[0]->with STATIC_PRESSURE=0.34,
aray[2]->1
array[3]->23.and so on..
Please help me out here i m struct.
This searches the highest value in each array keys with name "SPx" where x means a digit, maybe you can built up on this because i dont understand what you mean "with STATIC_PRESSURE=0.34, aray[2]->1 array[3]->23.and so on.."
$count = 0;
$max = array();
foreach ($array as $values) {
$max[$count] = 0;
foreach ($values as $key => $val) {
if(preg_match('/SP\d/', $key)===1){
if($val>$max[$count]){
$max[$count] = $val;
}
}
}
$count++;
}
var_dump($max);

How to sort same next value in foreach loop using php?

I new to PHP. What I want to do is hide the same data in a foreach loop.
Here is my code:
foreach($recording_record as $row ){
echo $row->criteria_title;
echo $row->question_title;
}
My current interface:
How I want my interface to be:
Here is my print_r data:
Array ( [0] => stdClass Object ( [record_id] => 6 [qm_id] => 2 [qm_title] => QM LEAD 2 [record_filename] => abcdefgh.mp3 [userid] => 1002 [unique_id] => 1325554791.71044 [supervisor_id] => 1000 [date_created] => 2013-05-14 05:29:24 [status] => 3 [id] => 6 [callid] => 1325554791.71044 [callerid] => 0383153394 [queuename] => t1-BM_OE [extension] => SIP/1003 [ivrtime] => 2013-05-14 11:14:36 [queuetime] => 2012-01-03 09:40:33 [connecttime] => 2013-05-09 09:40:36 [disconnecttime] => 2012-01-03 09:46:34 [callduration] => 358 [holdduration] => 0 [queueduration] => 3 [ansduration] => 3 [ringduration] => 0 [lastevent] => COMPLETEAGENT [transfer] => [wrapups] => ,12 [tenantid] => 1 [supervisor] => 1005 [username] => Fara [userpass] => 1234 [lastname] => Binti Johari [firstname] => Nurul Farahhin [userlevel] => 2 [usercreated] => 2011-03-26 23:11:56 [lastlogin] => 2012-10-13 20:17:10 [userexten] => [sessionid] => [userstatusid] => 0 [apptype] => webagent [statustimestamp] => 2012-10-13 20:33:21 [lastuserstatusid] => 1 [pqueuetimeout] => 0 [queueroutetype] => 1 [queueroutevalue] => 4 [userdbstatus] => A [criteria_id] => 1 [criteria_title] => Did not demonstrate inappropriate behavior - Zero Tolerance Policy [criteria_rate] => 40 [question_id] => 4 [question_title] => Question 2 [question_type] => n [question_score_y_yes] => [question_score_y_no] => [question_score_y_answer] => [question_score_y] => [question_score_n_a] => 1 [question_score_n_a_value] => True [question_score_n_b] => 0 [question_score_n_b_value] => False [question_score_n_c] => 0 [question_score_n_c_value] => [question_score_n_d] => 0 [question_score_n_d_value] => [question_score_n_e] => 0 [question_score_n_e_value] => [question_score_n_answer] => [question_score_n] => ) [1] => stdClass Object ( [record_id] => 6 [qm_id] => 2 [qm_title] => QM LEAD 2 [record_filename] => abcdefgh.mp3 [userid] => 1002 [unique_id] => 1325554791.71044 [supervisor_id] => 1000 [date_created] => 2013-05-14 05:29:24 [status] => 3 [id] => 6 [callid] => 1325554791.71044 [callerid] => 0383153394 [queuename] => t1-BM_OE [extension] => SIP/1003 [ivrtime] => 2013-05-14 11:14:36 [queuetime] => 2012-01-03 09:40:33 [connecttime] => 2013-05-09 09:40:36 [disconnecttime] => 2012-01-03 09:46:34 [callduration] => 358 [holdduration] => 0 [queueduration] => 3 [ansduration] => 3 [ringduration] => 0 [lastevent] => COMPLETEAGENT [transfer] => [wrapups] => ,12 [tenantid] => 1 [supervisor] => 1005 [username] => Fara [userpass] => 1234 [lastname] => Binti Johari [firstname] => Nurul Farahhin [userlevel] => 2 [usercreated] => 2011-03-26 23:11:56 [lastlogin] => 2012-10-13 20:17:10 [userexten] => [sessionid] => [userstatusid] => 0 [apptype] => webagent [statustimestamp] => 2012-10-13 20:33:21 [lastuserstatusid] => 1 [pqueuetimeout] => 0 [queueroutetype] => 1 [queueroutevalue] => 4 [userdbstatus] => A [criteria_id] => 1 [criteria_title] => Did not demonstrate inappropriate behavior - Zero Tolerance Policy [criteria_rate] => 40 [question_id] => 3 [question_title] => Question 1 [question_type] => y [question_score_y_yes] => 1 [question_score_y_no] => 0 [question_score_y_answer] => [question_score_y] => [question_score_n_a] => [question_score_n_a_value] => [question_score_n_b] => [question_score_n_b_value] => [question_score_n_c] => [question_score_n_c_value] => [question_score_n_d] => [question_score_n_d_value] => [question_score_n_e] => [question_score_n_e_value] => [question_score_n_answer] => [question_score_n] => )
Any idea how to do it?
$i = 0;
$criteria = array();
foreach($recording_record as $row ){
$criteria[$i] = $row->criteria_title;
if($i > 0){
if ($criteria[$i] != $criteria[$i-1]){
echo $criteria[$i];
}
} else {
echo $criteria[$i];
}
echo $row->question_title;
$i++;
}
Use this
$new_recording_record = array_unique($recording_record);
try this:
echo $recording_record[0]->criteria_title;
foreach($recording_record as $row ){
echo $row->question_title;
}
Check if this works?
$i = 1;
foreach($recording_record as $row ){
$title = $row->criteria_title;
$question_title = $row->question_title;
if($ငငငi==1)
echo $title;
echo $question_title;
$i++;
}

Categories