Refactoring

21. Juli 2010

Refactoring ist wie Wohnung aufräumen: es ist permanent notwendig, besonders, wenn mehrere Leute drin wohnen. Wer seine Zimmer nicht säubert und lüftet, fühlt sich irgendwann nicht mehr wohl.

Author: admin Categories: Allgemein Tags:

Module, wir brauchen Module

23. Juni 2010

Die yii-Community ist überzeugt von seinem Framework, klagt aber über den noch zu geringen Bekanntheitsgrad und die noch zu wenige Verbreitung.

Die Antwort ist für mich: Es gibt einfach zu wenig fertige Module.

Es gibt zwar ein Yii-Extension-Repository, jedoch eignen sich die Erweiterungen zum größten Teil nur für Entwickler und nicht für Endanwender.

Was die Community hervorbringen sollte, sind einfache Standardmodule wie ein Blog, Shop oder eine Galerie. Man schaue sich das Joomla-ExtensionRepo mal an.
Dort ließe sich aus dem Vollen schöpfen.

Author: admin Categories: Yii Tags:

Module und Submodule

22. Juni 2010

Ich vergleiche Yii-Module mit Joomla-Komponenten, wobei der Administrator-Part einer Joomla-Komponente das Yii-Submodul darstellt. Das Erzeugen von Modulen ist per yiic leicht möglich. Submodule (nested Modules) sind Module, die sich in einem modules-Verzeichnis des parent-Moduls befinden, wobei das Erstellen von Submodulen nicht direkt unterstützt wird.

Ich erzeuge zunächst beide Module

>>yiic shell ../index.php
>>module weblinks
>>module admin

Es entstehen die Verzeichnisse modules/weblinks und modules/admin.
Den modules/admin-Ordner verschiebe ich in den modules/weblinks/modules-Ordner (wenn dort noch kein modules-Ordner existiert, erstellen)

Das Hauptmodul wird in der main-config registriert.

'modules' => array('weblinks'),

Das AdminModul definiere ich in der Datei WeblinksModule.php im modules/weblinks-Ordner

public function init()
{
    // import the module-level models and components
    $this->setImport(array(
        'weblinks.models.*',
	'weblinks.components.*',
    ));
 
    $this->setModules(array('admin'));
}

Nun kann ich die Module auch schon benutzen indem ich folgende URLs aufrufe:

  • http://localhost/weblinks
  • http://localhost/weblinks/admin

Das Submodul mit eigenem Layout ausstatten, ist eigentlich auch recht simpel. Dazu die Datei modules/weblinks/modules/admin/AdminModule.php modifizieren:

public function init()
{
    // import the module-level models and components
    $this->setImport(array(
        'admin.models.*',
	'admin.components.*',
    ));
 
    $this->layout = 'admin';
}

und entsprechend eine Datei admin.php ins Verzeichnis modules/weblinks/modules/admin/views/layouts erstellen. Standardmäßig wird das nächsthöher definierte Layout benutzt, also entweder das Layout des parent-Moduls oder das Layout der Webanwendung.

Author: admin Categories: Yii Tags:

Standard main-config snippet

21. Juni 2010
'log' => array(
    'class' => 'CLogRouter',
    'routes' => array(
        array(
            'class' => 'CFileLogRoute',
            'levels' => 'error, warning',
        ),
        array(
            'class' => 'CProfileLogRoute'
        )
    ),
),
 
'urlManager' => array(
    'urlFormat' => 'path',
    'showScriptName' => false,
    'rules' => array()
),
 
'user' => array(
    // enable cookie-based authentication
    'allowAutoLogin' => true,
),
 
'db' => array(
    'connectionString' => 'mysql:host=localhost;dbname=dbname',
    'username' => 'root',
    'password' => 'root',
    'charset' => 'utf8',
    'enableProfiling' => true
)
Author: admin Categories: Yii Tags:

Integration Zend Framework 1.10

20. Juni 2010
Yii::import('application.vendors.*');
require_once 'Zend/Loader/Autoloader.php';
Yii::registerAutoloader(array("Zend_Loader_Autoloader", "autoload"));
Author: admin Categories: Yii, Zend Framework Tags:

CHtml::listData

9. Juni 2010

Eine kleine hierarchische Struktur:

  • section (id, name)
  • category (id,sectionId, name)
  • item (id, category, title)

Die activeDropDownList für das Feld categoryId im Item-Formular schreiben wir so:

<div class="simple">
    <?php echo CHtml::activeLabelEx($model,'categoryId'); ?>
    <?php echo CHtml::activeDropDownList($model,'categoryId', Item::getSectionCategoryOptions()); ?>
</div>

Die Methode Item::getSectionCategoryOptions()

public static function getSectionCategoryOptions()
{
    $sections = Section::model()->findAll();
 
    $tmp = array();
    foreach ($sections as $section) {
        $tmp[$section->name] = CHtml::listData($section->categories, 'id', 'name');
    }
 
    return $tmp;
}

ich frag mich, ob das auch einfacher geht.
Link zur Doku.

UPDATE:

<div class="simple">
    <?php echo CHtml::activeLabelEx($model,'categoryId'); ?>
    <?php echo CHtml::activeDropDownList($model,'categoryId', CHtml::listData(Category::model()->with('section')->findAll(), 'id', 'name', 'section.name')); ?>
</div>
Author: admin Categories: Yii Tags:

Rockettheme Juxta

2. Mai 2010

Rockettheme Juxta
Das Mai-Template von Rockettheme

Author: admin Categories: Allgemein Tags: