Dynamic PHP Class

Greetings,

I made a PHP script that runs next: index.php?page=SomePage.

Here is the code

[php]<?php

$page		=   $_GET['page'];
$form		=	$_GET['form'];
$action		=	$_GET['action'];

//------------------------------------------------------------
$library = $_GET[‘library’];
$content = $_GET[‘content’];

if (!$page)
    $page = "Index";
        
		if (!strpos($page, ".") && !strpos($page, "/")) {
	
				if (!$library)
    			$library = "LCF/lib/";

   				if (!$content)
   				$path = "$library/page/".$page.".php";
			
				else
				$path = "$library/$content/".$page.".php";
		}

		if (isset($action))
		$path = "$library/action/".$action.".php";

		if (isset($form))
		$path = "$library/form/".$form.".php";

include ($path);
?>
[/php]

So, I want to make it as php class, so I made something like this but it is not working…

[php]class DynamicLinkLibrary {

var $page;
var $content;
var $library;
var $path;

protected function __construct($page, $content, $library, $path) {

	$this->page = $_GET['page'];
	$this->content = $_GET['content'];
	$this->library = $_GET['library'];
	$this->path = $_GET['path'];

if(!$this->page)
$this->page = “Index”;

	if(!strpos($this->page, ".") && !strpos($this->page, "/")) {

		if(!$this->library)
		$this->library = LCF_DIR.'lib/';
		
		if(!$this->content)
		$this->path = $this->library.'page/'.$this->page.'.php';		
		
		else
		$this->path = $this->library.$this->content.'page/'.$this->page.'.php';
	
	}

return self::$this->path;

}

}[/php]

What is the problem here?

All regards. :slight_smile:

Well, first off “isn’t working” isn’t helping. What kind of feedback does PHP ( in the form of errormessages ) give?

Then I notice you use an older syntax for the class. But I doubt that’s the problem.

Then I see your new (creator) method would have the form:
[php]
$bla = new DynamicLinkLibrary( $page, $content, $library, $path );
[/php]

You don’t use these variables in the constructor, so why pass them? ( and if you leave them out PHP will tell you it expected them )

I hope this gives you a bit of a starting point to look at the code again.
If you elaborate on the errors you get maybe I ( and no doubt others ) can be more helpful.

Good luck,
O.

Sponsor our Newsletter | Privacy Policy | Terms of Service