Jump to content

Destramic

Members
  • Posts

    954
  • Joined

  • Last visited

Everything posted by Destramic

  1. 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.
  2. 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
  3. 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.
  4. 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 } ?>
×
×
  • 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.