-
Posts
969 -
Joined
-
Last visited
Everything posted by Destramic
-
Thanks one again for the great advice jacques Well im going to scrap the head helper nonsence and create a template engine myself...but still keep the idea of setting an array of header tags so i can call all globals
-
sorry it should be: <php $id = "test-id"; ?> <div id="<?php echo $id; ?>">this is a test</div>
-
sorry for the late reply i have been doing some research regarding this xss...i didn't realise a web page could be so vulnerable in so many asspects of xxs. so every string must be encoded using htmlspecialchars($string, ENT_QUOTES, 'UTF-8'); so i need to encode the attributes set in my view helper?...that would imply that the design would xxs? i'm sorry i don't understand fully how a user browsing can inject code from the following example, unless the $id is changed inside the file...how is it possible to do it via the browser? <php $id = "test-id" ?> <div id="{$id}">this is a test</div> but i do understand that with user input such as my forum reply it needs to be encoded to ensure no xss i'm not going to argue with you jacques, this looks alot easier on the eye thank you for your help
-
i found the problem which was so stiupid of me...i hate to say what i did wrong sorry! well i've never used a framework other than my own...i thought zend framrwork would be good so i read the files and manuel and based mine around that the helpers are only for the script, link, title and meta i wouldnt create helpers for every html element i use a decorator like so <?php namespace Head\View; use Exception\Exception as Exception; use HTML\Decorator_Abstract as Decorator_Abstract; use HTML\Decorator_Interface as Decorator_Interface; class Script Extends Decorator_Abstract implements Decorator_Interface { CONST ATTRIBUTES = array( 'charset', 'src', 'type' ); CONST BOOLEAN_ATTRIBUTES = array( 'async', 'defer' ); CONST ATTRIBUTE_VALUES = array( 'type' => array( 'text/javascript', 'text/ecmascript', 'application/ecmascript', 'application/javascript' ) ); protected function opening_tag() { return sprintf("<script%s>", $this->attributes()); } protected function closing_tag() { return '</script>'; } public function render() { return $this->opening_tag() . $this->closing_tag(); } } regarding using a template engine with the view, i don't really see the point i'm able to extract variables to the html like so $this->view->name = 'Destramic'; and use in my template like so $this->name; wouldn't using a template engine just over-complicate thing? with all the var, if, foreach syntax? thank for your help
-
good point...ok i did just that use MVC\View\View as View; $view = new View; $view->head->script(array( 'src' => 'test4' ))->append(array( 'scr' => 'hi4' )); $view->head->script->append(array( 'src' => 'test3' ))->append(array( 'scr' => 'hi3' )); echo $view->head->script; use MVC\View\Helper as Helper; $helper = new Helper; $helper->head->script(array( 'src' => 'test4' ))->append(array( 'scr' => 'hi4' )); $helper->head->script->append(array( 'src' => 'test3' ))->append(array( 'scr' => 'hi3' )); echo $helper->head->script; use View\Helper\Head as Head; $head = new Head; $head->script(array( 'src' => 'test2' ))->append(array( 'scr' => 'hi2' )); $head->script->append(array( 'src' => 'test3' ))->append(array( 'scr' => 'hi3' )); echo $head->script; use Helper\Head\Script as Script; $script = new Script; $script->set(array( 'src' => 'test' ))->append(array( 'scr' => 'hi' )); echo $script; which returns : // from view Array ( [0] => Array ( [src] => test4 ) [1] => Array ( [scr] => hi4 ) [2] => Array ( [src] => test3 ) [3] => Array ( [scr] => hi3 ) ) // from helper Array ( [0] => Array ( [src] => test4 ) [1] => Array ( [scr] => hi4 ) [2] => Array ( [src] => test3 ) [3] => Array ( [scr] => hi3 ) ) // from head Array ( [0] => Array ( [src] => test2 ) [1] => Array ( [scr] => hi2 ) [2] => Array ( [src] => test3 ) [3] => Array ( [scr] => hi3 ) ) // from script Array ( [0] => Array ( [src] => test ) [1] => Array ( [scr] => hi ) ) well i didn't expect it all to return results as it did...now i'm scratchig my head a bit here why when called like so does it return an empty array // controller $this->view->head->script(array( 'src' => 'test' )); // view <?= $this->head->script; ?> i want to use it for all head tags doctype, link, title etc...its how i see modern frameworks set thier head and then just call when needed in the view...i just asume that is the correct way as i have no real idea of what is the best practice other than what i see or unless you guys tell me different i suppose i could just scrap the whole idea altogether and just put html where it needs to go, but i find with this method i could have all control of the head inside my controller....i did notice a post of yours metioning a template engine with thier mcv before, but its maybe something i coiuld look into if that is a good way to go but with my method i'm able to set all default links, scripts, title etc and just call in my view, with the option of appending inside the controller too.
-
hey guys i'm currently writing a head helper and probably down to my bad design i'm unable to return array stored in my placeholder here is my head helper: <?php namespace View\Helper; use Exception\Exception as Exception; class Head { private $_tags = array( 'script' => 'Helper\Head\Script', 'link' => 'Helper\Head\Link' ); public function __get($key) { if (isset($this->_tags[$key])) { if (is_object($this->_tags[$key])) { return $this->_tags[$key]; } else if (class_exists($this->_tags[$key])) { $this->_tags[$key] = new $this->_tags[$key]; return $this->_tags[$key]; } } return null; } public function __call($key, $arguments) { if (!is_null($this->$key)) { $this->$key->set($arguments[0]); return $this->$key; } return null; } } pre set scripts within bootstrap $view->head->script(array( 'src' => 'test' ))->prepend(array( 'src' => 'hello' )); append to the scripts witin controller $this->view->head->script->append(array( 'src' => 'bye' )); script class <?php namespace Helper\Head; use Exception\Exception as Exception; use Placeholder\Placeholder as Placeholder; use Head\View\Script as Script; class Script extends Placeholder { public function __toString() { print_r($this->get()); // $script = new Script(array('src' => 'hello')); // return $script->render(); return 'return'; } } when __toString is executed in my view, the array stored in my placeholder is empty. <?= $this->head->script; ?> Array() i know the problem all lies down to the head helper, because when using the __call or __get method it returns the script object which has not reference of previous appends/depends of the script tag. ummm i hope i explained myself enough and that there is a simple way of makig this work to how i want. previously i used to something like this but it looks ugly when setting scripts public function __call($method, $parameters) { if (preg_match('/^(?P<action>set|(ap|pre)pend)]*(_)*(?P<type>title|meta|script|link)$/', $method, $matches)) { $parameters = $parameters[0]; $tag_name = $matches['type']; $action = $matches['action']; $tag = $this->get_tag($tag_name); return $tag->$action($parameters); } } // $this->view->head->set_script()->append(); if you require to look at any code please let me know...thank you for your time
-
it's hard to build a good framework in my opinion...i'm currently re-designing mine which i made 3 years ago....but with mine you have the view, modlel, controller but also the module which i get quite confused at and have yet to understand fully what's used for...that aside as you questions are not too specific and i'd suggest to download a framework such as zend (like i did) and spending time reading the manuel and stripping apart the code to understand the logic and the design of a framework first of all i have a router class which matches routes to a specific uri, then the controller, action and parameters are dispatched and load the contoller... the controller i'm able to access the view and the model i think if your trying to build a mvc, which is good in my optioin, cause i hate to use code i haven't written myself, then you you need to break down what each element does and how it's going to perform, plus cut out all the BS! inbetween. posting some code would be useful and maybe we could give you some points.
-
well i've learned something here had a read and this seems to do the trick on duplicate posts, unless i missed something <?php session_start(); if (isset($_SESSION['form'])) { print_r($_SESSION); print_r($_POST); // use data unset($_SESSION['form']); } else if (isset($_POST['submit'])) { $_SESSION['form'] = $_POST; header("Location: " . $_SERVER['REQUEST_URI']); exit; } else { ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Demo</title> </head> <body> <h1>The Form</h1> <form action="" method="POST"> Some Data: <input type="text" value="some data" name="data" id="data" /><br /> <input name='submit' type="submit" /> </form> </body> </html> <?php } ?>
-
your not going to achieve $conf->test when selecting multiple rows. i'd stick with $config['test'] mate
-
doh!...sorry i read something wrong, you are correct....i just got the manuel up a function like this would be great...a loop with preg_match is is then...i'm not sure it's going to save time caching it this way though...time will tell
-
if i'm correct the PREG_GREP_INVERT allows it to work this way also
-
i tried that but even then it returns the same array i did just realised that /register/(?P<activation_code>[^\s]+) didnt have a ) at the end still the same problem though $uri = '#^/register/aqwrgj73ffgsegr2h$#'; $routes = array( '/register', '/register/(?P<activation_code>[^\s]+)' ); $match = preg_grep($uri, $routes, PREG_GREP_INVERT); print_r($match);
-
hey guys i'm currently trying to create a cache system for my router, which i think i'm always there but i'm having a slight problem with preg_grep() here is how it goes...the routes are added Router::add_route('/register', array()); Router::add_route('/register/:activation_code', array()); (this is an example - i wouldnt really need to add two routes for /register page) the routes get added to my router class and then get passed to the route pattern class where the patterns will get phased. <?php namespace Router; use Exception\Exception as Exception; class Route_Pattern { const ROUTE_VARIABLES = '(?<=\/)(?[ahis])(?=?!.*?\{)))?(?:\w++)(?!\{\w+\}))?(?\*)|\{([\w-]+(?:\|[\w-]+)+)*\})?(?<!\/)'; const ROUTE_OPTIONAL_SEGMENTS = '(?:^|\G)[^\[\]]*(\[\/((?:[ahis]??[\w-]+)(?:\[\/((?:[ahis]??[\w-]+)\])?\])(?=\[|$)'; private $_character_types = array( 'i' => '[\d]++', 'a' => '[\dA-Za-z]++', 'h' => '[\dA-Fa-f]++', 's' => '[\w-]++', ); private $_route_pattern; public function phase($route_pattern) { if (is_null($route_pattern)) { throw new Exception('Route Pattern: Route pattern is empty.'); } $this->_route_pattern = $route_pattern; $this->optional_segments(); $this->variables(); return $this->_route_pattern; } private function variables() { $parameters = $this->match(self::ROUTE_VARIABLES, $this->_route_pattern); if ($parameters) { $count = count($parameters[0]); for ($i = 0; $i < $count; $i++) { $match = $parameters[0][$i]; $character_type = $parameters[1][$i]; $parameter = $parameters[2][$i]; $all_variable = $parameters[3][$i]; $static_values = $parameters[4][$i]; if ($static_values) { $replace = '(' . $static_values . ')'; } else { $replace = $this->character_type($character_type); } if ($parameter) { $replace = '(?P<' . $parameter . '>'. $replace . '+)'; } $this->_route_pattern = $this->replace($match, $replace, $this->_route_pattern); } } return $this->_route_pattern; } private function optional_segments() { $parameters = $this->match(self::ROUTE_OPTIONAL_SEGMENTS, $this->_route_pattern); if ($parameters) { $count = count($parameters[0]); for ($i = 0; $i < $count; $i++) { $match = $parameters[1][$i]; $segment1 = $parameters[2][$i]; $segment2 = $parameters[3][$i]; $replace = '(/' . $segment1; if ($segment2) { $replace .= '/' . $segment2; } $replace .= ')?'; $this->_route_pattern = $this->replace($match, $replace, $this->_route_pattern); } } return $this->_route_pattern; } private function character_type($character_type = null) { if (isset($this->_character_types[$character_type])) { return '(' . $this->_character_types[$character_type] . ')'; } return '[^\s]'; } private function replace($search, $replace, $subject) { $search = '#' . preg_quote($search) . '#'; return preg_replace($search, $replace, $subject, 1); } private function match($pattern, $subject) { $pattern = '#' . $pattern .'#'; if (preg_match_all($pattern, $subject, $matches)) { return $matches; } return false; } } uri: /register/aqwrgj73ffgsegr2h route pattern /register/:activation_code route pattern phased: /register/(?P<activation_code>[^\s]+ so i decided i'd cache the phased route pattern and use preg_grep (which i'm new to) to match the uri to a single pattern. now here is the problem at hand $uri = '/register/aqwrgj73ffgsegr2h'; $routes = array( '/register', '/register/(?P<activation_code>[^\s]+' ); $match = preg_grep($uri, $routes, PREG_GREP_INVERT); print_r($match); which returns Array ( [0] => /register [1] => /register/(?P<activation_code>[^\s]+ ) so my question is why is key 0 (/register) present? as its not even a match what i'd expect to have matched is /register/(?P<activation_code>[^\s]+ any help on this or my methods would be greatly appreciated...thanks guys
-
i only gone and nailed it #/([ahis])?(\w+))?(?\(([\w-+]+(?:\|[\w-]+)+)*\))|(\*)|(?<=:\w))(?![^\[\]]*\])# thanks you for pointing me into the right direction requinix
-
that is what i need...i come up with: #(?<=/)([ahis])?(?:(\w+))?\(([\w-]+(?:\|[\w-]+))*\)|((\w+))?\*)|\w+))(?![^\[\]]*\])# which is a bit spicy...i don't like how i've had to add (\w+)) to every options, also a:var(a) will come with a match althoght it shouldn't i think i'm gonna stop over complicating the pattern and just do each pattern individually thank you for your help again on this matter
-
sorry i meaning zero or one time ---> ? this returns my match perfectly $pattern = '#(?<=/)(([ahis]?)\w+))?(\(([\w-]+(?:\|[\w-]+)*)\))?(\*)?(?![^\[\]]*\])#'; if (preg_match_all($pattern, '/news/:action(add|delete|edit)/:type', $matches)) { print_r($matches); } but becuase of the ? zero or one, this subject (/test[/hello[/bye]]) will return matches because of the / $pattern = '#(?<=/)(([ahis]?)\w+))?(\(([\w-]+(?:\|[\w-]+)*)\))?(\*)?(?![^\[\]]*\])#'; if (preg_match_all($pattern, '/test[/hello[/bye]]', $matches)) { print_r($matches); } what i'm asking is there a way of making my pattern look for: /(with at least one of the zero or one groups) or else don't match i just don't want the regex pattern to match on a / hope i made myself a bit more clearer thank you
-
is the directory you trying to move the file to writable? or does the dir exist?...do you have any errors?
-
in my regex pattern i have a lot of none or many operators (?) , which has caused a bit of a problem, as a string containing a forward slash will come back with a result. (?<=/)(([ahis]?)\w+))?(\(([\w-]+(?:\|[\w-]+)*)\))?(\*)?(?![^\[\]]*\]) is it possible to match with a string containing at lease on for the one or many groups? and not just a forward slash? $pattern = '#(?<=/)(([ahis]?)\w+))?(\(([\w-]+(?:\|[\w-]+)*)\))?(\*)?(?![^\[\]]*\])#'; if (preg_match_all($pattern, '/news/:action(add|delete|edit)/:type', $matches)) { print_r($matches); // wanted match } if (preg_match_all($pattern, '/test[/hello[/bye]]', $matches)) { print_r($matches); // unwanted match } i'm not able to find evidence that such thing exists, but it's worth an ask. the reason i bundled all of my routing patterns into one regex pattern is so that i have one simple method to phase all route variables. giving me a nice array to work with: Array ( [0] => Array ( [0] => / [1] => /:action(add|delete|edit) [2] => /:type ) [1] => Array ( [0] => [1] => :action [2] => :type ) [2] => Array ( [0] => [1] => [2] => ) [3] => Array ( [0] => [1] => action [2] => type ) [4] => Array ( [0] => [1] => (add|delete|edit) [2] => ) [5] => Array ( [0] => [1] => add|delete|edit [2] => ) [6] => Array ( [0] => [1] => [2] => ) ) private function variables() { $pattern = self::ROUTE_VARIABLES; $parameters = $this->match($pattern); if ($parameters) { $count = count($parameters[0]); $route_split = explode('/', $this->_route); $uri_split = explode('/', $this->_uri); for ($i = 0; $i < $count; $i++) { $match = $parameters[0][$i]; $type = $parameters[2][$i]; $name = $parameters[3][$i]; $key = $this->array_search($match, $route_split); if (!isset($uri_split[$key])) { return false; } $value = $uri_split[$key]; if (!empty($parameters[5][$i])) { $values = explode('|', $parameters[5][$i]); if (!in_array($value, $values)) { return false; } else if (empty($name)) { $this->_route = $this->replace($match, $value, $this->_route); continue; } } else if (!empty($parameters[6][$i])) { if (empty($parameters[1][$i])) { $this->_route = $this->replace($match, '(.*)', $this->_route); continue; } else { $next_key = $key + 1; if (!isset($route_split[$next_key])) { return false; } $next_value = $route_split[$next_key]; $values = array(); for ($j = $key; $j < count($uri_split); $j++) { if ($uri_split[$j] === $next_value) { break; } $values[] = $uri_split[$j]; } $value = implode('/', $values); } } if ((!empty($type) && !$this->is_type($value, $type))) { return false; } $replace = '(?P<' . $name . '>'. $value . '+)'; $this->_route = $this->replace($match, $replace, $this->_route); } } return true; } thank you
-
how to post only user selected values in a form
Destramic replied to michelle1404's topic in Javascript Help
sounds like you havent got jquery included https://developers.google.com/speed/libraries/ latest: <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script> -
thanks guys for you replies...just what i'm after! @phscho yours returned an error strange really as my workbench is up to date also i had to turn off safe updates on my mysql workbench...not sure if that is a mysql workbench thing or i would still have gotten the same error if i hadn't of turned off and executed from my php script? thanks again much appreciated
-
hey guys i'm trying to delete all rows but the latest 6 but i'm having some trouble with the query if you could please help. i've done some reading and have been llooking at simular queries to what i'm after, but i'm not succeeding. here is what i have so far: DELETE FROM benchmarks WHERE ( SELECT count(benchmark_id) FROM benchmarks WHERE name = 'Framework' ORDER BY timestamp ASC ) < 6 the error i get is: any help on where i'm going wrong would be great. thank you guys
-
wel i feel a lot wiser now...thank you for the breakdown and all your help requinix
-
for 4:30am you've come up with some good solutions i do like the first option and it does get rid of the bother caused by the brackets and you've openned my mind up to another soltion, thank you...options 2 is what i'm currently doing at the moment. although my regex knowledge is poor could you please explain to me how i can make this pattern match multiple please? $uri = "/i:news_id/:hello"; if (preg_match_all('/^\/(i|a|h)?[A-Za-z0-9_]+)$/', $uri, $parameters)) { print_r($parameters); } thank you for your great information
-
well my routing system may contain something like this: /search/xbox[/category/:category] matching: /search/xbox /search/xbox/category/consoles so i decided to make my pattern a bit stonger so it match uri vars which are not inside brackets...so yeah my pattern has changed slightly...with the regex in this posts and the others i'm working on i get the problem of matching multiple patterns in the same string...this is my only problem. can you please tell me where i'm going wrong...thank you
-
i'm sorry for having to post a simular thread but i'm really struggling to get my pattern to work after many attempts...i've tried playing around with it but its just not matching multiple patterns this will work great $uri = "/i:news_id"; if (preg_match_all('/(??!\[\/).)*^\/(i|a|h)?[A-Za-z0-9_]+)$(??!\]))/', $uri, $parameters)) { print_r($parameters); } but when chaging this part of the code it won't work $uri = "/i:news_id/:hello"; examples of matching are: /:test /i:test /a:test /b:test but i only want a match as long as the pattern isn't wrapped inside brakcets [ ] invalid: [/:test] i thought the ^ start and $ end characters would have been all i needed...any advise wouldnt greatful...thank you