Jump to content

Andy-H

Members
  • Posts

    2,000
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Andy-H

  1. Ah. Well, I usually let my DB abstraction layer deal with that, I normally don't explicitly escape anything. Yeah, I will be using prepared statements, my validation class consists of : <?php namespace phantom\classes\filters; class Validate { public function email($email) { return filter_var($email, FILTER_VALIDATE_EMAIL); } public function url($url) { return filter_var($url, FILTER_VALIDATE_URL); } public function IP($IP) { return filter_var($IP, FILTER_VALIDATE_IP); } public function signed($int) { return filter_var($int, FILTER_VALIDATE_INT); } public function unsigned($int) { return filter_var($int, FILTER_VALIDATE_INT, array('options' => array('min_range' => 0))); } public function int_range($int, $min = false, $max = false) { $options = array(); if ( $min !== false ) $options['options']['min_range'] = $min; if ( $max !== false ) $options['options']['max_range'] = $max; return filter_var($int, FILTER_VALIDATE_INT, $options); } public function regex($input, $pat) { return filter_var($input, FILTER_VALIDATE_REGEXP, array('options' => $pat)); } public function callback($input, callable $callback) { return filter_var($input, FILTER_CALLBACK, array('options' => $callback)); } }
  2. lol nice, well it's not like you can make it any worse! Yeah, that's always good
  3. I like it, just one thing though, the three small images look a bit sharp around the edges, could do with something between them and the background for a more gradual introduction of the contrast IMO
  4. No worries, yeah, I was referring to "inbound validation" and "outbound sanitization" being injected into my controller and view, respectively. // EDIT Thanks for the help, by the way
  5. lol OK, thanks scootstah, thanks for clearing that up, time to hit the sack I think, thanks again for the help. Night.
  6. Fair enough, I guess I'm getting too hung up on following best practice rather than getting things done. Thanks for your help
  7. Isn't that just exposing your objects to the global scope though?
  8. OK, this was quite good reading for me: SOLID So in practice, you would inject the dependency?
  9. Here is an example of my current Controller, have I got the idea of MVC completely wrong? <?php namespace phantom\classes\controllers; // Dependancy injection use \phantom\classes\caching\Cache as Cache; use \phantom\classes\templating\Template as Template; // Instantiation use \phantom\classes\data as data; class Index implements Interface_iController { protected $_template; protected $_cache; public function __construct(Template $Template, Cache $Cache) { $this->_template = $Template; $this->_cache = $Cache; } public function deploy(array $params = array()) { switch ( count($params) ) { default : if ( $this->_cache->isCached('Index') ) return $this->_cache->getCachedData('Index'); // Twitter $Twitter = new data\Twitter('PhantomLtd'); // Template $this->_template->loadTemplate('default'); $this->_template->getFragments([ 'b2c/navigation', 'default/slider', 'b2c/product_nav' ])->insertAfter('#header'); $this->_template->getFragment('default/content_lr_divider')->prependTo('#content'); $this->_template->getFragments([ 'content/videos', 'content/news', 'content/twitter' ], [ 2 => [ 'tweets' => $Twitter->getLastTweets(2), 'user' => [ 'url' => $Twitter->getURL(), 'name' => $Twitter->getUsername() ] ] ])->prependTo('#left_content'); $this->_template->getFragments([ 'content/index/main_content', 'content/mini_product_slider' ])->appendTo('#right_content'); $html = $this->_template->getContents(); $this->_cache->cacheData('Index', $html); return $html; break; } } }
  10. Yes, I get your point, but is that not tight-coupling (the model class depends on the ValidationObject class being present in the application?) Does this mean there are instances where classes should be tightly-coupled with their dependencies as opposed to dependency injected?
  11. I think I understand the model helper (after a quick google search) So an instance specific helper: class User { protected function _validateUsername($username) { return ( ctype_digit($username) && strlen($username) > 2 && strlen($username) < 40 ); // I have been using this for a long time without knowing what it was, just not to validate input } } Whereas a more generic helper: class UserHelper { public function validateUsername($username) { return ( ctype_digit($username) && strlen($username) > 2 && strlen($username) < 40 ); // this is new to me, but seems plausible } } Is that right?
  12. Hmm, you make a good point, it was more I thought to use a factory and wanted someone to validate that what I was doing was right or wrong (which you did, thank you ) I watched a video on KillerPHP (which I've never found to be a great resource) stating that the Controller is the "throw-away" part of the MVC, (I don't really see how reusable views work, I can't see it being flexible enough), so I assumed this would be where validation and sanitizing should be done (as I've sussed from previous posts, models should not validate inputs as such (i.e. if ( strlen($username) < 40 ) // do something) ? ) so the only place left was the controller, as for sanitizing in the view, I forgot that the view should contain no logic, so this seemed like a good idea in my head. So, how do model-helpers work? // EDIT Thinking about it, whats wrong with sanitizing in my view? It is related to output. I.E. what's wrong with: <?= $Sanitize->html($tweet[0]); ?> in my view? I see your point about validation in the model, although I'm still intrigued by the model-helper?
  13. Never mind, I just realised my Validate filter should be dependency injected into my Controllers, whilst my Sanitize filter should be injected into my views
  14. Basically I have two classes in my filters namespace that I want to pass from Index.php to *Controller.php via dependency injection, to avoid instantiating the classes separately I want to group them into one object called filter, then I can call: $Filter->Sanitize->email($email); if ( $Filter->Validate->email($email) ) // do stuff Is this the right way to go about it or am I going to cause problems down the line? <?php namespace phantom\classes\filters; class FilterFactory { public $Sanitize; public $Validate; public function __construct() { $this->Sanitize = new Sanitize(); $this->Validate = new Validate(); } } Thanks for any help
  15. Yeah, I noticed but was looking for somewhere for a normal user to post blogs, I was thinking about it before, and maybe it should be restricted to reputable users with x+ posts, and then have to be verified by a staff member, so you don't get people giving bad advice or spamming websites/black hat SEO methods.
  16. I don't know if this is already implemented, but it would be nice for PHPFreaks to host blogs for users - if this was free I think a lot of people would use it and it would benefit the forum with plenty of new content which, in turn, would boost SERP's
  17. Never thought, if it removed all whitespace outside of tags, <b>hello</b> <i>PHPFreaks</i> would result as <b>hello</b><i>PHPFreaks</i> return preg_replace('~\s+~i', ' ', ob_get_clean()); Seemed like a pretty safe bet
  18. It seems that setting preserveWhiteSpace to true yields the same result too, wierd
  19. Think about it like this, behind the scenes php sees that you're using a boolean value and comparing it to an integer, so it casts the integer value to a boolean value for you, if you used the strict (typed) comparison operator, it would evaluate to false: var_dump( true === 999 ); //are true and 999 equal in both type and value? (false) var_dump( true == 999 ); //are true and 999 equal in value (true) //why? var_dump((bool)999); // true var_dump(true == true); // true
  20. Hi, I'm working on a template system which uses DOMDocument, I set preserveWhitespace before calling loadHTML but still the unnecessary spaces are not removed, anyone got any experience in this area? My code: Template.class.php [size=78%]<?php[/size] namespace phantom\classes\templating; class Template { protected $_document; protected $_settings = array( 'version' => '4.01', 'encoding' => 'UTF-8', 'template_dir' => 'templates', 'template_ext' => 'tmpl.php', 'preserve_whitespace' => false ); public function __construct($tmpl_file, array $data = array(), array $settings = array()) { $this->_settings = array_merge($this->_settings, $settings); $this->_document = new \DOMDocument($this->_settings['version'], $this->_settings['encoding']); $this->_document->preserveWhiteSpace = $this->_settings['preserve_whitespace']; $this->_document->loadHTML($this->_getContent($tmpl_file, $data)); } public function getFragment($file_name, array $data = array()) { return new TemplateFragment($this->_getContent($file_name, $data), $this->_document); } public function getContents() { return $this->_document->saveHTML(); } public function printContents() { $this->_document->saveHTMLFile('php://output'); } protected function _getContent($file_name, array $data = array()) { ob_start(); extract($data, EXTR_SKIP); include $this->_settings['template_dir'] . DIRECTORY_SEPARATOR . $file_name .'.'. $this->_settings['template_ext']; return ob_get_clean(); } } TemplateFragment.class.php [size=78%]<?php[/size] namespace phantom\classes\templating; class TemplateFragment { protected $_content; protected $_document; public function __construct($content, \DOMDocument $document) { $this->_document = $document; $this->_content = $this->_document->createDocumentFragment(); $this->_content->appendXML($content); } public function appendTo($selector) { $this->_insertNode($selector, false, true); } public function prependTo($selector) { $this->_insertNode($selector, true, true); } public function insertBefore($selector) { $this->_insertNode($selector, true, false); } public function insertAfter($selector) { $this->_insertNode($selector, false, false); } protected function _insertNode($selector, $top, $inside) { $node = $this->_getElement($selector); if ( $inside && $top ) { $node = $node->insertBefore($this->_content, $node->firstChild); } elseif ( !$inside && $top ) { $node = $node->parentNode->insertBefore($this->_content, $node); } elseif ( $inside && !$top ) { $node = $node->appendChild($this->_content); } elseif ( !$inside && !$top ) { if( $node->nextSibling ) { $node = $node->parentNode->insertBefore($this->_content, $node->nextSibling); } else { $node = $node->parentNode->appendChild($this->_content); } } $this->_document->loadHTML($this->_document->saveHTML()); } protected function _getElement($selector) { if ( substr($selector, 0, 1) == '#' ) { $elem = $this->_document->getElementById(substr($selector, 1)); if ( is_null($elem) ) throw new \Exception('No element found in document with that ID'); return $elem; } $XPath = new \DOMXPath($this->_document); $pos = strpos($selector, '['); if ( $pos !== false ) { $index = (int)substr($selector, $pos+1, strpos($selector, ']')-1); $selector = substr($selector, 0, $pos); } else { $index = 0; } $query = $this->_parse_selector($selector); $nodeList = $XPath->query($query); if ( $nodeList->length < $index ) throw new \Exception('XPath query did not return '. number_format($index, 0) .' or more NodeList in TemplateFragment::_getElement(".classname")'); return $nodeList->item($index); } protected function _parse_selector($selector) { preg_match('~([^#|^.]?)([\.?|#?])(.+)~', $selector, $matches); $query = '//'; $query .= !empty($matches[1]) ? $matches[1] : '*'; if ( isset($matches[2]) ) { $query .= str_replace(array('.', '#'), array("[@class='", "[@id='"), $matches[2]); if ( isset($matches[3]) ) $query .= $matches[3] ."']"; } return $query; } } templates/default.tmpl.php <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <title>Phantom - Tracking Ststems and Accessories</title> <!-- META //--> <meta name="description" content="" > <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" > <!-- LINKS AND SCRIPTS //--> <link rel="stylesheet" href="css/layout.css" type="text/css" > </head> <body> <div id="clouds"><> <div id="container"> <!-- HEADER //--> <div id="header"> <h1> <a href="/"> <img src="images/layout/b2c/phantom.png" alt="Phantom vehicle tracking and accessories" > </a> </h1> <div id="header_right"> <ul id="header_nav" class="navigation"> <li class="first"><a href="#">About</a></li> <li><a href="#">News</a></li> </ul> <img class="telephone" src="images/layout/b2c/tel.png" alt="Telephone number" > <> <> <!-- CONTENT //--> <div id="content"> <div class="clr"><> <> <> <!-- FOOTER //--> <div id="footer"> <div id="logo"><> <div class="green_banner"> <div id="motto">Protect, Secure, Enjoy<> <> <div class="blue_banner"><> <> </body> </html> NOTE: This is one of many template files involved index.php <?php include 'phantom/classes/templating/Template.class.php'; include 'phantom/classes/templating/TemplateFragment.class.php'; use \phantom\classes\templating as tmpl; try { $page = new tmpl\Template('default'); $page->getFragment('b2c/navigation')->insertAfter('#header'); $page->getFragment('default/slider')->insertAfter('#main_nav'); $page->getFragment('b2c/product_nav')->insertAfter('#slider'); $page->getFragment('default/content_lr_divider')->prependTo('#content'); $page->getFragment('content/videos')->prependTo('#left_content'); $page->getFragment('content/news')->insertAfter('#video'); $page->getFragment('content/twitter')->appendTo('#left_content'); $page->getFragment('content/index/main_content')->appendTo('#right_content'); $page->getFragment('content/mini_product_slider')->appendTo('#right_content'); echo $page->printContents(); } catch ( Exception $e ) { echo $e->getMessage(); } OUTPUT: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"><head><title>Phantom - Tracking Ststems and Accessories</title><!-- META //--><meta name="description" content=""><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><!-- LINKS AND SCRIPTS //--><link rel="stylesheet" href="css/layout.css" type="text/css"></head><body><div id="clouds"><><div id="container"> <!-- HEADER //--> <div id="header"> <h1> <a href="/"> <img src="images/layout/b2c/phantom.png" alt="Phantom vehicle tracking and accessories"></a> </h1> <div id="header_right"> <ul id="header_nav" class="navigation"><li class="first"><a href="#">About</a></li> <li><a href="#">News</a></li> </ul><img class="telephone" src="images/layout/b2c/tel.png" alt="Telephone number"><> <><!-- MAIN NAVIGATION //--> <ul id="main_nav" class="navigation"><li class="first"><a href="#">Home</a></li> <li><a href="#">Tracking</a></li> <li><a href="#">Remapping</a></li> <li><a href="#">Tyre protector</a></li> <li><a href="#">Alarms</a></li> <li><a href="#">Cameras and sensors</a></li> <li><a href="#">Insurance</a></li> <li><a href="#">Contact us</a></li> </ul><!-- SLIDER //--><div id="slider"> <><!-- PRODUCT NAVLIGATION IMAGES //--> <ul id="product_navigation"><li class="first"><a href="#" id="remap">Engine ECU remapping</a></li> <li><a href="#" id="tyre-pro">Tyre protector</a></li> <li><a href="#" id="sat-dish">Caravan and motorhome satellite dish</a></li> <li><a href="#" id="reverse-sensor">Reverse sensor</a></li> <li><a href="#" id="in-car-cam">In car camera</a></li> <li><a href="#" id="alarms">Caravan and motorhome alarms</a></li> <li><a href="#" id="tracking">Caravan and motorhome tracking</a></li> <li><a href="#" id="subs">Renew tracking subscription</a></li> </ul><!-- CONTENT //--><div id="content"><!-- LEFT CONTENT //--> <div id="left_content"><!-- VIDEOS //--> <div class="horizontal_grey" id="video"> <div class="video_still"><> <strong class="title">Watch videos</strong> <ul><li><a href="#">Engine remapping</a></li> <li><a href="#">Reversing camera</a></li> <li><a href="#">Tyre protector</a></li> <li><a href="#">Mobile-home Satellite TV</a></li> <li><a href="#">Alarms</a></li> <li><a href="#">Tracking</a></li> </ul><><!-- NEWS //--> <div class="orange_bg" id="news"> <strong class="title">News in brief</strong> <h2><a href="#">From complete GPS tracking</a></h2> <p> and security packages, through to engine (ECU) remaps, tyre protectors, alarms and hands-free-kits, all our products... <a href="#">more</a> </p> <h3><a href="#">From complete GPS tracking</a></h3> <p> and security packages, through to engine (ECU) remaps, tyre protectors, alarms and hands-free-kits, all our products... <a href="#">more</a> </p> <h3><a href="#">From complete GPS tracking</a></h3> <p> and security packages, through to engine (ECU) remaps, tyre protectors, alarms and hands-free-kits, all our products... <a href="#">more</a> </p> <> <!-- TWITTER //--> <div class="vertical_grey"> <div id="twitter"><> <strong class="title">Tweets</strong> <p> From complete GPS tracking and security packages through to engine (ECU) remaps, tyre protectors </p> <p> From complete GPS tracking and security packages through to engine (ECU) remaps, tyre protectors </p> <><> <!-- RIGHT CONTENT //--> <div id="right_content"> <!-- MAIN CONTENT //--> <div class="grey_bg"> <p> Phantom offers a comprehensive range of leisure and business monitoring services that will protect, enhance and increase your enjoyment of your vehicle. </p> <p> From complete GPS tracking and security packages through to engine (ECU) remaps, tyre protectors, alarms and hands free kits all our products can be installed in caravans, motorhomes, cars, trucks and business fleet vehicles. </p> <p> Our specialist mobile satellite team can assist you in the purchase of the correct satellite dish. Allowing you to recieve all your faviroute TV programs while travelling across Europe. Not only do we offer national custom-fitting vehicle service, we can even bespoke our GPS monitoring and tracking software to meet your individual and business requirements. </p> <p> So why not take advantage of our nationwide fitting service to protect and enhance your vehicle today. </p> <><!-- MINI SLIDER //--> <div class="dark_blue_bg" id="mini_slider"> <strong class="title">Other products</strong> <a href="#" class="first"><img src="images/product_small/product_small.jpg" alt="product1" title="product1"></a> <a href="#"><img src="images/product_small/product_small.jpg" alt="product1" title="product1"></a> <a href="#"><img src="images/product_small/product_small.jpg" alt="product1" title="product1"></a> <a href="#"><img src="images/product_small/product_small.jpg" alt="product1" title="product1"></a> <a href="#"><img src="images/product_small/product_small.jpg" alt="product1" title="product1"></a> <><> <div class="clr"><> <> <><!-- FOOTER //--><div id="footer"> <div id="logo"><> <div class="green_banner"> <div id="motto">Protect, Secure, Enjoy<> <> <div class="blue_banner"><> <></body></html> NOTE: In the view source it didn't have the double line breaks, but they appeared when I pasted into notepad++ to remove formatting ( I have notepad++ setup to use UTF-8 without BOM) could this be something to do with it? The whitespace messes up at the first double line break. Sorry for the long code samples. Thanks for any help.
  21. Managed it, but for some reason setting preserveWhitespace to false isn't working properly. I had to do it a bit of a dirty way, reloading the html every time a node is inserted, still could do with a better way. Template.class.php <?php namespace phantom\classes\templating; class Template { protected $_document; protected $_settings = array( 'version' => '4.01', 'encoding' => 'UTF-8', 'template_dir' => 'templates', 'template_ext' => 'tmpl.php', 'preserve_whitespace' => 0 ); public function __construct($tmpl_file, array $data = array(), array $settings = array()) { $this->_settings = array_merge($this->_settings, $settings); $this->_document = new \DOMDocument($this->_settings['version'], $this->_settings['encoding']); $this->_document->preserveWhiteSpace = $this->_settings['preserve_whitespace']; $this->_document->loadHTML($this->_getContent($tmpl_file, $data)); } public function getFragment($file_name, array $data = array()) { return new TemplateFragment($this->_getContent($file_name, $data), $this->_document); } public function getContents() { return $this->_document->saveHTML(); } protected function _getContent($file_name, array $data = array()) { ob_start(); extract($data, EXTR_SKIP); include $this->_settings['template_dir'] . DIRECTORY_SEPARATOR . $file_name .'.'. $this->_settings['template_ext']; return ob_get_clean(); } } TemplateFragment.class.php <?php namespace phantom\classes\templating; class TemplateFragment { protected $_content; protected $_document; public function __construct($content, \DOMDocument $document) { $this->_document = $document; $this->_content = $this->_document->createDocumentFragment(); $this->_content->preserveWhitespace = false; $this->_content->appendXML($content); } public function appendTo($selector) { $this->_insertNode($selector, false, true); } public function prependTo($selector) { $this->_insertNode($selector, true, true); } public function insertBefore($selector) { $this->_insertNode($selector, true, false); } public function insertAfter($selector) { $this->_insertNode($selector, false, false); } protected function _insertNode($selector, $top, $inside) { $node = $this->_getElement($selector); if ( $inside && $top ) { $node = $node->insertBefore($this->_content, $node->firstChild); } elseif ( !$inside && $top ) { $node = $node->parentNode->insertBefore($this->_content, $node); } elseif ( $inside && !$top ) { $node = $node->appendChild($this->_content); } elseif ( !$inside && !$top ) { if( $node->nextSibling ) { $node = $node->parentNode->insertBefore($this->_content, $node->nextSibling); } else { $node = $node->parentNode->appendChild($this->_content); } } $this->_document->loadHTML($this->_document->saveHTML()); } protected function _getElement($selector) { if ( substr($selector, 0, 1) == '#' ) { $elem = $this->_document->getElementById(substr($selector, 1)); if ( is_null($elem) ) throw new \Exception('No element found in document with that ID'); return $elem; } $XPath = new \DOMXPath($this->_document); $pos = strpos($selector, '['); if ( $pos !== false ) { $index = (int)substr($selector, $pos+1, strpos($selector, ']')-1); $selector = substr($selector, 0, $pos); } else { $index = 0; } $query = $this->_parse_selector($selector); $nodeList = $XPath->query($query); if ( $nodeList->length < $index ) throw new \Exception('XPath query did not return '. number_format($index, 0) .' or more NodeList in TemplateFragment::_getElement(".classname")'); return $nodeList->item($index); } protected function _parse_selector($selector) { preg_match('~([^#|^.]?)([\.?|#?])(.+)~', $selector, $matches); $query = '//'; $query .= !empty($matches[1]) ? $matches[1] : '*'; if ( isset($matches[2]) ) { $query .= str_replace(array('.', '#'), array("[@class='", "[@id='"), $matches[2]); if ( isset($matches[3]) ) $query .= $matches[3] ."']"; } return $query; } }
  22. Tried import node but that doesn't seem to do what I thought it would, anyone know if this is possible or whether I am wasting my time?
  23. http://www.php.net/manual/en/domnode.insertbefore.php Just read: This function inserts a new node right before the reference node. If you plan to do further modifications on the appended child you must use the returned node. Bummer
  24. Does anyone know if DOMDocument allows you to call getElementById on the id of an element that has been inserted into the DOM (in my case, via DOMDocumentFragment) since instantiation? It doesn't find the element if I try to select a newly inserted element, but works fine if its from the original template: Template.class.php <?php namespace phantom\classes\templating; class Template { protected $_document; protected $_settings = array( 'version' => '4.01', 'encoding' => 'UTF-8', 'template_dir' => 'templates', 'template_ext' => 'tmpl.php' ); public function __construct($tmpl_file, array $data = array(), array $settings = array()) { $this->_settings = array_merge($this->_settings, $settings); $this->_document = new \DOMDocument($this->_settings['version'], $this->_settings['encoding']); $this->_document->loadHTML($this->_getContent($tmpl_file, $data)); } public function getFragment($file_name, array $data = array()) { return new TemplateFragment($this->_getContent($file_name, $data), $this->_document); } public function getContents() { return $this->_document->saveHTML(); } protected function _getContent($file_name, array $data = array()) { ob_start(); extract($data, EXTR_SKIP); include $this->_settings['template_dir'] . DIRECTORY_SEPARATOR . $file_name .'.'. $this->_settings['template_ext']; return ob_get_clean(); } } TemplateFragment.class.php <?php namespace phantom\classes\templating; class TemplateFragment { protected $_content; protected $_document; public function __construct($content, \DOMDocument $document) { $this->_document = $document; $this->_content = $this->_document->createDocumentFragment(); $this->_content->appendXML($content); } public function insertBefore($selector) { $node = $this->_getElement($selector); $node->parentNode->insertBefore($this->_content, $node); } public function insertAfter($selector) { $node = $this->_getElement($selector); if( $node->nextSibling ) { $node->parentNode->insertBefore($this->_content, $node->nextSibling); } else { $node->parentNode->appendChild($this->_content); } } public function appendTo($selector) { $node = $this->_getElement($selector); $node->appendChild($this->_content); } public function prependTo($selector) { $node = $this->_getElement($selector); $node->insertBefore($this->_content); } protected function _getElement($selector) { if ( substr($selector, 0, 1) == '#' ) { $elem = $this->_document->getElementById(substr($selector, 1)); if ( is_null($elem) ) throw new \Exception('No element found in document with that ID'); return $elem; } $XPath = new \DOMXPath($this->_document); $pos = strpos($selector, '['); if ( $pos !== false ) { $index = (int)substr($selector, $pos+1, strpos($selector, ']')-1); $selector = substr($selector, 0, $pos); } else { $index = 0; } $query = $this->_parse_selector($selector); $nodeList = $XPath->query($query); if ( $nodeList->length < $index ) throw new \Exception('XPath query did not return '. number_format($index, 0) .' or more NodeList in TemplateFragment::_getElement(".classname")'); return $nodeList->item($index); } protected function _parse_selector($selector) { preg_match('~([^#|^.]?)([\.?|#?])(.+)~', $selector, $matches); $query = '//'; $query .= !empty($matches[1]) ? $matches[1] : '*'; if ( isset($matches[2]) ) { $query .= str_replace(array('.', '#'), array("[@class='", "[@id='"), $matches[2]); if ( isset($matches[3]) ) $query .= $matches[3] ."']"; } return $query; } } index.php <?php include 'phantom/classes/templating/Template.class.php'; include 'phantom/classes/templating/TemplateFragment.class.php'; use \phantom\classes\templating as tmpl; try { $page = new tmpl\Template('default'); // this works fine as id="header" is in the default template $page->getFragment('default/slider')->insertAfter('#header'); $page->getFragment('b2c/navigation')->insertAfter('#header'); // this doesn't work as main_nav is in the slider template $page->getFragment('b2c/navigation')->insertAfter('#header'); $page->getFragment('default/slider')->insertAfter('#main_nav'); echo $page->getContents(); } catch ( Exception $e ) { echo $e->getMessage(); } Thanks for any help.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.