mafflog
random stuff for teh interwebs
  • About
  • Projects
  • Archives
Home » Development

Enable Twig debug in Symfony2

January 13, 2012 · in Development, How-Tos, Snippets

To enable the debug tag in Twig, add the following to app/config/config_dev.yml

services:
    twig.extension.debug:
        class: Twig_Extensions_Extension_Debug
        tags:
            - { name: twig.extension }

Afterwards clear the cache and use the debug extension:

{% debug my_var %}

Sources

  • http://groups.google.com/group/symfony2/browse_thread/thread/40df2ca0b22b0166

eZPublish access/change user account from PHP

February 15, 2011 · in Development, How-Tos

It took me some time to figure out how to access and change a user account in eZPublish from PHP. Here’s an example how to achieve this:

<?php
// user node
$node = eZContentObjectTreeNode::fetch($nodeID);

// user object
$dataMap = $node->dataMap();

// change attribute
$firstname = $dataMap['firstname'];
$firstname->setAttribute('data_text', 'Foo');
$firstname->sync();

// user account attribute
$user = $dataMap['user_account'];
$userData = $user->content();

// user settings
$userSetting = eZUserSetting::fetch($user->ContentObjectID);

// get account status
$isEnabled = $userSetting->attribute('is_enabled');

// enable user account
$userSetting->setAttribute('is_enabled', 1);
$userSetting->store();

Or if you just want to access the user account object or the user setting directly:

<?php
// user account object
$user = eZUser::fetch($objectID);

// user settings
$userSetting = eZUserSetting::fetch($objectID);

Check broken links/rewrites with curl

April 16, 2010 · in Development, How-Tos, Linux

I just did a change in the URL structure of a bigger site and had to check if all existing URLs are rewritten correctly to the new structure. First I extracted a list of all URLs from the CMS of the old version and wrote them to a text file, each line containing an URL. Then I changed the structure and used the following shellscript to check each URL with curl and output the result. Afterwards it’s easy to analyze the results and check for broken links.

#!/bin/sh
while read f
do
  echo $f
  echo ""
  curl -IL --silent $f
  echo "------------------"
  echo ""
done < $1

Usage:

$ ./checklinks.sh links.txt > stats.txt
Continuous Integration with phpUnderControl and Git

Continuous Integration with phpUnderControl and Git

September 8, 2009 · in Development, How-Tos, Server

I was looking for a decent continuous integration solution for my PHP projects for some time now, but always had the problem that most of the described solutions used SVN instead of Git as VCS system. Yesterday I found an article which describes the setup exactly as I needed it: phpUnderControl with Git on a Debian/Ubuntu system. Using the article, I managed to set up a working system quickly, which basically works as expected: CruiseControl checks the repository for modifications and starts the build process if there are any new commits. The build process includes generating API documentation (phpdocumentor), running static code analysis (php-codesniffer) and executing unit tests (phpunit). If the build succeeds, the results are published and can be accessed through a nice webinterface powered by phpUnderControl (see screenshot above which I stole from the phpUnderControl site).

However, the described setup has a few issues which bugged me:

  1. CruiseControl runs from the shellscript as root, posts all output to the console and is not automatically started at boot time.
  2. CruiseControl runs on port 8080, but I wanted to manage access to the webinterface through the apache which is already running on the box
  3. There’s no authentication – everybody can access my CI server, see the build details and start new builds through the webinterface.

(more…)

FH Raumbelegung: iCal Support für Wochenübersicht

FH Raumbelegung: iCal Support für Wochenübersicht

June 19, 2009 · in Development, Projects

Ab sofort gibt es in meinem Raumbelegung-Webservice die Möglichkeit, die Wochenübersicht via iCal abzurufen. Dadurch lässt sich der Service komfortabel in Kalenderapplikationen (z.B. der Thunderbird-Extension Lightning) verwenden. Verwendung: einfach an eine Wochenübersicht den Parameter format/ical anhängen oder die entsprechenden Links am Ende der Übersicht verwenden.

Um zum Beispiel immer die aktuelle Woche des Studiengangs WI07 als Kalender in meinem Thunderbird anzeigen zu können, habe ich dort folgende URL als iCal-Quelle angegeben:

