lpmraven Posted July 27, 2012 Share Posted July 27, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/266338-php-navigation-list-issue/ Share on other sites More sharing options...
scootstah Posted July 27, 2012 Share Posted July 27, 2012 Any PHP errors? Is error reporting turned on? To make sure, put this at the top of your script: error_reporting(-1); ini_set('display_errors', 1); Quote Link to comment https://forums.phpfreaks.com/topic/266338-php-navigation-list-issue/#findComment-1364859 Share on other sites More sharing options...
lpmraven Posted July 27, 2012 Author Share Posted July 27, 2012 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)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/266338-php-navigation-list-issue/#findComment-1364860 Share on other sites More sharing options...
scootstah Posted July 27, 2012 Share Posted July 27, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/266338-php-navigation-list-issue/#findComment-1364862 Share on other sites More sharing options...
lpmraven Posted July 27, 2012 Author Share Posted July 27, 2012 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] } Quote Link to comment https://forums.phpfreaks.com/topic/266338-php-navigation-list-issue/#findComment-1364863 Share on other sites More sharing options...
Mahngiel Posted July 27, 2012 Share Posted July 27, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/266338-php-navigation-list-issue/#findComment-1364867 Share on other sites More sharing options...
lpmraven Posted July 27, 2012 Author Share Posted July 27, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/266338-php-navigation-list-issue/#findComment-1364869 Share on other sites More sharing options...
Mahngiel Posted July 27, 2012 Share Posted July 27, 2012 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() Quote Link to comment https://forums.phpfreaks.com/topic/266338-php-navigation-list-issue/#findComment-1364870 Share on other sites More sharing options...
lpmraven Posted July 27, 2012 Author Share Posted July 27, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/266338-php-navigation-list-issue/#findComment-1364871 Share on other sites More sharing options...
Mahngiel Posted July 27, 2012 Share Posted July 27, 2012 Then make a helper. If you named it 'squad_helper.php' with function 'squad_menu', you can add <?php echo squad_menu(); ?> into header.php Quote Link to comment https://forums.phpfreaks.com/topic/266338-php-navigation-list-issue/#findComment-1364872 Share on other sites More sharing options...
lpmraven Posted July 27, 2012 Author Share Posted July 27, 2012 Ok 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 Quote Link to comment https://forums.phpfreaks.com/topic/266338-php-navigation-list-issue/#findComment-1364874 Share on other sites More sharing options...
Mahngiel Posted July 27, 2012 Share Posted July 27, 2012 [ 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(); Quote Link to comment https://forums.phpfreaks.com/topic/266338-php-navigation-list-issue/#findComment-1364877 Share on other sites More sharing options...
lpmraven Posted July 27, 2012 Author Share Posted July 27, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/266338-php-navigation-list-issue/#findComment-1364887 Share on other sites More sharing options...
Mahngiel Posted July 27, 2012 Share Posted July 27, 2012 you have to include the helper. do so in clancms/config/autoload.php here: $autoload['helpers'] = array( ..., 'squad_helper'); Quote Link to comment https://forums.phpfreaks.com/topic/266338-php-navigation-list-issue/#findComment-1364889 Share on other sites More sharing options...
lpmraven Posted July 27, 2012 Author Share Posted July 27, 2012 Ive entered into the autoload.php $autoload['helpers'] = array('squad_helper'); still getting that error, Message: Undefined variable: squad_menu Quote Link to comment https://forums.phpfreaks.com/topic/266338-php-navigation-list-issue/#findComment-1364893 Share on other sites More sharing options...
scootstah Posted July 27, 2012 Share Posted July 27, 2012 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? No, then you are repeating a ton of code. wiredesignz' widget plugin might be a good solution here. Quote Link to comment https://forums.phpfreaks.com/topic/266338-php-navigation-list-issue/#findComment-1364895 Share on other sites More sharing options...
Mahngiel Posted July 27, 2012 Share Posted July 27, 2012 $squads_menu is not a variable (my bad, fingers typed too fast). it's a helper function, it works like echo squads_menu(). Also, remove the reference to $squads $this->data->squads =& $squads Quote Link to comment https://forums.phpfreaks.com/topic/266338-php-navigation-list-issue/#findComment-1364896 Share on other sites More sharing options...
Mahngiel Posted July 27, 2012 Share Posted July 27, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/266338-php-navigation-list-issue/#findComment-1364899 Share on other sites More sharing options...
lpmraven Posted July 27, 2012 Author Share Posted July 27, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/266338-php-navigation-list-issue/#findComment-1364900 Share on other sites More sharing options...
Mahngiel Posted July 27, 2012 Share Posted July 27, 2012 $squads_menu is not a variable (my bad, fingers typed too fast). it's a helper function, it works like echo squads_menu(). Quote Link to comment https://forums.phpfreaks.com/topic/266338-php-navigation-list-issue/#findComment-1364904 Share on other sites More sharing options...
lpmraven Posted July 27, 2012 Author Share Posted July 27, 2012 $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? Quote Link to comment https://forums.phpfreaks.com/topic/266338-php-navigation-list-issue/#findComment-1364905 Share on other sites More sharing options...
Mahngiel Posted July 27, 2012 Share Posted July 27, 2012 If that's where you want it -- in the header. My skype is available on the xcel forums, you can tag me over there if you need help. Quote Link to comment https://forums.phpfreaks.com/topic/266338-php-navigation-list-issue/#findComment-1364906 Share on other sites More sharing options...
lpmraven Posted July 27, 2012 Author Share Posted July 27, 2012 Xcel is currently down for me, I've PMed you. Quote Link to comment https://forums.phpfreaks.com/topic/266338-php-navigation-list-issue/#findComment-1364908 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.