Closed kampunghosting closed 7 years ago
What does your code look like? A view is just a PHP page, so you could pass in your function like you do your template variables.
`function getBaseUrl()
{
// output: /myproject/index.php
$currentPath = $_SERVER['PHP_SELF'];
// output: Array ( [dirname] => /myproject [basename] => index.php [extension] => php [filename] => index )
$pathInfo = pathinfo($currentPath);
// output: localhost
$hostName = $_SERVER['HTTP_HOST'];
if(!empty($_SERVER['HTTP_X_FORWARDED_PROTO'])){
$protocol = $_SERVER['HTTP_X_FORWARDED_PROTO'].'://';
}else{
$protocol = strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,5))=='https://'?'https://':'http://';
}
$cekdir =$pathInfo['dirname']==='/'?'/':$pathInfo['dirname'].'/';
return $protocol.$hostName.$cekdir;
}`
and in view i try call function with function getBaseUrl() , but not work
I mean how are you calling your function? You can't just call any function from a view. You need to pass the function to your template.
$getBaseUrl = 'getBaseUrl';
Flight::render('template.php', array('getBaseUrl' => $getBaseUrl));
Then in your template you can call the variable:
$getBaseUrl();
Or you can use PHP $GLOBALS
to create a global variable.
Hi, I have this code:
Flight::render('header');
Flight::route('/', function(){ Flight::render('hello', array('title' => 'Bob')); });
My ask is this:
How can show the variable $title in the template "header", I only can show the variable $title in template "hello"
Thanks You.!
Regards!
Arthur03: First you must render yout template header in route like this Flight::route('/', function(){ Flight::render('header', array('title' => 'Bob')); Flight::render('hello', array('title' => 'Bob')); });
I hope i can help you..
hai, i make getBaseUrl() function in index. and i want to call function in view. but i get error ! ) ( ! ) Fatal error: Call to undefined function getBaseUrl() i
and, how to make custom library to framework?