Project-Id-Version: Trac 0.12
POT-Creation-Date: 2008-01-30 09:20+0100
PO-Revision-Date: 2010-07-19 23:05+0200
Last-Translator: Jeroen Ruigrok van der Werven <>
Language-Team: en_US <>
Plural-Forms: nplurals=2; plural=(n != 1)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Generated-By: Babel 0.9.6

Warning: Can't synchronize with repository "(default)" (Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? ). Look in the Trac log for more information.

Version 3 (modified by sebastian, 10 years ago) (diff)

Add mailinglist

phTagr uses the flexible and easy to learn PHP framework CakePHP 1.2 which comes with a Model-View-Control architecture.

To understand the code of phtagr it is important to understand the basic principle of MVC and CakePHP (see Understanding-Model-View-Controller, A-Typical-CakePHP-Request, and Basic-Principles-of-CakePHP). However, it is quite simple to get into the code and this page will lead you to the major and important sites and hints.

Where to get help?



The source has a special file structure and reflects to the MVC architecture. See also

  • cake - CakePHP framework files
  • phtagr (or app) - phtagr files
    • config - config files. Mainly config/core.php and config/database.php
    • models - Model files like Media, User, Group, etc
      • behaviors - Helpers for Models with specific behavior like Cipher, Type, Flag, etc.
    • controllers - Handles all the logic
      • components - Helpers for controllers like FileManager, FilterManager, QueryBuilder, etc.
    • views - View files of the controllers
      • helpers - Helpers for the views like ExplorerMenu, Cloud, Option, etc.
      • elements - Little parts of pages are handled in elements.
    • vendors - 3rd party files like kcaptcha, phpThumb
    • plugins - extensions of phtagr. Eg. DupFinder

Coding Convention

phTagr follows basically the coding standards of cake - except that phtagr uses to spaces instead of tabs.

An example

The plugin DupFinder is a nice example to get into the code. Its actions is limited but straightforward. See its code for details.


While developing on phtagr it is always a good idea to increase the debug level of cake to retrieve hints and errors of missing actions, views or even typos. To see behind phtagr actions watch on its log file!

  • Enable Debug mode in config/core.php and set it to level 2:
    Configure::write('debug', 2);
  • Watch log file in tmp/logs/logger.log
    $> tail -f tmp/logs/logger.log

HowTo …

Add a new action to a controller

An action is defined by a function of the controller. The structure of a request is: controller/action/paramter1/parameter2/....

class ExplorerController extrends AppController {
  function hint($msg) {
    $this->set('hint', 'This is a hint text: $msg');

Further the action need a view in views/controller/action.ctp. For controller ExplorerController and action hint it would be views/explorer/hint.ctp.

The parameters are passed to the action. There are also stored in $this->params['passed']. Special parameters with the structure name:value are named parameters and are stored in $this->params['named'].

Get data from the controller to the view?

There are different ways to save data for the view within the controller. The special controller variable $this->data is also available in the view as $this->data. Named variables could be set via $this->set() method. Or data could be stored in a special parameter array in $this->params - which is used in special cases.

class ExplorerController extrends AppController {
  function storage() {
    // View: $this->data
    $this->data = 'Special variable';
    // View: $foo
    $this->set('foo', 'Named variable for the view');
    // View: $this->params array.

Get data from the request?

The form data is submitted to the $this->data array of the controller and can be evaluated.

class ExplorerController extrends AppController {
  function edit() {
    if (!empty($this->data)) {
      $media = $this->Media->findById($this->data['Media']['id']);
      // further actions

Retrieve and save data from/to a model?

To use a model, the model must be listed in the $uses variable in the controller.

class ExplorerController extrends AppController {
  $uses = array('Media', 'User');

Now the models Media and User could be accessed within the controller.

  $data = $this->Media->findById($id);
  $data['Media']['name'] = 'New Name';

BTW: The data of the models are usually stored as associative arrays

  [Model] => array(
    [fieldname1] => 'value1',
    [fieldname2] => 'value2'
  [AssociatedModel] => array(
    [fieldname1] => 'value1',
    [fieldname2] => 'value2'

Or more precisely

  [Media] => array(
    [id] => 123,
    [name] => 'IMG_1234.JPG'
  [User] => array(
    [id] => 1,
    [username] => 'admin'

See also:,

Enhanced debugging output with debug_kit plugin

The debug_kit plugin adds nice debug information to cakePHP applications.

Versions could be found at, eg.

According to the README of debug_kit:

  • Copy the files in this directory into app/plugins/debug_kit
  • Include the toolbar component in your app_controller.php:
     var $components = array('DebugKit.Toolbar');
  • Set debug mode to at least 1. (in app/config/core.php)