PHP Classes

There's no template helpers?

Recommend this page to a friend!

      Build Simple OO MVC  >  All threads  >  There's no template helpers?  >  (Un) Subscribe thread alerts  
Subject:There's no template helpers?
Summary:template helpers
Messages:2
Author:rudie dirkx
Date:2011-12-29 14:22:26
Update:2012-01-01 13:03:40
 

 


  1. There's no template helpers?   Reply   Report abuse  
Picture of rudie dirkx rudie dirkx - 2011-12-29 14:22:26
I don't see template helpers. I miss them (especially url or link) because the view hardcoded the URI:

<a href="/simple_mvc/">Home</a> |

but my app isn't located in /simple_mvc/.

If you add (extendable) template helpers, this tiny mvc package would be extremely useful.

  2. Re: There's no template helpers?   Reply   Report abuse  
Picture of jeffrey Afable jeffrey Afable - 2012-01-01 13:03:40 - In reply to message 1 from rudie dirkx
You can add a function like this.
Example:
<a href="<?php echo PathUrl('Link1'); ?>">Link1</a>


function PathUrl($path="",$viewIndex=TRUE){
$index = ($viewIndex==TRUE)?'/index.php':'';
$SCRIPT_NAME = $_SERVER['SCRIPT_NAME'];
if(strpos($SCRIPT_NAME,'index.php')>1 && !preg_match("/\/index.php/i",$_SERVER['REQUEST_URI'])) header('Location: '.$SCRIPT_NAME);
$SCRIPT_NAME = substr($SCRIPT_NAME,0,strpos($SCRIPT_NAME,'index.php'));
$isindex = preg_match("/index.php/i",$_SERVER['REQUEST_URI']);
if($isindex!=FALSE)
return str_replace('//','/',$SCRIPT_NAME.$index.'/'.$path);
else
return str_replace('//','/',$SCRIPT_NAME.'/'.$path);
}

I use this in one of my framework i made :) work fine..