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

18 hours ago koushki opened a pull request in UnionOfRAD/lithium

Bug in Router::match

Router::match doesn't work as expected when an scope is attached with absolute parameter.
20 hours ago koushki forked UnionOfRAD/lithium

UnionOfRAD/lithium currently has:

20 hours ago koushki started watching UnionOfRAD/lithium

UnionOfRAD/lithium currently has:

20 hours ago koushki started watching UnionOfRAD/lithium

UnionOfRAD/lithium currently has:

3 days ago blissland started watching scharrier/li3_socialauth

scharrier/li3_socialauth currently has:

Ignore duplicate scripts, styles and head inserted via helpers and handlers

Extended helpers and handlers for scripts, styles and head to ignore duplicate entries. Prevents a duplicate HTML tag from being inserted into the script, style or head contexts. Also works for inline. Previously calling ```$this->html->script(array('foo', 'bar', 'foo'));``` would generate the following: ```` <script type="text/javascript" src="/js/foo.js"></script> <script type="text/javascript" src="/js/bar.js"></script> <script type="text/javascript" src="/js/foo.js"></script> ````` With this, the same call will only insert the foo and bar scripts once each, resulting in: ```` <script type="text/javascript" src="/js/foo.js"></script> <script type="text/javascript" src="/js/bar.js"></script> ````` Also works with successive ```$this->html->script('foo', array('inline' => false));``` calls, resulting in only one ```foo.js``` script being generated.
4 days ago ericcholis created a comment about an issue in UnionOfRAD/lithium

Ignore duplicate scripts, styles and head inserted via helpers and handlers

Excellent point @davidpersson, encouraging things like requirejs is the better solution here. ericcholis
5 days ago davidpersson created a comment about an issue in UnionOfRAD/lithium

Ignore duplicate scripts, styles and head inserted via helpers and handlers

Thanks for both your comments and also for providing the original use case. @ericcholis You're right my assumption was wrong, array_unique doesn't sort first. I'm personally using requirejs to load any js scripts and just keep some bootstrap scripts in the head. With styles, from time to time I add some conditionally in a view. So I don't know if I'm speaking for the majority of users out there, but I think script loading is probably best done outside the PHP framework (or at least should). We should promote those "best/better practices" . I think the original problem boils down to not being able to check if the script is already added, so a method to check would also do it. Unfortunately the scripts property of the context isn't populated by scripts added in the layout (this is because of 2-step rendering). So I don't see an easy way to implement this. davidpersson
5 days ago ericcholis created a comment about an issue in UnionOfRAD/lithium

Ignore duplicate scripts, styles and head inserted via helpers and handlers

Controlling insertion order would be a nice bonus, thanks @marcghorayeb. My use case came up only recently. I've got a few different elements that conditionally insert a script into the context. I only just noticed that the script was being inserted multiple times. Currently, I'm using a filter on ````style```` and ````script```` in my Html helper to eliminate duplicates. ```` $asset_exists = function ($self, $params, $chain) { $path = $params["path"]; $adapter = ($this->_context) ? $this->_context : false; if (!$adapter) { return $chain->next($self, $params, $chain); } $method = $chain->method(); if (!in_array($method, array("script","style"))) { return $chain->next($self, $params, $chain); } $method = "{$method}s"; $context = $adapter->$method(); if (stripos($context, $path) !== false) { return false; } return $chain->next($self, $params, $chain); }; ```` ericcholis
5 days ago marcghorayeb created a comment about an issue in UnionOfRAD/lithium

Ignore duplicate scripts, styles and head inserted via helpers and handlers

I had an extension that uses a weight option when you inserted a script/style. The files were then ordered using that weight before compilation / combination. You can check it out here: https://github.com/marcghorayeb/li3_assets I do not however remove filter on duplicate files - I didn't think it was needed :) marcghorayeb
5 days ago ericcholis created a comment about an issue in UnionOfRAD/lithium

Ignore duplicate scripts, styles and head inserted via helpers and handlers

I thought that ```array_unique``` still kept the original insertion order. On another note, looks like ````array_keys(array_flip($array))```` is much faster. It also keeps the original first-in insertion order. ```` $arr = ["bar", "baz", "foo", "baz", "foo", "bar"]; print_r(array_keys(array_flip($arr))); Array ( [0] => bar [1] => baz [2] => foo ) ```` Currently, the ````scripts```` handler and ````script```` helper don't let you control insertion order. So, the developer still has to be keen on where and when they've inserted scripts; to ensure the proper loading order when building the page. ericcholis
5 days ago davidpersson created a comment about an issue in UnionOfRAD/lithium

Ignore duplicate scripts, styles and head inserted via helpers and handlers

`array_unique` reorders the array and makes it more unpredictable which asset will be loaded in which order. While the idea is good (prevent the developer from making mistakes) - it has unexpected side effects and adds "automagic" behavior. davidpersson

Ignore duplicate scripts, styles and head inserted via helpers and handlers

Extended helpers and handlers for scripts, styles and head to ignore duplicate entries. Prevents a duplicate HTML tag from being inserted into the script, style or head contexts. Also works for inline. Previously calling ```$this->html->script(array('foo', 'bar', 'foo'));``` would generate the following: ```` <script type="text/javascript" src="/js/foo.js"></script> <script type="text/javascript" src="/js/bar.js"></script> <script type="text/javascript" src="/js/foo.js"></script> ````` With this, the same call will only insert the foo and bar scripts once each, resulting in: ```` <script type="text/javascript" src="/js/foo.js"></script> <script type="text/javascript" src="/js/bar.js"></script> ````` Also works with successive ```$this->html->script('foo', array('inline' => false));``` calls, resulting in only one ```foo.js``` script being generated.

Fixed case of assertNulL() method call

Fixed case of `$this->assertNulL()` to be consistent with PSR-1 camelCase method naming convention.

Fixed case of assertNulL() method call

Fixed case of `$this->assertNulL()` to be consistent with PSR-1 camelCase method naming convention.
7 days ago davidpersson pushed to UnionOfRAD/li3_docs

Better JS.!

7 days ago yfix forked UnionOfRAD/lithium

UnionOfRAD/lithium currently has:

7 days ago yfix started watching UnionOfRAD/lithium

UnionOfRAD/lithium currently has:

UnionOfRAD/lithium currently has:

UnionOfRAD/lithium currently has:

8 days ago davidpersson created a comment about an issue in UnionOfRAD/lithium

Fixed. Initial session read always throw the MissingSignatureException.

Hi @jovanialferez, if you have the time, it would be great if you could add a test case - to verify the issue has been fixed. davidpersson