/    Sign up×
Community /Pin to ProfileBookmark

Content not injected into parents variable

Hi,

I’m developing a web application that deals with login as usual. However, somehow I’m getting stuck on something.
I have a controller which basically reads a config file and depending on the settings there does several things.
One of them is that is puts together a variable that holds a string that is actually the html that is to be printed after everything is done. I do this because I want to be able to send headers at any stage in the process.

The first thing is to put the head together, then do whatever is needed. In this case check for valid login. The system detects that there is no valid login so a login screen should be added to the html-string. At the end the system appends a footer.

Here’s the code the controller goes over:

[code=php]
// Fire up the system
$system = new System;
$system->output .= file_get_contents(‘./application/templates/top.html’);

// Parse the config file
if ($config[‘sessions’]) {
Sessions::setSession();
if ($config[‘login’]) {
if (!isset($_SESSION[‘login’]) && $_SESSION[‘login’] != 1) {
$login = new Login;
$auth = $login->login();
if ($auth) {
$_SESSION[‘login’] = 1;
Router::redirect(__REF__.’/nl/’.$config[‘default_module’].’/’.$config[‘default_method’].’/0/index.html’);
} else {
Messenger::displayError($login->messages);
}
}
}
}

try {
$system->ignition();
} catch (Exception $e) {
echo ‘Caught exception: ‘, $e->getMessage(), “<br/>”;
}

$system->output .= file_get_contents(‘./application/templates/bottom.html’);
$system->display();
[/code]

This function login() of the Login class is eventually called and it is supposed to add the html for the login box to the system variable $output. Therefore it calls $system->append(). I can see that the functions are all being called but somehow the html is not injected. Both the header and the footer are injected and displayed properly.

System function to add and display content:

[code=php]
function append($content) {
$this->output .= $content;
}

function display() {
echo $this->output;
}[/code]

Login function that adds html to the system class

[code=php]
public function displayLogin() {
$this->append(file_get_contents(‘./application/templates/login.html’));
}
[/code]

So the problem that I don’t see the html in ‘./application/templates/login.html’ anywhere.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@SyCoDec 11.2008 — I think you've just got the names mixed up.

This function login()[/QUOTE]
[code=php]public function displayLogin() { [/code]
Copy linkTweet thisAlerts:
@bealauthorDec 12.2008 — Thanks, I'm afraid that'tn not it. Login->login() checks whether the visitor is logged in or not. If not, the login function calls displayLogin() to draw the login box.
Copy linkTweet thisAlerts:
@bealauthorDec 12.2008 — Ok, I've got a little further on this thanks to this thread: http://codingforums.com/showthread.php?t=149958

The class Login is a child of System. So when I instantiate Login I'm actually overriding System. Therefore, when I call the method System->append() from Login->displayLogin() it's actually not the same instance as when I do it directly in the root class System.

So how can I let the Login class know that it should use the already instanciated class System and not redeclare and subsequently override it?
×

Success!

Help @beal spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...