Yii model default DB values

Great tip if your working with the PHP-framework Yii, if you create a new model and want to set some default values, like ”order by”, you can just add the following function (defaultScope) to your CActiveRecord extended class:

public function defaultScope(){
return array(
‘order’=>’my_order_field DESC’

Read more here: http://www.yiiframework.com/doc/guide/1.1/en/database.ar


Raspberry PI – disable screen saver for X

I just got my hands on a raspberry PI, and the first problem I ran into was that the screen is going black after a couple of minuts. It does not seems to be a simple way to solve this, but I found three solutions online and I will summon them up here. Just follow the steps in each:

X-Server setting:

  1. Run this to install utilities (if not installed): apt-get install x11-xserver-utils
  2. Create (if not exists) this file in your home directory: ~/.xinitrc
  3. Open thie file: sudo nano ~/.xinitrc
  4. Add the following four lines:
    xset s off
    xset -dpms
    xset s noblank
    exec /etc/alternatives/x-session-manager
  5. Save and exit

Lightdm setting:

  1. sudo nano /etc/lightdm/lightdm.conf
  2. In that file, look for: [SeatDefault]
  3. Insert this: xserver-command=X -s 0 dpms

KDB settings:

  1. Run: sudo nano /etc/kbd/config
  2. Change the value ”BLANK_TIME=30” to ”BLANK_TIME=0”
  3. Change the value ”POWERDOWN_TIME=30” to ”POWERDOWN_TIME=0”
  4. Save exit nano
  5. Run: sudo /etc/init.d/kbd restart


Completing all these steps solved the problem for me =)

WordPress (WP) wp_list_pages returns null

I recently had a problem with wordpress 3.6 and the function wp_list_pages within my template. I know my page had subpages, but when I executed the code the function returned NULL. After doing some digging I found that when wp_list_pages runs, it applys a ”exlcude”-filter, and somewhere on the way this filter added all my pages to it. I tried deactivating all plugins, search all code for the exclude filter funtion and tried another theme but it did not work.

So for now I just added comment marks infront of line 842 in fil ”wp-includes/post-template.php” which temporarly solved the problem.

I know this is the forbidden way so solve it =) so if someone has a better solution, please put it in the comment section.

WordPress child menu allways from top

* Submenu
if ($post->post_parent)    {
$parent = $ancestors[$root];
} else {
$parent = $post->ID;
echo ”Parent: $parent”;
$children = wp_list_pages(‘title_li=&child_of=’.$parent.’&echo=0′);

if($children) { echo(‘<ul>’.$children.'</ul>’); }

TYPO3 social sharelinks with typoscript

Here is a ”simple” typoscript” to create sharelinks with just typoscript:

lib.field_footerleft = COA
lib.field_footerleft {
wrap = <div class="shareLinksfooter"><h3>Dela länkar</h3>|</div>

10 = TEXT
10.wrap = <p>|</p>
10 {
value = Facebook
typolink.title = Dela på Facebook
typolink.ATagParams = class=”facebooklink”
typolink.parameter.cObject = COA
typolink.parameter.cObject {
10 = TEXT
10.dataWrap = http://www.facebook.com/sharer.php?u={$baseURL}|
10.typolink.parameter.data = getenv:HTTP_HOST
10.typolink.returnLast = url
10.typolink.addQueryString = 1
10.typolink.addQueryString.exclude = id

20 = TEXT
20.data = getenv:REQUEST_URI

30 = TEXT
30.data = page:title
30.wrap = &t=|
30.rawUrlEncode = 1

20 = TEXT
20.wrap = <p>|</p>
20 {
value = Twitter
typolink.title = Dela på Twitter
typolink.ATagParams = class=”twitterlink”
typolink.parameter.cObject = COA
typolink.parameter.cObject {
10 = TEXT
10.data = getenv:HTTP_HOST
10.noTrimWrap = |Spana%20in%20||
10.dataWrap = http://twitter.com/home/?status=|
10.rawUrlEncode = 1

20 = TEXT
20.dataWrap = /|
20.typolink.parameter.data = TSFE:id
20.typolink.returnLast = url
20.typolink.addQueryString = 1
20.typolink.addQueryString.exclude = id

30 = TEXT
30.wrap = <p>|</p>
30 {
value = Google plus
typolink.title = Dela på Google plus
typolink.ATagParams = class=”googlepluslink”
typolink.parameter.cObject = COA
typolink.parameter.cObject {
10 = TEXT
10.dataWrap = https://plus.google.com/share?url={$baseURL}|
10.typolink.parameter.data = getenv:HTTP_HOST
10.typolink.returnLast = url
10.typolink.addQueryString = 1
10.typolink.addQueryString.exclude = id

20 = TEXT
20.data = getenv:REQUEST_URI



Responsive slider with fixed height

If you want to have a fixed height for a responsive-slider, you must disable ”max-width” and set width and height to auto. This is NOT a solution for a specific slideshow, just a general thinking of how to solve it.


.slider img {
max-width: none;
height: auto;
width: auto;

Then you can set your height for the container div.

Javascript associative array (objects)

Javascript does not have associative arrays, only key numbered arrays. But it is posible to use javascript objects and let them behave as associative arrays, example:

//-- Create object<script>
var myObject = { 'level1': {'level1-sub1' : 'value 1 1', 'level1-sub2' : 'value 1 2', 'level1-sub3' : 'value 1 3'},
'level12' : {'level2-sub1' : 'value 2 1', 'level2-sub2' : 'value 2 2', 'level2-sub3' : 'value 2 3'},
'level13' : {'level3-sub1' : 'value 3 1', 'level3-sub2' : 'value 3 2', 'level3-sub3' : 'value 3 3'}};

//-- Loop object
function loopObj(myObject)
for (i in myObject) {
if (typeof myObject[i] === 'object') {
} else {


Javascript objects can be read in two ways, myObject.myKey or myObject[‘myKey’]. The second ways has to be used if you want to loop throw all keys.

Read this blog post for more info: http://www.quirksmode.org/js/associative.html