Lithium 101

Lithium101 is an unofficial community resource for the Lithium PHP framework indexing articles, tutorials, code snippets and libraries.

Libraries

Tracking 261 plugins, categorised and sorted. If you are the plugin owner you can edit the status and category.

Snippets

So far there are 54 Lithium related snippets. It's super easy to add your gists as snippets on the site, if there is anything you think might be interesting or helpful take a minute to share it.

Latest Activity

Fix Database queryExport issue with related model's conditions

When using `limit` or using a `Find::('first')`, subsequent conditions are not applied in the query export array returned by `data\source\Database::_queryExport`. Questions: 1. Should I add a new case to the integration tests? (`CrudTest.php`?) 2. Should I remove the conditions that begin with the same table/model name? They are redundant in the subsequent query.
6 hours ago davidpersson created a comment about an issue in UnionOfRAD/lithium

Fix Database queryExport issue with related model's conditions

Committed your patch in bf55c063d3006211132583ee582ff2c869bb2ccf, added test in 89db7af1b638d14acfd4fea55b7e4b7397ba2299 and improved with suggested filtering in 6aeccbecba0ef96cd509bc05009191a8dac31900. davidpersson
9 hours ago davidpersson created a comment about an issue in UnionOfRAD/lithium
12 hours ago jails created a comment about an issue in UnionOfRAD/lithium
12 hours ago davidpersson created a comment about an issue in UnionOfRAD/lithium

Fields specified in relationships are ignored

@jails Are you working on this? Just asking as you've assigned yourself to the issue. davidpersson

Model::save() should only save updated fields

hi, in updating entity data , all fields that are selected, even they which didn't change will embed into query and they will store their datas. <b>It is dangerous risk !!</b> to becoming more clear i explain this with belove sample. <em>in controller A:</em> ```php $user = Users::find(1); $user->balance = 10; $user->save(); ``` <em>in controller B:</em> ```php $user = Users::find(1); $user->name = 'test'; $user->save(); ``` <ol> <li>Request for A : select user 1 (id = 1, balance = 0, name = 'your name') <li>Request for B : select user 1 (id = 1, balance = 0, name = 'your name') <li>Request for A : change balance and save data in database (balance = 10, name = 'your name') <li>Request for B : change name and save data in database (balance = 0, name = 'test') </ol> in above sample, in item 4, request shouldn't change `balance` field because `balance` hasn't changed in this request.
1 day ago koushki created a comment about an issue in UnionOfRAD/lithium

Why Model::update() doesn't return number of updated rows?

I think even this can implement for `Model::delete()` similarly. koushki
1 day ago anova started watching UnionOfRAD/lithium

UnionOfRAD/lithium currently has:

1 day ago gmercey opened an issue in UnionOfRAD/lithium

SQL error with LIMIT, ORDER and GROUP in the same request

