Jump to content

PHP navigation list issue


lpmraven

Recommended Posts

Hi everyone,

 

I'm having problems with my drop down navigation bar, here is the coding for the section that the problem is occuring:

 

 <?php $squads = $this->squads->get_squads(array('squad_status' => 1)); ?>
               <?php if($squads): ?>
                <?php foreach($squads as $squad): ?> 
                    <li><span class="left"></span><span class="middle"> 
                        <?php echo anchor('roster/squad/' . $squad->squad_slug, $squad->squad_title); ?> 
                        </span><span class="right"></span></li> 
                <?php endforeach; ?> 
             <?php endif; ?>

 

On pages after this, all the content disappears, its as if i'm not closing off the code correctly, i'm a rookie, please help

 

I beleive the problem may be the top line, but I don't know what i'm doing.. haha

Link to comment
Share on other sites

A PHP Error was encountered

 

Severity: Notice

 

Message: Undefined property: ClanCMS_Loader::$squads

 

Filename: gamingcorps/header.php

 

Line Number: 111

 

 

Fatal error: Call to a member function get_squads() on a non-object in B:\xampp2\htdocs\clancms\views\themes\gamingcorps\header.php on line 111

 

 

the line it refers to is

 <?php $squads = $this->squads->get_squads(array('squad_status' => 1)); ?>

Link to comment
Share on other sites

ClanCMS uses CodeIgniter, which I am familiar with.

 

Is "squads" a model? I don't believe you can access models in that way from a view. You really shouldn't be anyway though, you should be getting that stuff in the controller and then passing it to the view.

Link to comment
Share on other sites

Yeah that did cross my mind but I tried to simply put this into my dashboard.php controller to see if it would make the squads appear and it didnt, but when i put it in the view header with the list code, the squads appear, I really am terrible with Codeigniter, I dont totally get how it works. 

 

<?php $squads = $this->squads->get_squads(array('squad_status' => 1)); ?>

 

I also tried to copy the entire roster controller and paste that into the dashboard controller, as the squads appear in the navigation bar only when your on the roster page... but that failed. I'm really not very good, I cant write MVC on my own.

 

Do I just put the

 

 <?php $squads = $this->squads->get_squads(array('squad_status' => 1)); ?>

 

into each controller so the squads navigation appears on all pages?

 

 

Or is this what I do?

 

   	/**
 * Index
 *
 * SQUAD NAVIGATION
 *
 * @access	public
 * @return	void
 */
function navigation()  <<<<[b] NOT sure what function to put[/b]
{
// Retrieve the squads
$squads = $this->squads->get_squads(array('squad_status' => 1));

    	 
   	// Load the squad navigation view
$this->load->view(THEME . 'dashboard', $this->data);     <<<<< [b]NOT sure what this should be[/b]
    }

 

Link to comment
Share on other sites

What you're trying to do already exists here: https://github.com/mahngiel/The-Clan-CMS-Project-codezyne/blob/master/clancms/controllers/roster.php

 

Yeah that did cross my mind but I tried to simply put this into my dashboard.php controller to see if it would make the squads appear and it didnt

 

If you want to bring a squad listing to your dashboard, it's easy

<?php
//fetch squads
$squads = $this->squads->get_squads(array('squad_status' => 1));

...
// Build objects
$this->data->squads =& $squads;

// load out
$this->load->view( THEME . 'dashboard', $this->data);

 

$tihs->data is the object that is storing all the data, by appending the objects we are using onto it, we can pass one object to our views.

Link to comment
Share on other sites

I have this in my dashboard controller:

 

   	/**
 * Index
 *
 * SQUAD NAVIGATION
 *
 * @access	public
 * @return	void
 */
function nav()
{
//fetch squads
    $squads = $this->squads->get_squads(array('squad_status' => 1));

    // Build objects
    $this->data->squads =& $squads;

    // load out
    $this->load->view( THEME . 'dashboard', $this->data);
    }

 

And this in my header view

 

               <?php if($squads): ?>
                <?php foreach($squads as $squad): ?> 
                    <li><span class="left"></span><span class="middle"> 
                        <?php echo anchor('roster/squad/' . $squad->squad_slug, $squad->squad_title); ?> 
                        </span><span class="right"></span></li> 
                <?php endforeach; ?> 
             <?php endif; ?>   

 

Doesn't work, am I missing something?

Link to comment
Share on other sites

it doesn't work because (most) every Class function in CodeIgniter is a route path.  What I mean is dashboard nav() actually goes to www.example.com/dashboard/nav

 

If you want to add your squads somewhere on the dashboard, add the squads object and the reference to it in the index()

Link to comment
Share on other sites

Im not trying to add them on my dashboard though, Im trying to create a navigation dropdown list with all the squads in it.

 

The list only works on the roster page because that page has the correct controller code, I am now trying to work out some code I can put in all controllers so that the squads navigation listing appears on each page of the site.

 

 

*** Apologies codezyne, I understand now :) working

 

Link to comment
Share on other sites

Ok  :D

 

I have squad_helper.php in the helpers folder

 

/**
* Squad menu
*
* 
*
* @access	public
* @param	array
* @return	bool
*/
function squad_menu()
{

//fetch squads
    $squads = $this->squads->get_squads(array('squad_status' => 1));

    // Build objects
    $this->data->squads =& $squads;

    // load out
    $this->load->view( THEME . 'dashboard', $this->data);
} 


