Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

Vars into php injection template method

posted by irob 8 years ago

Hi

After a pair of days trying to organize my template codes I get that isn't possible to use php var from the parent file into injecting files, and I don't know why, here's what I'm doing:

index.php (parent file)

Then... if I got a php var in index.php this isn't possible to use into list_intems.php :| :
:( why???

Is any option to include files and enabling the option for use php vars????

Thank U

Are you using fTemplating? If so, you need to set values via fTemplating::set() when in your parent file, and then from the child files you can call $this->get().

If this doesn't help, please try posting some example code.

posted by wbond 8 years ago

May this example help you ?

www/views/header.php

<?php fHTML::sendHeader() ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"> 
<head> 
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
	<title><?php echo $this->prepare('title') ?></title> 

www/mysite/index.php

<?php include_once($_SERVER['DOCUMENT_ROOT'] . '/inc/init.php');

	if (fRequest::isPost()) {
		$validator = new fValidation();
		try {

		$myName = "James BOND";
		
		} catch (fExpectedException $e) {
			fMessaging::create('error', fURL::get(), $e->getMessage());	
		}	
	}

include '/../views/index.php';

www/views/index.php

<?php 
$tmpl->set('title', 'Welcome !'); // "Welcome !" will be printed in the template "header"
$tmpl->place('header');?>
<h1><?php echo $tmpl->prepare('title') ?></h1> //... and here, too (in the template index.php).
<form action="index.php">
	<input id="url" value="<?php echo Meetup::makeURL('delete', $meetup) ?>" .....> // it's OK : the object prints something
	<input id="email" value="<?php echo fRequest::encode('email') ?>" .....> // it's OK : the POST prints something
	<input id="name" value="<?php echo $myName ?>" .....> // It' OK too : the var passes the include
		......
</form>
<div class="alert">
	 <?php 	fMessaging::show('error', fURL::get()); ?> // it's OK : the error message is printed
</div>
<p>
	Name: <?php echo $myName ?> // OK too ! 
</p>
posted by gill 8 years ago

@Gill

The only issue I see there is that you are only setting $myName when the request is a POST and not when it is a GET. Other than that, it looks like it should work.

posted by wbond 8 years ago

Right ! It was for iRob. I hope it will help him...

There are many short examples, in the documentation (and I appreciate it a lot), but not really complete examples like this (or the demo). Though it's very usefull for beginners (like me). Of course, it's more PHP than Flourish...

posted by gill 8 years ago

Oops, it appears I misunderstood your post. Thanks for taking the time to write some examples and share them!

posted by wbond 8 years ago