baibaratsky / yii2-serialized-attributes-behavior Goto Github PK
View Code? Open in Web Editor NEWActiveRecord behavior that allows you to store arrays in attributes
License: Other
ActiveRecord behavior that allows you to store arrays in attributes
License: Other
It would be nice if one could also specify a special rule four such fields. Now I have to use safe for such fields.
E.g.:
public function rules() {
return [
[['my_field'], 'serialized', 'max' => 10000],
];
}
With max it could be checked that the string won't get truncated.
Error
Undefined index: <some index>
baibaratsky/yii2-serialized-attributes-behavior/SerializedAttributes.php at line 45
Problem with
...
$this->owner->setOldAttribute($attribute, $this->oldAttributes[$attribute]);
...
because
$this->oldAttributes
is empty by default in serialize function. Function setOldAttribute($name, $value) catches exception with empty $value
I do not know why you use this variable in start a function. In my way its removed from there.
I added a check for count($this->oldAttributes).
Best Regards, Bogdan.
Save serialized data in database through base64_encode, and get through base64_decode.
It helps avoid popular error with offset
Hello,
I have 2 models. One called Hotel and one called Amenities.
In model Hotel I have a multiple select field of amenities. When I change the order, it's saved in the database for example :
a:9:{
i:0;s:2:"30";
i:1;s:2:"31";
i:2;s:2:"33";
i:3;s:2:"27";
i:4;s:2:"35";
i:5;s:2:"40";
i:6;s:2:"34";
i:7;s:2:"42";
i:8;s:2:"43";
}
But when I use the deserialized attribute, the array is ordered by ID so It'll be :
Array => [
[0] => [27]
[1] => [30]
[2] => [31]
[3] => [33]
[4] => [34]
[5] => [35]
].....
How can I preserve the order after a deserialized attribute ?
Thank you for your help,
Rebecca
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.