Begründung?
Beiträge von ulle
-
-
Hallo liebes MCore Team,
wie schon angedroht werde ich versuchen den Webcoding Bereich etwas aufleben zu lassen.Da ich gestern von einem Kollegen gefragt wurde wie man ein Blocksystem in PHP realisieren könnte welches dynamisch auf eventuelle Gegebenheiten reagiert.
Lange Rede kurze Sinn. Ich habe es mit Ihm zusammen gebaut und wollte es euch nicht vorenthalten.
Was ist ein Block System?
Das Block System wird benötigt, um aus einem Controller oder wo auch immer, diverse Parameter oder ganze Programmteile nachzuladen.
Das ganze System ist natürlich weder ausgereift, noch out of box nutzbar. Es ging für meinen Kollegen viel mehr darum einen Anhaltspunkt zuhaben und zu verstehen wie man eine Klasse bauen kann, welche ohne komplett definierte Methoden, dennoch dynamisch benutzt werden kann.
Was bedeutet ohne definierte Methoden?
Ohne fefinierte Methoden bedeutet, das wir die PHP eigene Magic Methode
benutzen werden.
Wie wird die Klasse benutzt?
Die Klasse kann man ganz einfach in ein bestehendes System integrieren und muss noch eine Anpassung bezüglich der Verarbeitung der Blöcke machen.
Code der Klasse
PHP
Alles anzeigen<?php class Block { /** * Beinhaltete alle Sections * * @var array */ private static $sections=array(); /** * Dynamischer Aufruf von nicht definierten Methodennamen * * @param string $method * @param array $args * @return void */ public static function __callStatic($method, $args=array()) { array_set(static::$sections, $method, array()); foreach($args as $k => $v) { if(is_array($v)) { foreach($v as $key => $value) { array_set(static::$sections[$method], $key, $value); } } } } /** * Aufruf einer Section egal in welcher Tiefe * * @param string $section * @param string $default * @return string|array */ public static function get($section=false, $default=null) { if(!$section) { return static::$sections; } else { return array_get(static::$sections, $section, $default); } } }Beispiel Implementation
PHP
Alles anzeigen<?php require 'helpers.php'; require 'blocks.php'; Block::sidebar(array( array('social.facebook' => 'social/facebook'), array('social.twitter' => 'social/twitter') )); // Wenn man nun einen Block Segment auslesen will, dann reicht es wenn man das Array mit der Dot Syntax durchläuft Block::get(); // Gibt alle definierten Blöcke als Array aus Block::get('sidebar'); // Gibt alle Blöcke der Sidebar Kategorie aus als Array wenn es mehrere sind Block::get('sidebar.social'); // Alle Blöcke der Kategorie Sidebar und Unterkategorie Social als Array wenn es mehrere sind Block::get('sidebar.social.facebook'); // Gibt alle Blöcke der Kategorie Sidebar, Social, Facebook aus // Ich hoffe ich konnte mit dieser Erklärung alles klarstellenHelfer Datei damit die Array Dot Syntax funktioniert, diese wurde aus dem Laravel Framework übernommen
PHP
Alles anzeigen<?php /** * Get an item from an array using "dot" notation. * * <code> * // Get the $array['user]['name] value from the array * $name=array_get($array, 'user.name'); * * // Return a default from if the specified item doesn't exist * $name=array_get($array, 'user.name', 'Taylor'); * </code> * * @param array $array * @param string $key * @param mixed $default * @return mixed */ function array_get($array, $key, $default=null) { if (is_null($key)) return $array; // To retrieve the array item using dot syntax, we'll iterate through // each segment in the key and look for that value. If it exists, we // will return it, otherwise we will set the depth of the array and // look for the next segment. foreach (explode('.', $key) as $segment) { if ( ! is_array($array) or ! array_key_exists($segment, $array)) { return value($default); } $array=$array[$segment]; } return $array; } /** * Set an array item to a given value using "dot" notation. * * If no key is given to the method, the entire array will be replaced. * * <code> * // Set the $array['user]['name] value on the array * array_set($array, 'user.name', 'Taylor'); * * // Set the $array['user]['name]['first] value on the array * array_set($array, 'user.name.first', 'Michael'); * </code> * * @param array $array * @param string $key * @param mixed $value * @return void */ function array_set(&$array, $key, $value) { if (is_null($key)) return $array=$value; $keys=explode('.', $key); // This loop allows us to dig down into the array to a dynamic depth by // setting the array value for each level that we dig into. Once there // is one key left, we can fall out of the loop and set the value as // we should be at the proper depth. while (count($keys) > 1) { $key=array_shift($keys); // If the key doesn't exist at this depth, we will just create an // empty array to hold the next value, allowing us to create the // arrays to hold the final value. if ( ! isset($array[$key]) or ! is_array($array[$key])) { $array[$key]=array(); } $array =& $array[$key]; } $array[array_shift($keys)]=$value; } /** * Remove an array item from a given array using "dot" notation. * * <code> * // Remove the $array['user]['name] item from the array * array_forget($array, 'user.name'); * * // Remove the $array['user]['name]['first] item from the array * array_forget($array, 'user.name.first'); * </code> * * @param array $array * @param string $key * @return void */ function array_forget(&$array, $key) { $keys=explode('.', $key); // This loop functions very similarly to the loop in the "set" method. // We will iterate over the keys, setting the array value to the new // depth at each iteration. Once there is only one key left, we will // be at the proper depth in the array. while (count($keys) > 1) { $key=array_shift($keys); // Since this method is supposed to remove a value from the array, // if a value higher up in the chain doesn't exist, there is no // need to keep digging into the array, since it is impossible // for the final value to even exist. if ( ! isset($array[$key]) or ! is_array($array[$key])) { return; } $array =& $array[$key]; } unset($array[array_shift($keys)]); } /** * Return the first element in an array which passes a given truth test. * * <code> * // Return the first array element that equals "Taylor" * $value=array_first($array, function($k, $v) {return $v == 'Taylor';}); * * // Return a default value if no matching element is found * $value=array_first($array, function($k, $v) {return $v == 'Taylor'}, 'Default'); * </code> * * @param array $array * @param Closure $callback * @param mixed $default * @return mixed */ function array_first($array, $callback, $default=null) { foreach ($array as $key => $value) { if (call_user_func($callback, $key, $value)) return $value; } return value($default); } /** * Recursively remove slashes from array keys and values. * * @param array $array * @return array */ function array_strip_slashes($array) { $result=array(); foreach($array as $key => $value) { $key=stripslashes($key); // If the value is an array, we will just recurse back into the // function to keep stripping the slashes out of the array, // otherwise we will set the stripped value. if (is_array($value)) { $result[$key]=array_strip_slashes($value); } else { $result[$key]=stripslashes($value); } } return $result; } /** * Divide an array into two arrays. One with keys and the other with values. * * @param array $array * @return array */ function array_divide($array) { return array(array_keys($array), array_values($array)); } /** * Return the value of the given item. * * If the given item is a Closure the result of the Closure will be returned. * * @param mixed $value * @return mixed */ function value($value) { return ($value instanceof Closure) ? call_user_func($value) : $value; }Ich hoffe ich kann damit dem ein oder anderen helfen. Bei Frage und konstruktiver Kritik, einfach hier im Thread posten.
Bitte bedenkt das es nur eine Beispiel Verwendung ist und natürlich ausgebaut werden muss/kann.
-
Rilouu
Mönch
90
Allianz
Kel'Thuzad
Aktiv im Raid -
Ich spiele einen Pandaren Mönch als Heiler. Mir gefällt einfach die Klassenmechanik und der Rassenbonus. Es macht unheimlich viel Spass als Mönch zu heilen.
-
einzogger#1902
Alli
PVP/PVE
aktiv -
Aber das hast du garantiert auf Linux nicht so getestet wie du es schreibst. Denn das kann mit dem wine befehl nicht funktionieren. Auch glänzt der Linux Bereich mit Halbwissen. Du schreibst das es seit einiger Zeit möglich ist Windows Programme unter Linux zu starten.
Hier mal ein Auszug der offiziellen Seite:
CodeThe Wine team is proud to announce that Wine 1.0 is now available.This is the first stable release of Wine after 15 years of developmentSteht da direkt auf der Startseite ;). Natürlich ist es nun auch nicht mehr aktuelle. Denn Version 1.0 ist schon sehr alt. Aber dennoch ist es definitiv schon länger möglich Windows Programme unter Linux zu starten. Und zwar länger als du auf der Welt bist ;)
-
Quellenangabe?
-
Also ich empfehle dir auch Einzelkopfhörer zukaufen und auf ein Headset zu verzichten. Der Klang aus reinen Kopfhörern ist deutlich besser als aus einem Headset.
Ist natürlich nur meine Meinung. Ich selbst habe ein Steelseries Headset mit einem externen Mikrofon von Samson.
Aber da ich nur in den seltensten Fällen Kopfhörer nutze ist mir der Klang aus den Dingern auch relativ wurscht.Bezüglich unseres Saturn Mitarbeiters, du scheinst in deiner Aushilfsposition ja viel Geld zuverdienen das du dir Sonos, Bose und Beats leisten kannst ;)
Und nur, weil etwas im netz steht das es gut ist, heißt es noch lange nicht das es gut ist. Also ich kenne keinen DJ der Beats Kopfhörer nutzt zum auflegen :D
-
Um das ganze aber wirklich gut umzusetzen sollte man die einzelnen Media Querys noch mit max-width begrenzen.
Ist nicht zwingen notwendig aber in meiner Karriere ist mir das nun schon ein paar mal untergekommen das es ohne diese Begrenzung zu fehlern kommen kann. Ist aber wie gesagt kein muss.
-
Das Zend Framework ist auch nicht gerade das was man ein gutes Framework nennt. Empfehlen kann ich Welcome! - Laravel PHP Framework
-
Und dann noch ein Tipp, nutze am besten von Anfang an ein Framework. Jeder der etwas dagegen sagt, hat in meinen Augen keine Ahnung :D
-
Was ich auch noch empfehlen kann. Überspringe den ganzen prozeduralen Bullshit. :D
Das führt eh zu nichts
-
Nee aber mal im ernst, ich habe gerade mal die ersten 2 Kapitel von Codecademy gemacht, also wirklich super ist das net :D
Das einzige was cool ist, ist die Interaktion im Browser :D
Ich finde um PHP zulernen sollte man sich einfach ein Projekt ausdenken und anfangen. Und der Rest ergibt sich dann.
Kannst ja auch hier im Forum fragen, ist ja net so das es keine Leute gibt die PHP könnten ;)
Lieben Gruß
-
-
Die beste Alternative wie ich finde,
Learning by doing :D
-
das mit dem -o und dem -ms kannste entfernen. Opera benutzt mittlerweile die Webkit Engine und der Internet Explorer kratzt sich an dem Tag herzlich wenig.
Es reicht also bei sowas immer ein normales tag, das -webkit und das -moz tag
Lieben Gruß
-
Was mir auch gerade noch einfällt für dein Design.
Das würde mit einer Transition der Buttons auch gut aussehen.
Mach mal in der template.css in Zeile 56, 57 und 58 ein:
Ich finde der effekt wirkt dort sehr gut mit den Buttons. Falls du es benutzen willst vergiss nicht den Browserfix für mozilla und chrome mit einzubauen
-
Zitat von nintendo94;322607
Was man bis jetzt nicht machen kann ist die APP's zu Sortieren nach den eigenen Vorstellungen.
Natürlich geht das, halt doch einfach mal die Maus lange auf ein ICON und verschiebe es dann.....
-
-