Jump to content

Oop Login Tutorial - Problem With Template Class


Neo73

Recommended Posts

Hi,

 

I tried to use the authentication class from the OOP login tutorial in combination with the OOP shopping cart.

 

The problem is that both tutorials use different template methods, in particular getData(). Out of the box, the OOP login classes, just work fine, I can log in and out without problems. 

 

However, in combination with the m_template.php of the shopping cart, the login credentials (although correct) are posted at the top of the page and the 'access-denied' error message is displayed.

 

I tracked the problem down to the getData()-function in m_template.php, which seems to cause the issue:

 

getData() within login tutorial:

function getData($name)
	{
		if (isset($this->data[$name]))
		{
			return $this->data[$name];
		}
		else
		{
			return '';
		}
	}

getData() within shopping cart tutorial:

public function getData($name, $echo = TRUE)
	{
		if (isset($this->data[$name]))
		{
			if ($echo)
			{
				echo $this->data[$name];
			}
			else
			{
				return $this->data[$name];
			}
		}
		return '';
	}

When I replace the getData()-function of the original login tutorial with the one in the shopping cart tutorial, I am able to log in and out, but no content is displayed any longer (i.e. no menus, no products).

 

I would appreciate your help on how to integrate this properly.

Link to comment
Share on other sites

Looks like the problem is that the defaults between those two functions are different. By default, the getData() function within the login tutorial returns the variable, whereas the default getData() function from the shopping cart tutorial echos the data.

 

With that in mind, and considering that the login functionality involves less code, I would suggest using the getData() function from the cart tutorial, and make sure to pass "FALSE" in as the second parameter in any instances of getData() within the login code where you need to return the data rather than echo it out.

 

My apologies about the default functionality changing -- I didn't even realize that till just now. I'm not completely sure why it changed, it's just what made sense to me at the time when I was developing it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...