Hi, I work with a Postgres database, and I found a problem with the model finder when there are limit, order and group instruction in the same request. Operation::find('all', array( 'conditions' => array(), 'with' => array('Partner', 'Code), 'fields' => array('Operation.*', 'Partner.name', 'COUNT(DISTINCT "Code".id) AS total_code'), 'group' => array('Operation.id', 'Partner.name'), 'order' => array('date_start' => 'DESC'), 'limit' => 5 )); It seems that it's caused by the first request done for the pagination. Here's the SQL error : for SELECT DISTINCT, ORDER BY, expressions must appear in the SELECT list (I translate the error message from french, so it might not be the exact translation) Thanks
1 day ago davidpersson created a comment about an issue in UnionOfRAD/lithium

Why Model::update() doesn't return number of updated rows?

A few question to allow us to decide if this feature can be added: - Can you describe your use case/s? - What is your current workaround? davidpersson
1 day ago davidpersson closed an issue in UnionOfRAD/lithium

Schema cast not working on $elemMatch

Tested on last data-branch HEAD from today. If I define a schema in a Model (e.g. Groups) ``` protected $_schema = array( '_id' => array('type' => 'id'), 'name' => array('type' => 'string'), 'members' => array('type' => 'object', 'array' => 'true'), 'members.user_id' => array('type' => 'id'), 'members.status' => array('type' => 'string'), ); ``` and do a find operation , with condition: ``` Groups::first(array('conditions' => array('members' => array('$elemMatch' => array('user_id' => $user['_id'], 'status' => 'activated'))))); ``` where `$user['_id']` is a string representation of a `MongoId` (like I get after calling ->data() method of Entity). The `user_id` will not be casted to MongoId by `Schema->cast()` and still remains as string in the query, resulting in an empty result set.
1 day ago davidpersson created a comment about an issue in UnionOfRAD/lithium

Schema cast not working on $elemMatch

Fixed by b51090684f9aaf1f74178cf2a018eaaa49fca44c. Thanks @koushki for the test and patch and @Daikoun for submitting the report and the patience :) davidpersson

Issue date casts mongo exists

Add a failing test to highlight a casting issue with `$exists` on `date` fields. PS: Discovered the hard way => emails sent to wrong users :bomb:
1 day ago davidpersson created a comment about an issue in UnionOfRAD/lithium

Issue date casts mongo exists

Fixed by b51090684f9aaf1f74178cf2a018eaaa49fca44c. Thanks @koushki for the test and patch and @mehlah for submitting the report. davidpersson
1 day ago davidpersson closed an issue in UnionOfRAD/lithium

Schema casting breaks mongo query operators

The query builder uses Model schema to cast `conditions` clauses. This can break special mongodb query operators such as `$exists` and `$size` when used on non-scalar field types such as `array`. I've committed a failing test case to a fork, the commit is here: https://github.com/warrenseymour/lithium/commit/7bf16f29304c2cb2d590fba2cf6aede648f843cb
1 day ago davidpersson created a comment about an issue in UnionOfRAD/lithium

Schema casting breaks mongo query operators

Fixed by b51090684f9aaf1f74178cf2a018eaaa49fca44c. Thanks @koushki for the test and patch and @warrenseymour for submitting the report. davidpersson
1 day ago davidpersson closed an issue in UnionOfRAD/lithium

Commands ignore character '0' as an argument

Very minor problem with the console argument parser. Arguments consisting of the sole character "0" are ignored. **Problem** ```shell $ li3 ArgTest 1 0 1 Resulting Params: [1, 1] ``` **Possible Solution** ```php /* lithium\console\Router::parse */ // Change: while ($arg = array_shift($args)) { // To: while (($arg = array_shift($args)) !== null) { ``` Thanks for all the hard work guys!
1 day ago davidpersson created a comment about an issue in UnionOfRAD/lithium

Commands ignore character '0' as an argument

Fixed by d964bf6bc3d42151700f52a4a846598b0d864f50. Thanks @farhadi for the test and patch and @adallaway for submitting the bug. davidpersson
1 day ago davidpersson closed an issue in UnionOfRAD/lithium

[RFC] Router parsing

My problem is illustrated here as a test case: https://gist.github.com/marcghorayeb/6061882 I was under the impression that both routes would be handled the same way, however, the first route fails when matching against the given case. I looked up the code and it seems that regex patterns are not passed through the Inflector which is understandable ;) Maybe this behavior should be documented ? Or maybe can we work something out to make this test case work ?
1 day ago davidpersson created a comment about an issue in UnionOfRAD/lithium

[RFC] Router parsing

Closed by 540c86f9be79ac7485a6e5b35dd9de472d025f25, thanks @jails for the patch and @marcghorayeb for submitting the original report and test case. davidpersson
1 day ago farhadi opened an issue in UnionOfRAD/lithium

Why model Model::update() doesn't return number of updated rows?

In most of cases after a `Model::update()` we need the number of updated rows. And we have to tweak the underlying resource to extract the number manually. I have always had this question why this method shouldn't return the number of updated rows out of the box. If there isn't any technical or logical limitation for this change, I think it's worth a BC break.

Not to casting conditions values for some of mongodb query operators.

Conditions values shouldn't cast when we use some of mongodb query operators (like $exists, $type, $mod, $size) on non-scalar fields. Issues #1091 and #1085 fixed.