Welcome Guest, Not a member yet? Register   Sign In
Invalid Argument Supplied for Foreach()
#1

[eluser]xtremer360[/eluser]
I'm using the HMVC module separator plugin by wiredesignz and wanted to know why i keep getting an invalid argument supplied in my controller.

Controller Dashboard (found in normal controllers folder inside of application)

Code:
$categoriesDB = $this->news->getNewsCategories($this->data['userData']->usersRolesID);
print_r($categoriesDB);
$categories = array();
foreach ($categoriesDB AS $category)
{
    $category[$category->id] = $category->categoryName;
}
$this->data['categories'] = $categories;

News library (found in application/modules/news/libraries/news.php)
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
* News Library
*
* News Library for Code Igniter
*
* @package KOW Manager
* @author Jeffrey Davidson
* @version 1.0.0
* @copyright 2012
*/

class News
{
            
    function __construct()
    {
        //assign the CI superglobal to $CI
        $this->ci =& get_instance();
        $this->ci->load->model('news/news');            
    }
    
    /**
     * Get roster list
     *
     * @param integer
     * @return object/NULL
     */
    function getNewsCategories($usersRolesID)
    {
        // Check args
        if(!is_numeric($usersRolesID)) { throw new Exception('Non-numeric $usersRolesID provided to getNewsCategories()'); }
        
        if (($usersRolesID == 3) || ($usersRolesID == 4) || ($usersRolesID == 5))
        {
            return $this->ci->news->getNewsCategories(2);
        }
        else
        {
            return $this->ci->news->getNewsCategories(1);
        }
    }
    
}

News Model (found in application/modules/news/models/news.php)
Code:
<?php

if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
* News
*
* This model represents user authentication data.
*
* @package KOW Manager
* @author Jeffrey Davidson
* @version 1.0.0
* @copyright 2012
*/

class News extends CI_Model
{
    function __construct()
    {
        parent::__construct();
    }
    
    /**
     * Get list of categories
     *
     * @param   integer
     * @return object/NULL
     */
    function getNewsCategories($permissionID)
    {
        // Check args
        if (!is_numeric($permissionID)) { throw new Exception('Non-numeric $permissionID provided to getNewsCategories()'); }
        
        $this->db->select('id');
        $this->db->select('categoryName');
        $this->db->from('siteNewsCategories');
        $this->db->where('newsPermissionsID', $permissionID);
        $this->db->order_by('categoryName');
        $query = $this->db->get();
        if ($query->num_rows() > 0)
        {
            return $query->result();
        }
        return null;
    }
}
#2

[eluser]zoopstud[/eluser]
Code:
$category[$category->id] = $category->categoryName

should be

Code:
$categories[$category->id] = $category->categoryName

#3

[eluser]xtremer360[/eluser]
Tried that and I am now getting this error.

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 1048576 bytes) in /home/xtremer/public_html/kowmanager/application/third_party/MX/Loader.php on line 206
#4

[eluser]CroNiX[/eluser]
Whatever you are doing requires more than 32 megs of RAM. You either need to find a more efficient way to do it or increase the ram for your server.




Theme © iAndrew 2016 - Forum software by © MyBB