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
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

 

:)

 

 

Link to comment
Share on other sites

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'

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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