Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 407577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:36:30+00:00 2026-05-12T17:36:30+00:00

I have the following db and php. I am trying to make a unordered

  • 0

I have the following db and php. I am trying to make a unordered list of category menu.
The original php is working by itself.
I am trying to convert this to MVC in codeigniter and the following is what I got so far and not working.
If someone can point out what I am doing wrong, I will appreciate it.

Database

CREATE TABLE IF NOT EXISTS `categories` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(255) NOT NULL,
  `shortdesc` varchar(255) NOT NULL,
  `longdesc` text NOT NULL,
  `status` enum('active','inactive') NOT NULL,
  `parentid` int(11) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;

-- 
-- Dumping data for table `categories`
-- 

INSERT INTO `categories` (`id`, `name`, `shortdesc`, `longdesc`, `status`, `parentid`) VALUES (1, 'shoes', 'Shoes for boys and girls.', '', 'active', 7);
INSERT INTO `categories` (`id`, `name`, `shortdesc`, `longdesc`, `status`, `parentid`) VALUES (2, 'shirts', 'Shirts and blouses!', '', 'active', 7);
...
...

menu.php (original php and working)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title>View Tasks</title>
</head>
<body>
<h3>Menu</h3>
<?php 
function make_list ($parent) {

    global $data;
    echo '<ul>';

    foreach ($parent as $task_id => $todo) {

        echo "<li>$todo";

        if (isset($data[$task_id])) { 

            make_list($data[$task_id]);
        }

        echo '</li>';

    }
    echo '</ul>';

} 

$dbc = @mysqli_connect ('localhost', 'root1', 'root', 'ci_day6') OR die ('<p>Could not connect to the database!</p></body></html>');

$q = 'SELECT id, parentid, name FROM categories ORDER BY parentid ASC'; 
$r = mysqli_query($dbc, $q);

$data = array();

while (list($id, $parentid, $name) = mysqli_fetch_array($r, MYSQLI_NUM)) {

    $data[$parentid][$id] =  $name;

}

make_list($data[0]);

?>

</body>
</html>

This php output the following html

Menu

    * clothes
          o shoes
          o shirts
          o pants
          o dresses
    * fun
          o toys
          o games

My MVC so far and not working.

cat_menu_model.php(model)

<?php

class Cat_menu_model extends Model
{
         function Cat_menu_model()
        {
            parent::Model();

        }

        function get_categories_nav()
        {

            $data = array();
            $this->db->select('id,name,parentid');
            $this->db->where('status', 'active');
            $this->db->orderby('parentid','asc');
            $this->db->orderby('name','asc');

            $Q = $this->db->get('categories');
        if ($Q -> num_rows() > 0){
          foreach ($Q -> result_array() as $row){
          $data[$row['parentid']][$row['id']] = $row['name'];
          }
          }

           $Q->free_result(); 
           return $data; 

        }
}

cat_menu.php (controller)

<?php

class Cat_menu extends Controller
{

    function Cat_menu()
    {
        parent::Controller();
    }
    function make_menu($parent)
    {
        $this->load->model('cat_menu_model');

        $data['navlist'] = $this->cat_menu_model->get_categories_nav();
            $this -> load ->view('menu');
    }
}

menu.php(view)

<?php
if (count($navlist))
{
  $this->make_menu($data[0]);
  echo '<ol>';
    foreach ($parent as $id => $catname) {

        echo "<li>$catname";

        if (isset($data[$id])) { 

        make_menu($data[$id]);

        }

        echo '</li>';

    } 
 echo '</ol>';
}
?>

It shows an error messages.

A PHP Error was encountered

Severity: Warning

Message: Missing argument 1 for Cat_menu::make_menu()

Filename: controllers/cat_menu.php