/* End of file squad_helper.php */
/* Location: ./clancms/helpers/squad_helper.php */

 

Then in the header.php view I have

 

    <?php echo squad_menu(); ?>
               <?php if($squads): ?>
                <?php foreach($squads as $squad): ?> 
                    <li><span class="left"></span><span class="middle"> 
                        <?php echo anchor('roster/squad/' . $squad->squad_slug, $squad->squad_title); ?> 
                        </span><span class="right"></span></li> 
                <?php endforeach; ?> 
             <?php endif; ?>  

 

I believe I have done something wrong :)

Link to comment
Share on other sites

[ mods: this is a 3rd party script for all intensive purposes ]

 

Please pay attention to what you're actually doing, raven.  Foremost, you're trying to load a view where you are calling the helper.  My apologies if you did not fully understand i put it in my previously reply purely for demonstrative purposes.

 

You're got two options with regard to building the helper.  You can either expect data to build the menu OR you can expect the entire menu.  Let's make it entirely simple by expecting the entire menu.

 

<?php 
// helper
function squad_menu()
{
    // include model
    $this->load->model('Squads_model', 'squads');

    //fetch squads
    $squads = $this->squads->get_squads(array('squad_status' => 1));

    if( $squads )
    {
        // create menu
        $menu = '<ul>';

        foreach( $squads as $squad )
        {
            // create a LI for each squad and ammend it to $menu
            $menu .= '<li>' . $squad->squad_title . '</li>';
        }

        // close menu
        $menu .= '</ul>';
    }

    // return the menu
    return $menu;
}

// header.php
echo $squad_menu();
   

Link to comment
Share on other sites

 

A PHP Error was encountered

 

Severity: Notice

 

Message: Undefined variable: squad_menu

 

Filename: gamingcorps/header.php

 

Line Number: 110

 

<?php 
/**
* Clan CMS squad menu Helper
*
* @package		Clan CMS
* @subpackage  Helpers
* @category    Helpers
* @author		Xcel Gaming Development Team
* @link		http://www.xcelgaming.com
*/

// --------------------------------------------------------------------

/**
* Squad menu
*
* 
*
* @access	public
* @param	array
* @return	bool
*/

// helper
function squad_menu()
{
    // include model
    $this->load->model('Squads_model', 'squads');

    //fetch squads
    $squads = $this->squads->get_squads(array('squad_status' => 1));

    // Build objects
    $this->data->squads =& $squads;

    if($squads)
    {
        // create menu
        $menu = '<ul>';

        foreach($squads as $squad)
        {
            // create a LI for each squad and ammend it to $menu
            $menu .= '<li>' . $squad->squad_title . '</li>';
        }

        // close menu
        $menu .= '</ul>';
    }

    // return the menu
    return $menu;
}

/* End of file squad_helper.php */
/* Location: ./clancms/helpers/squad_helper.php */

 

<div id="squads">

<ul>
<li><div id="topbutton3"><a href="#"></a></div>  

    <?php echo $squad_menu(); ?>


    </li> 
</ul>  
   
</div>

 

I've tried to make it work but its not happening, any suggestions on whats not right?

Link to comment
Share on other sites

No, then you are repeating a ton of code.

 

No need for a widget here.  ClanCMS has a widget feature, but it's not necessary. 

 

If he did want a widget, the widget form of the helper would include the same code with $this->load/model being replaced by $this->CI->load/model

 

Just emulate one of the widgets in clancms/widgets

Link to comment
Share on other sites

Ok, this is my header.php view

 

<div id="squads">

<ul>
<li><div id="topbutton3"><a href="#"></a></div>  

   <?php echo $squad_menu(); ?>


    </li> 
</ul>  
   
</div>  

 

this is my squad_helper.php (in the helpers folder)

 

<?php 
/**
* Clan CMS squad menu Helper
*
* @package		Clan CMS
* @subpackage  Helpers
* @category    Helpers
* @author		Xcel Gaming Development Team
* @link		http://www.xcelgaming.com
*/

// --------------------------------------------------------------------

/**
* squad menu
*
* 
*
* @access	public
* @param	array
* @return	bool
*/

// helper
function squad_menu()
{
    // include model
    $this->load->model('Squads_model', 'squads');

    //fetch squads
    $squads = $this->squads->get_squads(array('squad_status' => 1));

    if($squads)
    {
        // create menu
        $menu = '<ul>';

        foreach($squads as $squad)
        {
            // create a LI for each squad and ammend it to $menu
            $menu .= '<li>' . $squad->squad_title . '</li>';
        }

        // close menu
        $menu .= '</ul>';
    }

    // return the menu
    return $menu;
}


/* End of file squad_helper.php */
/* Location: ./clancms/helpers/squad_helper.php */

 

I have added to the autoload

 

$autoload['helpers'] = array('squad_helper');

 

Its still not working, yet :)

Link to comment
Share on other sites

$squads_menu is not a variable (my bad, fingers typed too fast).

 

it's a helper function, it works like echo squads_menu().

 

The echo squads_menu is supposed to be in the header.php isnt it? What am I supposed to be doing, im lost?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.