http://raumbelegung.stud.ailoo.net/week/show/class/wi07-vz/format/ical

Vorschläge sind wie üblich willkommen :)

Build a FlashMessenger system in ASP.NET MVC

Build a FlashMessenger system in ASP.NET MVC

June 1, 2009 · in Development, How-Tos, Windows

Usually, I’m using PHP for web projects, but currently I’m working on an application using ASP.NET’s MVC framework. In many frameworks (e.g. Zend Framework or CakePHP) there is some kind of messaging system (flash messages), which allows to save a message to the session and to display it on the next request. This is useful in many situations, but mostly used after saving forms. So for example you recieve a POST request to create a new record, you save the record, redirect the user to the overview page and inform him about successful creation through a flash message which you saved before doing the redirect. As I didn’t find a way how to achieve this in ASP.NET MVC, I started to build an own solution. The result is a combination of a base controller, an action filter and a flashmessenger object which is stored in the session. Please note that I’m not too familiar neither with ASP.NET nor with C#/.NET in general, so if there are things to improve please feel free to correct me.

(more…)

Set up a Zend Framework application using Zend_Application (including PHPUnit setup)

April 25, 2009 · in Development, How-Tos, Server

Today I spent some time setting up a new Zend Framework application using ZF 1.8.0 Beta 1 and the new component Zend_Application. Using that component, all bootstrapping is done by Zend_Application_Bootstrap and so-called resource plugins. Such resource plugins are responsible for initialization of single components such as front controller, database or the view. This way, the whole bootstrapping is nicely modularized and keeps some headache away. In addition, the majority of settings can be set in the application config file. As I ran into some issues, I’d like to note the required steps and hope that it’s useful so someone. I won’t explain the files in detail, you can find enough information about components and parameters on the manual and the quickstart, but you should get to a working setup with just copy&pasting the code here ;)

Basically a big part of this setup can be done using the new Zend_Tool CLI, however I had some problems setting it up, so I’ve done it manually (however most of the code is the one generated by Zend_Tool).

(more…)

NextGEN Gallery Sidebar Widget

April 18, 2009 · in Development, Wordpress

I just released a simple WordPress widget which allows you to show links to NextGEN Gallery galleries in your sidebar. For more information and download take a look at the wordpress repository.

Authenticate Apache against Redmine with AuthMySQL

March 28, 2009 · in Development, How-Tos, Server

For a student project we needed to authenticate an apache host against a MySQL database, in this a case we wanted to handle authentication for a Subversion repository with a Redmine database. I know that Redmine has its own solution for this problem using Redmine.pm, but for some reason that approach didn’t work and we didn’t have the time to bug around with it. This howto is written for the use with Redmine (especially the database view), but you should get the point how to set it up on other environments. The howto was done on an Ubuntu 8.10 box but should work on any other distro as well (except for the module installation). I assume that you got all the other stuff (apache, mysql, …) up and running.

(more…)

gitosis-create-repo

March 22, 2009 · in Development, Server

A simple script to create a new gitosis-repository on the fly. I’m not really familiar with bash scripting so don’t expect too much ;)

#!/bin/bash
if [ -z $1 ]; then
    echo "Please specify a repository."
    exit 1
fi

if [ -z $2 ]; then
    echo "Please specify a remote url."
    exit 1
fi

if [ -d $1 ]; then
    echo "Repository already exists."
    exit 1
fi

mkdir $1
cd $1
git init
touch .gitignore
git add .gitignore
git commit -a -m "Initial commit."
git remote add origin $2:$1.git
git push origin master:refs/heads/master

Please make sure you set the correct permissions in gitosis.conf. Example:

[group me]
members = me@example.com
writable = test</pre>

Then you can run the script to create a new repository test on myhost.example.org:

$ gitosis-create-repo test git@myhost.example.org
1 2 3 Next →
github github github

Search

Categories

  • Android
  • Development
  • Fun
  • General
  • Hardware
  • How-Tos
  • Kitchen
  • Linux
  • No Comment
  • Projects
  • Server
  • Snippets
  • Software
  • Video
  • Web
  • Windows
  • Wordpress

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Copyright © 2008-2013 mafflog