Bootstrap.php und MySQL

Hallo Ich möchte mein Übungsplugin http://wiki.shopware.de/Getting-Started … 6_866.html weiter ausbauen. und zwar möchte ich die slogen in einer DB abspeichern public $slogans = array( 'Nur ein toter Bug ist ein guter Bug!', 'Smarty is keine Schokolinse!', 'Ein Zend ist kein Geldstück!' ); Die Tabelle name nenne ich einfach Mattes_slogen_test Es soll die Tabelle erstellt werden ID | slogenname Normal sollte es so gehen $sql = " CREATE TABLE `Mattes_slogen_test` ( `id` INT( 10 ) NOT NULL AUTO\_INCREMENT PRIMARY KEY , `slogenname` TEXT( ) NOT NULL , ) ENGINE = MYISAM ; "; Wie fügen ich sowas am besten in public function install() und wie frage ich in Shopware die DB wieder ab? gruß Mattes

Hallo Mattes, also deinen Query kannst du in der install() wie folgt absetzen. public function install() { $qry = 'CREATE QUERY HERE'; Shopware()-\>Db()-\>query($qry); } Aber schau doch einfach mal in diesen Teil zur Erweiterung des “Slogan des Tages”. Da wird dies auch beschrieben und erläutert. http://wiki.shopware.de/Shopware-4-Grun … 1_867.html Viele Grüße und viel Erfolg, mrtee

Ich habe das Beispiel Plugin mal angepasst. Ist nicht getestet sollte aber funktionieren: [code]<?php class Shopware_Plugins_Frontend_SwagSloganOfTheDay_Bootstrap extends Shopware_Components_Plugin_Bootstrap
{
public $slogans = array();

public function install()
{
    $this->subscribeEvent( 'Enlight\_Controller\_Action\_PostDispatch\_Frontend\_Index', 'onPostDispatchIndex' ); $sql = " CREATE TABLE IF NOT EXISTS `mattes_slogen_test` ( `id` int(11) NOT NULL AUTO\_INCREMENT, `slogenname` text, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO\_INCREMENT=2 DEFAULT CHARSET=latin1; "; Shopware()-\>Db()-\>query($sql); foreach ($this-\>slogans as $slogan){ Shopware()-\>Db()-\>query('INSERT INTO mattes\_slogen\_test (slogenname)VALUE(:slogan)',array(":slogan"=\>$slogan)); } return true; } public function uninstall() { Shopware()-\>Db()-\>query('DROP TABLE IF EXISTS `mattes_slogen_test`;'); return true; } public function onPostDispatchIndex(Enlight\_Event\_EventArgs $arguments) { /\*\*@var $controller Shopware\_Controllers\_Frontend\_Index \*/ $controller = $arguments-\>getSubject(); $view = $controller-\>View(); $this-\>slogans = Shopware()-\>Db()-\>fetchCol('SELECT slogenname FROM mattes\_slogen\_test'); //Add our plugin template directory to load our slogan extension. $view-\>addTemplateDir($this-\>Path() . 'Views/'); $view-\>extendsTemplate('frontend/plugins/slogan\_of\_the\_day/index.tpl'); $view-\>assign('slogan', $this-\>getRandomSlogan()); } private function getRandomSlogan() { //get random number between 0 and the count of our slogans $index = rand(0, count($this-\>slogans) - 1); return $this-\>slogans[$index]; } }[/code]