Git Product home page Git Product logo

yii2-serialized-attributes-behavior's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

yii2-serialized-attributes-behavior's Issues

You could add a Validator

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.

Exeption

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.

serialized data in database

Save serialized data in database through base64_encode, and get through base64_decode.
It helps avoid popular error with offset

Preserve Order after Deserialization

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.