Page 2 of 2

Posted: Tue Aug 07, 2007 2:07 am
by feyd
search for forums for the term "dereference"

Posted: Tue Aug 07, 2007 4:44 am
by stereofrog
fwc wrote:While I'm at it can someone please explain the syntax

Code: Select all

->
Ok, thanks
IIRC, php manual doesn't mention this anywhere, kind of "implied knowledge" I guess.

-> is an "of" operator, "foobar->quux" means "quux of foobar". It's used to access object's properties and methods.

And no, it has nothing to do with references and dereferencing. ;)

Posted: Tue Aug 07, 2007 8:34 am
by Zoxive

Code: Select all

<?php
// The linked you clicked on what something like 'mysite.com?page=about'

include ('db_config.php');

$page = strtolower($_GET['page']);

include ('header.php');

switch($page){
  default:
    echo "<p>YEA</p>";
    echo "<a href=/eclipse_projects/?page=about>About</a><br>";
  break;

  case 'about':
    echo "<p>We're the smurf!</p>";
    echo "<a href=/eclipse_projects/?page=home>Home</a><br>";
  break;

  case 'contact':
    echo "<p>Contact Page!</p>";
    echo "<a href=/eclipse_projects/?page=home>Home</a><br>";
  break;
}

include ('footer.php');

?>
Is an example of a switch, which in cases like this would be more readable then multiple "else ifs".

And you were getting a blank page, because none of your if statements where validated TRUE.

Posted: Tue Aug 07, 2007 9:02 am
by fwc
thanks very much to the three posts above me, I understand better what the -> means

As for my browsing that is a good option but I found one that worked :)

EDIT: I just looked at Zoxive's a little closer and it is actually very good, thanks a bunch

Code: Select all

<?php
include ('db_config.php');
//Get page info
$page =	$_GET['page'];

if (!$page)
{
	include ('header.php');
	include ('body1.php');
	echo "<a href=/eclipse_projects/?page=about>About</a><br>";
	include ('footer.php');
	
}

//About Page
else if ($page == 'about')
{
	include ('header.php');
	echo "<p>We're the <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>!</p>";
	echo "<a href=/eclipse_projects/?page=home>Home</a>";
	include ('footer.php');
}

//Contact
else if ($page == 'contact')
{
	   echo "<p>Contact Page!</p>";
    echo "<a href=/eclipse_projects/?page=home>Home</a><br>";
}

?>

Posted: Tue Aug 07, 2007 9:24 am
by fwc
stereofrog wrote:
fwc wrote:While I'm at it can someone please explain the syntax

Code: Select all

->
Ok, thanks
IIRC, php manual doesn't mention this anywhere, kind of "implied knowledge" I guess.

-> is an "of" operator, "foobar->quux" means "quux of foobar". It's used to access object's properties and methods.

And no, it has nothing to do with references and dereferencing. ;)
Ok, well I'm looking over Smarty and the potential uses of templates but I can't figure out what these "->" symbols are doing. Are they storing information into $tpl?

EDIT: Ok, wait nevermind, they must be getting information from $tpl?

Code: Select all

<?php

require_once('Smarty.class.php');

$self = $DOCUMENT_ROOT . $PHP_SELF;

$tpl = new Smarty;

$tpl->template_dir = dirname($self);

$tpl->compile_dir = $tpl->template_dir . '/.smarty/templates_c';

$tpl->config_dir = $tpl->template_dir . '/.smarty/configs';

$tpl->cache_dir = $tpl->template_dir . '/.smarty/cache';

$tplname = basename($self);

$cacheid = '';

Posted: Tue Aug 07, 2007 9:42 am
by Zoxive

Code: Select all

<?php

class Dog{
	$name = 'None';
	
	function name(){
		echo $this->name;
	}
}

$var = new Dog();             // $var is now an Instance of the Class Dog
$var->name();                   // Calls the function name in the class Dog
// Echos 'None';

$var2 = new Dog();
$var2->name = 'Spot';
$var2->name();
// Echos Spot

?>
PHP Manual

Posted: Tue Aug 07, 2007 9:56 am
by fwc
Zoxive wrote:

Code: Select all

<?php

class Dog{
	$name = 'None';
	
	function name(){
		echo $this->name;
	}
}

$var = new Dog();             // $var is now an Instance of the Class Dog
$var->name();                   // Calls the function name in the class Dog
// Echos 'None';

$var2 = new Dog();
$var2->name = 'Spot';
$var2->name();
// Echos Spot

?>
PHP Manual
thankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyou