yii ed

Ein PHP-Framework. http://www.yiiframework.com/...jetzt yii2

Neue Anwendung ed

generell ed

php composer.phar global require "fxp/composer-asset-plugin:~1.1.1"
php composer.phar create-project --prefer-dist yiisoft/yii2-app-advanced 

Datenbank ed

Mysql-Schema APP anlegen (mit Benutzer/pw APP/APP). Darin eine Benutzer-Tabelle:

CREATE TABLE "tbl_user" (
  "id" int(11) NOT NULL AUTO_INCREMENT,
  "username" varchar(128) NOT NULL,
  "password" varchar(128) NOT NULL,
  "email" varchar(128) NOT NULL,
  "password_hash" varchar(128) DEFAULT NULL,
  "password_reset_token" varchar(128) DEFAULT NULL,
  "auth_key" varchar(128) DEFAULT NULL,
  "role" int(11) DEFAULT NULL,
  "status" int(11) DEFAULT NULL,
  "created_at" int(11) DEFAULT NULL,
  "updated_at" int(11) DEFAULT NULL,
  PRIMARY KEY ("id")
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8;

in common/config/main-local.php eintragen:

<?php
return [
    'components' => [
        'db' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'mysql:host=localhost;dbname=APP',
            'username' => 'APP',
            'password' => 'APP',
            'charset' => 'utf8',
        ],

Benutzer ed

in common/models/User.php namen der Benutzer-Tabelle anpassen:

public static function tableName()
    {
        return 'tbl_user';//'{{%user}}';
    }

veraltet ed

generell ed

Im yii/framework/ Verzeichnis:

./yiic webapp 

Bootstrap ed

Inhalt des Bootstrap-Verzeichnises nach protected/extensions/bootstrap/ kopieren und den Inhalt des theme-Unterverzeichnises nach theme/bootstrap/.

In protected/config/main.php hinzufügen:

Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../extensions/bootstrap');
return array(
        ...
        'theme'=>'bootstrap',
        ...
        'components'=>array(
                ...
                'bootstrap'=>array(
                        'class'=>'bootstrap.components.Bootstrap',
                ),
        ),
);

Grundstruktur ed

Benutzerverwaltung ed

Kommandozeilen-Befehle ed

Um Modell-Klassen nutzen zu können, in der protected/config/console.php hinzufügen:

return array(
        ...
        'import'=>array(
                'application.models.*',
                'application.components.*',
        ),
);

Dann in protected/commands/ eine Datei Name1Command.php anlegen:

<?php
class Name1Command extends CConsoleCommand
{
        public function actionName2($param1, $param2)
        {
                ...
        }
}
?>

Der Befehl kann dann so ausgeführt werden:

./protected/yiic name1 name2 --param1=... --param2=...

Categories: Computer, Programmieren