I tried using Kohana/ORM on my localhost xampp and i get the following error
ErrorException [ Notice ]: Array to string conversion
MODPATH\orm\classes\kohana\orm.php [ 980 ]
975 }
976 else
977 {
978 // List columns and mirror for performance
979 $this->_table_columns = $this->list_columns();
980 $this->_table_columns = array_combine($this->_table_columns, $this->_table_columns);
981
982 // Load column cache
983 ORM::$_column_cache[$this->_object_name] = $this->_table_columns;
984 }
985 }
It seems to be a common error appearing in different Frameworks/PHP Applications, but I have not found any clue to fix it.
The Model is just the basic ORM
class Model_Product extends ORM {
}
The Mysql Table (InnoDB - UTF-8) has two fields
id - primary int
name - varchar 50
no voodoo anywhere, help is very appreciated
thanks in advance!
edit: the requested vardump
array(2) {
["id"]=>
array(13) {
["type"]=>
string(3) "int"
["min"]=>
string(11) "-2147483648"
["max"]=>
string(10) "2147483647"
["column_name"]=>
string(2) "id"
["column_default"]=>
NULL
["data_type"]=>
string(3) "int"
["is_nullable"]=>
bool(false)
["ordinal_position"]=>
int(1)
["display"]=>
string(2) "11"
["comment"]=>
string(0) ""
["extra"]=>
string(14) "auto_increment"
["key"]=>
string(3) "PRI"
["privileges"]=>
string(31) "select,insert,update,references"
}
["name"]=>
array(12) {
["type"]=>
string(6) "string"
["column_name"]=>
string(4) "name"
["column_default"]=>
NULL
["data_type"]=>
string(7) "varchar"
["is_nullable"]=>
bool(false)
["ordinal_position"]=>
int(2)
["character_maximum_length"]=>
string(2) "50"
["collation_name"]=>
string(15) "utf8_general_ci"
["comment"]=>
string(0) ""
["extra"]=>
string(0) ""
["key"]=>
string(0) ""
["privileges"]=>
string(31) "select,insert,update,references"
}
}
Line 980:
980 $this->_table_columns = array_combine($this->_table_columns, $this->_table_columns);
looks superfluous taken the previous line 979 into account:
979 $this->_table_columns = $this->list_columns();
Merging two times the same array is useless, especially as the array is this:
array(2) {
["id"]=>
array(13) {
["type"]=>
string(3) "int"
["min"]=>
string(11) "-2147483648"
["max"]=>
string(10) "2147483647"
["column_name"]=>
string(2) "id"
["column_default"]=>
NULL
["data_type"]=>
string(3) "int"
["is_nullable"]=>
bool(false)
["ordinal_position"]=>
int(1)
["display"]=>
string(2) "11"
["comment"]=>
string(0) ""
["extra"]=>
string(14) "auto_increment"
["key"]=>
string(3) "PRI"
["privileges"]=>
string(31) "select,insert,update,references"
}
["name"]=>
array(12) {
["type"]=>
string(6) "string"
["column_name"]=>
string(4) "name"
["column_default"]=>
NULL
["data_type"]=>
string(7) "varchar"
["is_nullable"]=>
bool(false)
["ordinal_position"]=>
int(2)
["character_maximum_length"]=>
string(2) "50"
["collation_name"]=>
string(15) "utf8_general_ci"
["comment"]=>
string(0) ""
["extra"]=>
string(0) ""
["key"]=>
string(0) ""
["privileges"]=>
string(31) "select,insert,update,references"
}
}
It only contains string keys. You should open a bug report with the kohana framework.
Comment line 980 until this get's fixed.
I found a way to resolve this error, just declare the table colums in the model.
protected $_table_columns = array(
'column' => NULL,
'names' => NULL,
'go' => NULL,
'here' => NULL,
......
);
this will ged rid of the problem and increase performance as well.
Related
I'm using cakephp 2.x and I would like to get certain element as field from my model. the problem is with my structure. If I use find all then I recieve this:
array(9) {
[0]=> ...
[1]=>
array(7) {
["Person"]=>
array(18) {
["id"]=>
int(2)
["imie"]=>
string(6) "STEFAN"
["nazwisko"]=>
string(8) "ŚMIAŁY"
["tel"]=>
string(13) "+55 648989748"
["mob"]=>
string(13) "+87 489747489"
["email"]=>
string(25) "HSDJKAHSDJK#HSDFJASHF.CIJ"
["tytul_naukowy"]=>
string(7) "TEZ NIE"
["data_od"]=>
string(10) "2017-02-16"
["data_do"]=>
NULL
["object_id"]=>
int(-1)
["object_type_id"]=>
int(2)
["duty_id"]=>
int(28)
["created"]=>
string(22) "2017-02-16 13:22:32+01"
["modified"]=>
string(22) "2017-02-16 13:22:32+01"
["deleted"]=>
int(0)
["additional_email"]=>
string(17) "UDIHAS#HFSDKFH.OK"
["description"]=>
string(4) "OPIS"
["displayName"]=>
string(15) "STEFAN ŚMIAŁY"
}
["Duty"]=>
array(3) {
["id"]=>
int(28)
["nazwa"]=>
string(20) "KOORDYNATOR RECEPCJI"
["atrybut"]=>
string(1) "W"
}
["ObjectType"]=>
array(3) {
["id"]=>
int(2)
["nazwa"]=>
string(4) "Obks"
["model"]=>
string(3) "Obk"
}
["Cro"]=>
array(12) {
["id"]=>
NULL
["created"]=>
NULL
["nazwa"]=>
NULL
["tel"]=>
NULL
["fax"]=>
NULL
["email"]=>
NULL
["www"]=>
NULL
["modified"]=>
NULL
["deleted"]=>
NULL
["cro_type_id"]=>
NULL
["displayName"]=>
NULL
["objectTypeIdWithId"]=>
NULL
}
["Attachment"]=>
array(0) {
}
["Specialization"]=>
array(0) {
}
["Obk"]=>
array(1) {
[0]=>
array(13) {
["id"]=>
int(2)
["nazwa"]=>
string(10) "OBK Z ID 2"
["tel"]=>
string(13) "+48 123456890"
["fax"]=>
string(13) "+48 123456789"
["email"]=>
string(15) "EMAIL#EMAIL.COM"
["www"]=>
string(11) "WWW.WWW.WWW"
["modified"]=>
string(22) "2017-03-20 15:11:31+01"
["created"]=>
string(22) "2014-05-12 21:50:17+02"
["deleted"]=>
int(0)
["local_order"]=>
int(3)
["displayName"]=>
string(10) "OBK Z ID 2"
["objectTypeIdWithId"]=>
string(3) "2_2"
["PeopleObk"]=>
array(3) {
["id"]=>
int(1)
["person_id"]=>
int(2)
["obk_id"]=>
int(2)
}
}
}
}
[2]=>
array(7) {
["Person"]=>
array(18) {
["id"]=>
int(3)
["imie"]=>
string(5) "KAMIL"
["nazwisko"]=>
string(10) "STEFAŃSKI"
["tel"]=>
string(13) "+23 123123123"
["mob"]=>
string(13) "+21 412312312"
["email"]=>
string(16) "ASDASD#SDFDSF.LS"
["tytul_naukowy"]=>
string(3) "NIE"
["data_od"]=>
string(10) "2017-02-22"
["data_do"]=>
NULL
["object_id"]=>
int(-1)
["object_type_id"]=>
int(2)
["duty_id"]=>
int(26)
["created"]=>
string(22) "2017-02-22 16:14:32+01"
["modified"]=>
string(22) "2017-02-22 16:14:32+01"
["deleted"]=>
int(0)
["additional_email"]=>
string(22) "ADAM.2313#WEBIMPULS.PL"
["description"]=>
string(4) "TEST"
["displayName"]=>
string(16) "KAMIL STEFAŃSKI"
}
["Duty"]=>
array(3) {
["id"]=>
int(26)
["nazwa"]=>
string(41) "KOORDYNATOR OŚRODKÓW BADAŃ KLINICZNYCH"
["atrybut"]=>
string(1) "W"
}
["ObjectType"]=>
array(3) {
["id"]=>
int(2)
["nazwa"]=>
string(4) "Obks"
["model"]=>
string(3) "Obk"
}
["Cro"]=>
array(12) {
["id"]=>
NULL
["created"]=>
NULL
["nazwa"]=>
NULL
["tel"]=>
NULL
["fax"]=>
NULL
["email"]=>
NULL
["www"]=>
NULL
["modified"]=>
NULL
["deleted"]=>
NULL
["cro_type_id"]=>
NULL
["displayName"]=>
NULL
["objectTypeIdWithId"]=>
NULL
}
["Attachment"]=>
array(0) {
}
["Specialization"]=>
array(0) {
}
["Obk"]=>
array(1) {
[0]=>
array(13) {
["id"]=>
int(3)
["nazwa"]=>
string(10) "OBK Z ID 3"
["tel"]=>
string(13) "+48 123456890"
["fax"]=>
string(13) "+48 123456789"
["email"]=>
string(15) "EMAIL#EMAIL.COM"
["www"]=>
string(11) "WWW.WWW.WWW"
["modified"]=>
string(22) "2017-03-20 10:45:24+01"
["created"]=>
string(22) "2014-05-16 09:09:33+02"
["deleted"]=>
int(0)
["local_order"]=>
int(1)
["displayName"]=>
string(10) "OBK Z ID 3"
["objectTypeIdWithId"]=>
string(3) "2_3"
["PeopleObk"]=>
array(3) {
["id"]=>
int(2)
["person_id"]=>
int(3)
["obk_id"]=>
int(3)
}
}
}
}
And I want just to retrieve Person.id, Person.displayName and Obk.0.id. The two first are no problem, but wheneve I try to get Obk.0.id I'm getting error: SQLSTATE[42P01]: Undefined table: 7 ERROR: missing FROM for Table Obk.
How can I get something like that? I want to set the value in codition later, but it block my work.
In CakePHP 2 you can specify the fields you want returned by a find() query using the fields option like:-
$this->Foo->find('all', [
'fields' => ['Foo.id', 'Foo.name']
]);
This also works with contained models that have a belongsTo or hasOne relationship:-
$this->Foo->find('all', [
'fields' => ['Foo.id', 'Foo.name', 'Bar.name'],
'contain' => ['Bar']
]);
However, if the contained model is a hasMany or HABTM relationship you need to specify the fields of that model on the contain:-
$this->Foo->find('all', [
'fields' => ['Foo.id', 'Foo.name'],
'contain' => [
'Bar' => ['fields' => 'Bar.name']
]
]);
This is because CakePHP will be performing multiple SQL queries, so the contain needs to have the parameters for the query being run for the relevant model.
I’m trying to make a purchase request to a Simulator end point (https://test.sagepay.com/Simulator/VSPDirectGateway.asp), with the following data:
array(35) {
["VPSProtocol"]=>
string(4) "2.23"
["TxType"]=>
string(7) "PAYMENT"
["Vendor"]=>
string(9) "MY VENDOR NAME"
["AccountType"]=>
string(1) "E"
["Description"]=>
string(13) "My Test Order"
["Amount"]=>
string(4) "1.50"
["Currency"]=>
string(3) "GBP"
["VendorTxCode"]=>
string(1) "3"
["ClientIPAddress"]=>
NULL
["ApplyAVSCV2"]=>
int(0)
["Apply3DSecure"]=>
int(0)
["BillingFirstnames"]=>
string(3) "Sam"
["BillingSurname"]=>
string(4) "King"
["BillingAddress1"]=>
string(1) "1"
["BillingAddress2"]=>
string(1) "2"
["BillingCity"]=>
string(8) "Brighton"
["BillingPostCode"]=>
string(3) "BN1"
["BillingState"]=>
string(0) ""
["BillingCountry"]=>
string(2) "GB"
["BillingPhone"]=>
NULL
["DeliveryFirstnames"]=>
NULL
["DeliverySurname"]=>
NULL
["DeliveryAddress1"]=>
NULL
["DeliveryAddress2"]=>
NULL
["DeliveryCity"]=>
NULL
["DeliveryPostCode"]=>
NULL
["DeliveryState"]=>
string(0) ""
["DeliveryCountry"]=>
NULL
["DeliveryPhone"]=>
NULL
["CustomerEMail"]=>
NULL
["CardHolder"]=>
string(8) "Sam King"
["CardNumber"]=>
string(16) "4012888888881881"
["CV2"]=>
string(3) "123"
["ExpiryDate"]=>
string(4) "0215"
["CardType"]=>
string(4) "visa"
}
However, all I repeatedly keep getting back from Sagepay is a validation error:
"The CardHolder field should be between 1 and 50 characters long.”
However, as you can see in the above data array, I’m sending a CardHolder value of ‘Sam King’, which is clearly between 1 and 50 characters long.
For reference, I'm using the Omnipay (https://github.com/thephpleague/omnipay) library to make requests.
Any idea what I could be doing wrong here?
This is my first post so hello there all!
Wondering could I get a bit of help with getting my results out of this md array? Its giving me unexpected results. I have looked for answers but am not sure what question I should be asking..
This is a sample of the relevant part of the array [using var_dump]:
["Attendee"] => array(11)
{
["id"]=> int(148)
["firstname"]=> string(5) "dave"
["lastname"]=> string(6) "davey"`
}
This is my foreach code to get the first and last names for each attendee:
foreach ($the_info_array['body']['Registrations'] as $registrations)
{
foreach ($registrations as $regvalue)
{
echo $regvalue['firstname'].” “.$regvalue['lastname'];
}
echo “<br>”;
}
This prints:
a a2 2 5 5 dave davey
a a2 2 5 5 scott davey
a a2 2 5 5 bill davey
etc
rather than what i want ie:
dave davey
scott davey
bill davey
Where am i going wrong, & what are the extra characters?
Thanks in advance for any kind help the community can give!
EDIT>>
Strangely, if I change the echo to
echo $regvalue['firstname'];
it prints:
a25dave
a25scott
a25bill
and
echo $regvalue['firstname']." ";
prints
a 2 5 dave
a 2 5 scott
a 2 5 bill
Here is the complete array minus several records as I can't seem to post that many characters:
array(3) {
["status"]=> string(2) "OK"
["status_code"]=> int(200)
["body"]=> array(1) {
["Registrations"]=> array(12) {
[0]=> array(15) {
["id"]=> int(148)
["status"]=> string(8) "approved"
["date_of_registration"]=> string(19) "2013-12-04 12:43:31"
["final_price"]=> int(0)
["code"]=> string(23) "529f2373bb7555.08033147"
["url_link"]=> string(0) ""
["is_primary"]=> bool(true)
["is_group_registration"]=> bool(true)
["is_going"]=> bool(true)
["is_checked_in"]=> bool(false)
["Event"]=> array(14) {
["id"]=> int(531) ["code"]=> string(15) "1-5298c3675e610"
["name"]=> string(21) "Recital 2014"
["description"]=> string(721) "The Description is this!"
["status"]=> string(6) "active"
["limit"]=> int(280)
["group_registrations_allowed"]=> bool(true)
["group_registrations_max"]=> int(50)
["active"]=> bool(true)
["member_only"]=> bool(false)
["virtual_url"]=> string(0) ""
["call_in_number"]=> string(0) ""
["phone"]=> string(0) ""
["metadata"]=> array(9) {
["default_payment_status"]=> string(10) "Incomplete"
["venue_id"]=> int(1)
["additional_attendee_reg_info"]=> string(1) "1"
["add_attendee_question_groups"]=> array(1) {
[1]=> string(1) "1" }
["date_submitted"]=> string(10) "29/11/2013"
["event_hashtag"]=> string(0) ""
["event_format"]=> string(0) ""
["event_livestreamed"]=> string(0) ""
[""]=> string(0) "" } }
["Attendee"]=> array(11) {
["id"]=> int(219)
["firstname"]=> string(5) “dave”
[“lastname”]=> string(7) "davis"
["address"]=> string(13) "10 The Street"
["address2"]=> string(0) ""
["city"]=> string(8) "The City"
["state"]=> string(10) "The County"
["country"]=> string(0) ""
["zip"]=> string(6) "BN66YY"
["email"]=> string(17) "mail#webhost.com"
["phone"]=> string(12) "012736654432" }
["Transaction"]=> array(9) {
["id"]=> int(219)
["timestamp"]=> string(19) "2013-12-23 00:26:22"
["total"]=> float(132.6)
["amount_paid"]=> int(0)
["status"]=> string(10) "incomplete"
["details"]=> string(0) ""
["tax_data"]=> string(0) ""
["session_data"]=> string(0) ""
["payment_gateway"]=> string(19) "Credit / Debit Card" }
["Datetime"]=> array(8) {
["id"]=> int(0) ["is_primary"]=> bool(true)
["event_start"]=> string(19) "2014-01-11 00:00:00"
["event_end"]=> string(19) "2014-01-11 00:00:00"
["registration_start"]=> string(19) "2012-08-12 16:00:00"
["registration_end"]=> string(19) "2014-01-10 16:00:00"
["limit"]=> int(280) ["tickets_left"]=> int(274) }
["Price"]=> array(9) {
["id"]=> int(0)
["name"]=> string(0) ""
["amount"]=> int(0)
["description"]=> string(0) ""
["limit"]=> int(9999999)
["remaining"]=> int(999999)
["start_date"]=> NULL
["end_date"]=> NULL
["Pricetype"]=> array(8) {
["id"]=> int(1)
["name"]=> string(10) "Base Price"
["is_member"]=> bool(false)
["is_discount"]=> bool(false)
["is_tax"]=> bool(false)
["is_percent"]=> bool(false)
["is_global"]=> bool(true)
["order"]=> int(0) } } } } } }
// Also, don't know if relevant, but the array comes from a json decode originally
The problem is that your looping over each array inside registrations even though most of these are not an attendee (i.e $regvalue will be an id in the first loop status in the second loop e.t.c.).
Try:
foreach ($the_info_array['body']['Registrations'] as $registrations)
{
echo $registrations['Attendee']['firstname']." ".$registrations['Attendee']['lastname'];
echo "<br>";
}
I'm new to PHP and am trying to access the value of "contactId" from the following:
object(stdClass)#2 (4) {
["contacts"]=> array(1) {
[0]=> object(stdClass)#3 (18) {
["email"]=> string(24) "joewilliams#icontact.com"
["firstName"]=> string(3) "Joe"
["lastName"]=> string(8) "Williams"
["prefix"]=> string(3) "Mr."
["suffix"]=> string(3) "Jr."
["fax"]=> string(0) ""
["phone"]=> string(10) "8668039462"
["street"]=> string(21) "2365 Meridian Parkway"
["street2"]=> string(0) ""
["city"]=> string(6) "Durham"
["state"]=> string(2) "NC"
["postalCode"]=> string(5) "27713"
["createDate"]=> string(19) "2013-03-30 21:22:28"
["status"]=> string(6) "normal"
["bounceCount"]=> NULL
["contactId"]=> string(8) "67295434"
}
}
["limit"]=> int(20)
["offset"]=> int(0)
["total"]=> int(1)
}
How can I retrieve the value of contactId?
Many thanks!
These are not arrays, but an object containing an array containing an object. PHP object access syntax is with ->
$variableName->contacts[0]->contactId
here is the obj :
array(2) {
[0]=> object(stdClass)#538 (9)
{
["term_id"]=> string(3) "152"
["name"]=> string(19) "Éducation physique"
["slug"]=> string(18) "education-physique"
["term_group"]=> string(1) "0"
["term_taxonomy_id"]=> string(3) "159"
["taxonomy"]=> string(11) "product_cat"
["description"]=> string(0) ""
["parent"]=> string(3) "123"
["count"]=> string(1) "3"
}
[1]=> object(stdClass)#540 (9)
{
["term_id"]=> string(3) "123"
["name"]=> string(5) "Sport"
["slug"]=> string(5) "sport"
["term_group"]=> string(1) "0"
["term_taxonomy_id"]=> string(3) "123"
["taxonomy"]=> string(11) "product_cat"
["description"]=> string(0) ""
["parent"]=> string(1) "0"
["count"]=> string(2) "49"
}
}
mam :
i try to get the value : [term_id] of 152. what i need it the "152" value in a variable. i try : $product_category->term_id it return "nothing"
and i try : $product_category['term_id'] it return "nothing"
How is the "proper" way to retreive value from object
thanks in advance !
If I'm reading you right, and $product_category is the entire variable, you have two objects in an array. So you'll need to tell PHP which array item you're after before trying to access the object.
Something like $product_category[0]->term_id should work.
Here is another solution :
Convert this object to an array using json_decode, then get the values from array
$array = json_decode($json_string, true);
$term_id = $array[0]['term_id'];
OR to get both values :
foreach($array as $val){
echo $val['term_id'];
}