Jump to content

setting a global help


ricky spires

Recommended Posts

hello,

 

ok if i set a Global on index.php  (wwwroot/admin/index.php) it works

 

$page1='hello from page1 on index';
global $page1;
echo $page1;

 

i can echo $page1 on other pages like (wwwroot/admin/pages/home.php) and it will echo out "hello from page1 on index".

 

GREAT

 

but if i write a Global on (wwwroot/admin/pages/home.php) it does not work. i also can not echo it out on any other page

 

$page2='hello from page2 on home';
global $page2;
echo $page2;

 

 

 

why is this ???

Link to comment
https://forums.phpfreaks.com/topic/248541-setting-a-global-help/
Share on other sites

ok.

 

so if i had this code below on a page...

 

$pName = 'adminHome';
$page = Pages::find_by_pageName($pName);

 

and this method (function) inside my class

 

public static function find_by_pageName($pName){
$sql = "SELECT * FROM ".self::$table_name." WHERE pageName='".escape_value($pName)."'";
	$result_array = self::find_by_sql($sql);

return !empty($result_array) ? array_shift($result_array) : false;
}

 

which will return these values on the page

 

$page = Pages::find_by_pageName($pName);

echo $page->id."<br />";
echo $page->pageName."<br />";
echo $page->visible.'<br/>';
echo $page->layoutElements_id.'<br/>';
echo $page->layoutTemps_id.'<br/>';
echo $page->module_id.'<br/>';
echo $page->title.'<br/>';
echo $page->sub_title.'<br/>';
echo $page->description.'<br/>';
echo $page->image.'<br/>';
echo $page->about.'<br/>';

 

 

how would i put the $page->pageName and the $page->layoutTemps_id ( OR ALL OF THEM) into there own globals to use them out on other pages

 

:)

 

 

The $page variable should be able to be accessed by any locally included file as long as the file is included below the declared variable.

// index.php
$pName = 'admin';
$page = Pages::find_by_pageName($pName);
include('something.php');

Then

// something.php
echo '$page is a ' , gettype($page);

The output of above should be 'object'

thanks.

 

i put this code on admin/pages/home.php

 

$pName = 'adminHome';
$page = Pages::find_by_pageName($pName);
//include('../index.php');

 

and i put this code on admin/index.php

 

echo '$page is a ' , gettype($page);

 

 

and it echo'd back

$page is a NULL

 

 

also i commented out //include('../index.php');

because it just displayed the index.php page on home.php

 

 

why is

$page is a NULL

 

i also tried this

echo '$page is a ' , gettype($page);
echo $page->pageName."<br />";

 

but it didnt echo the pageName

 

thanks

rick

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.