Jump to content
Killersites Forums

Navigation Display Issue - Oo Php Shopping Cart


masterdrue
 Share

Recommended Posts

Hi..

Going through video's 11-12 for the creation of (m_categories.php), when I added the line of code,

<?php $this->get_data('page_nav'); ?>

in public header I ended up with a navigation that displayed the "li" tags themselves in the navigation.

 

Index.php

<li class="active"><a href="http://localhost/dapouda/">View All</a></li><li><a href="http://localhost/dapouda/index.php?id=3">Clothing</a></li><li><a href="http://localhost/dapouda/index.php?id=2">Electronics</a></li><li><a href="http://localhost/dapouda/index.php?id=1">Toys</a></li>

 

So I went back through both videos and checked line for line any possible typo's, then copied in the project source to see if it would work correctly and I get the same result.

Also note, that I did get the correct array output from the part of "echo pre tags" section.

 

I rechecked public header

<div class="secondarynav">
       	<strong>0 items ($0.00) in cart</strong>  |  
           <a href="<?php echo SITE_PATH;?>cart.php">Shopping Cart</a>
       </div>

       <h1><?php echo SITE_NAME; ?></h1>

       <ul class="nav">
		<?php $this->get_data('page_nav'); ?>
       </ul> 

 

which appears to match the source project also.

 

m_categories.php

/*
	Create page parts
*/

/**
 * Returns an unordered list of links to all category pages
 *
 * @access	public
 * @param	string (optional)
 * @return	string
 */
public function create_category_nav($active = NULL)
{
	// get all categories
	$categories = $this->get_categories();

	// set up all item
	$data = '<li';
	if (strtolower($active) == 'home') 
	{
		$data .= ' class="active"';
	}
	$data .= '><a href="' . SITE_PATH . '">View All</a></li>';

	// loop through each category
	if ( ! empty($categories))
	{
		foreach($categories as $category)
		{
			$data .= '<li';
			if (strtolower($active) == strtolower($category['name']))
			{
				$data .= ' class="active"';
			}
			$data .= '><a href="' . SITE_PATH . 'index.php?id=' . $category['id'] . '">' . $category['name'] . '</a></li>';
		}
	}

	return $data;
}

One thing I did notice in Chromes view, was quotes after UL (see nav-error2)..

post-61046-018535700 1363026756_thumb.jpg

post-61046-063126600 1363027028_thumb.jpg

So I'm ultimately at a loss and hope you can steer me down the right path.

Thanks...

Drue

Link to comment
Share on other sites

Hi Ben,

Thanks for the response. I assume your asking for m_template.php, if it's another file, let me know..

Thanks again..

/*
Template Class
handles all templating tasks - displaying views, alerts, errors and view data

*/
class Template
{
private $data;
private $alert_types = array('success', 'alert','error'); 

function __construct(){}
/*
* Loads specified url
* 
* @access public
* @param string, string
* @return null
*/
public function load($url, $title = '')
{
	if($title !=''){$this->set_data('page_title',$title);}
	include($url);
}
/*
* Redirects to specified url
* 
* @access public
* @param string
* @return null
*/
public function redirect($url)
{
	header("Location: $url");
	exit;
}
/*
	Get Set Data
*/
/*
* Saves provided data for use by the view later
* 
* @access public
* @param string, string, bool
* @return null
*/
public function set_data($name, $value, $clean = FALSE)
{
	if($clean = TRUE)
	{
		$this->data[$name] = htmlentities($value, ENT_QUOTES);
	}
	else
	{
		$this->data[$name] = $value;
	}
}
/*
* Retrieves data based on provided name for access by view
* 
* @access public
* @param string, bool
* @return string
*/
public function get_data($name, $echo = TRUE)
{
	if(isset($this->data[$name]))
	{
		if($echo)
		{
			echo $this->data[$name];
		}
		else
		{
			return $this->data[$name];
		}
	}
	return '';
}

/*
	Get Set Alerts
*/
/*
* Sets an alert message stored in the session
* 
* @access public
* @param string, string (optional)
* @return null
*/
public function set_alert($value, $type = 'success')
{
	$_SESSION[$type][]=$value;
}
/*
* Returns strings, containing multiple list items of alerts
* 
* @access public
* @param 
* @return null
*/
public function get_alerts()
{
	$data ='';

	foreach($this->alert_types as $alert)
	{
		if (isset($_SESSION[$alert]))
		{
			foreach($_SESSION[$alert] as $value)
			{
				$data.= '<li class="' . $alert . '">' . $value . '</li>';
			}
			unset($_SESSION[$alert]);
		}
	}
	echo $data;
}
}

Link to comment
Share on other sites

The only other thing I can think of is that maybe when you are creating the menu using set_data() in your controller, you're passing in "True" as the third parameter, meaning that htmlspecialchars() is being called, and any code is being escaped rather than being processed properly by the browser.

 

If that isn't it though, I'm not really sure what's going on. If you've checked the controller code and made sure that the above isn't happening, you can try zipping your entire project and emailing it to me (ben [at] killersites.com) and I'll take a look as soon as I have time.

Link to comment
Share on other sites

Strange because I followed each video to suite..but theres always a margin for a typo.. I did perform the checks as was demonstrated. I'll go back through and swap out source for my code to see if i can isolate it and hone in on it.. thanks again..

Link to comment
Share on other sites

  • 2 weeks later...

Success... Unbelievable..

 

After line by line review, watching the video's umpteen more times.. i discovered that I misused the comparison operator in the get set data function in m_template.php.

 

Before

public function set_data($name, $value, $clean = FALSE)
{
	if($clean = TRUE) //Notice 1 equal
	{
		$this->data[$name] = htmlentities($value, ENT_QUOTES);
	}
	else
	{
		$this->data[$name] = $value;
	}
}

 

After

public function set_data($name, $value, $clean = FALSE)
{
	if($clean == TRUE)
	{
		$this->data[$name] = htmlentities($value, ENT_QUOTES);
	}
	else
	{
		$this->data[$name] = $value;
	}
}

Unbelievable how 1 oversight can completely stop production.

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

×
×
  • Create New...