Line Number: 10
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:36:30+00:00Added an answer on May 12, 2026 at 5:36 pm

    Given the PHP error message above, it’s saying that you’ve told the method Cat_menu::make_menu() to accept an argument. In this case the function make_menu($parent) in the Cat_menu controller.

    If this function does not require any input — doesn’t look like $parent is used — then just remove the $parent argument from make_menu.

    Alternatively, set a default value if you would like the function to accept no arguments. See below:

    cat_menu.php (Controller)

    <?php
    
    class Cat_menu extends Controller
    {
    
        function Cat_menu()
        {
            parent::Controller();
        }
    
        function make_menu($parent = FALSE) //Is this $parent argument needed?
        {
            $this->load->model('cat_menu_model');
    
            $data['navlist'] = $this->cat_menu_model->get_categories_nav();
    
            //If you want to parse data to a view you need to state it
            $this->load->view('menu', $data);
        }
    }
    

    Assuming the rest of your code is correct, this should now work. Please see the CodeIgniter User Guide for reference from now on. Specifically the views documentation on parsing values across.


    OP* has since responded in the comments below, this is my response.

    **OP = Original Poster*

    When running print_r($navlist) in the view. The OP gets the following output:

    Array ( 
        [0] => Array ( 
            [7] => clothes 
            [8] => fun 
        ) 
        [7] => Array ( 
            [3] => pants 
            [2] => shirts 
            [1] => shoes 
        ) 
        [8] => Array ( 
            [6] => games 
            [5] => toys 
        )
    )
    

    However, it is worth noting that the OP’s CI model ActiveRecord query is significantly different than the original — non MVC — query:

    SELECT 
        id, 
        parentid, 
        name 
    FROM 
        categories 
    ORDER BY 
        parentid ASC
    

    vs.

    $this->db->select('id,name,parentid');
    $this->db->where('status', 'active');
    $this->db->orderby('parentid','asc');
    $this->db->orderby('name','asc');
    $Q = $this->db->get('categories');
    

    The CI model query is different than the original SQL to begin with. When converted into SQL it would produce the following:

    SELECT
        id, 
        name,
        parentid
    FROM
        categories
    WHERE
        status = 'active'
    ORDER BY
        parentid ASC,
        name ASC
    

    However, it seems that this is the correct data being brought back so I’ll continue on.

    The OP would like the array formatted like a heirarchy. For future reference, please see: PHP/MySQL – building a nav menu hierarchy. The easiest way to do this, would be to follow the OP’s original (non MVC) function and add it as a model function. This model function would create a nested array, rather than the direct html output — the reason for this is to separate application logic from output.

    You can add the following to your model as a function. Originally taken from Nested sets, php array and transformation but since re-written due to errors appearing for OP:

    function to_hierarchy($collection = NULL)
    {
        if (is_null($collection)) return false;
    
        $tree = array();
    
        foreach($collection[0] as $key => $value)
        {
            $tree[$value] = array();
    
            foreach($collection[$key] as $item)
            {
                array_push($tree[$value], $item);
            }
        }
    
        return $tree;
    }
    

    Now we can update our controller to be the following:

    cat_menu.php (Controller)

    <?php
    
    class Cat_menu extends Controller
    {
    
        function Cat_menu()
        {
            parent::Controller();
        }
    
        function make_menu($parent = FALSE) //Is this $parent argument needed?
        {
            $this->load->model('cat_menu_model');
    
            $get_nav_list = $this->cat_menu_model->get_categories_nav();
    
            $format_nav_list = $this->cat_menu_model->to_hierarchy($get_nav_list);
    
            //Load the HTML helper for ul/ol conversion
            $this->load->helper('html');
    
            $data['navlist'] = $format_nav_list;
    
            //If you want to parse data to a view you need to state it
            $this->load->view('menu', $data);
        }
    }
    

    Now we can update our view to be the following:

    menu.php (View)

    <?php
        echo ul($navlist);
    ?>
    

    Disclaimer: None of the above has been tested using PHP as I currently don’t have access to the interpreter from this computer. Please make sure you check over any syntax.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following php code which I found here : function download_xml() {
I have been trying to output XML with PHP but encountered a strange(!) error
I'm trying to make a very basic php ORM as for a school project.
I am currently using PHP/MySQL, and I'd like to know the best way make
I am trying to make a soap call. It's a very basic call with
I am trying to make a function to pull a page's content from a
I'm trying to make git ignore some of my files and I found one
I have the following MySQL table structure: num field company phone website 1 Gas
I'm not very familiar with regEx's and I'm trying to find a preg_match regex

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.