Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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 <strong>make_menu($parent)</strong> in the <strong>Cat_menu</strong> controller.</p> <p>If this function does not require any input -- doesn't look like $parent is used -- then just remove the $parent argument from make_menu.</p> <p>Alternatively, set a default value if you would like the function to accept no arguments. See below:</p> <p><em>cat_menu.php (Controller)</em></p> <pre><code>&lt;?php class Cat_menu extends Controller { function Cat_menu() { parent::Controller(); } function make_menu($parent = FALSE) //Is this $parent argument needed? { $this-&gt;load-&gt;model('cat_menu_model'); $data['navlist'] = $this-&gt;cat_menu_model-&gt;get_categories_nav(); //If you want to parse data to a view you need to state it $this-&gt;load-&gt;view('menu', $data); } } </code></pre> <p>Assuming the rest of your code is correct, this should now work. Please see the <a href="http://codeigniter.com/user_guide/" rel="nofollow noreferrer">CodeIgniter User Guide</a> for reference from now on. Specifically the <a href="http://codeigniter.com/user_guide/general/views.html" rel="nofollow noreferrer">views documentation</a> on parsing values across.</p> <hr> <p><strong>OP* has since responded in the comments below, this is my response.</strong></p> <p>**OP = Original Poster*</p> <p>When running print_r($navlist) in the view. The OP gets the following output:</p> <pre><code>Array ( [0] =&gt; Array ( [7] =&gt; clothes [8] =&gt; fun ) [7] =&gt; Array ( [3] =&gt; pants [2] =&gt; shirts [1] =&gt; shoes ) [8] =&gt; Array ( [6] =&gt; games [5] =&gt; toys ) ) </code></pre> <p>However, it is worth noting that the OP's CI model ActiveRecord query is significantly different than the original -- non MVC -- query:</p> <pre><code>SELECT id, parentid, name FROM categories ORDER BY parentid ASC </code></pre> <p>vs.</p> <pre><code>$this-&gt;db-&gt;select('id,name,parentid'); $this-&gt;db-&gt;where('status', 'active'); $this-&gt;db-&gt;orderby('parentid','asc'); $this-&gt;db-&gt;orderby('name','asc'); $Q = $this-&gt;db-&gt;get('categories'); </code></pre> <p>The CI model query is different than the original SQL to begin with. When converted into SQL it would produce the following:</p> <pre><code>SELECT id, name, parentid FROM categories WHERE status = 'active' ORDER BY parentid ASC, name ASC </code></pre> <p>However, it seems that this is the correct data being brought back so I'll continue on.</p> <p>The OP would like the array formatted like a heirarchy. For future reference, please see: <a href="https://stackoverflow.com/questions/477793/php-mysql-building-a-nav-menu-hierarchy">PHP/MySQL - building a nav menu hierarchy</a>. 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.</p> <p>You can add the following to your model as a function. Originally taken from <a href="https://stackoverflow.com/questions/841014/nested-sets-php-array-and-transformation">Nested sets, php array and transformation</a> but since re-written due to errors appearing for OP:</p> <pre><code>function to_hierarchy($collection = NULL) { if (is_null($collection)) return false; $tree = array(); foreach($collection[0] as $key =&gt; $value) { $tree[$value] = array(); foreach($collection[$key] as $item) { array_push($tree[$value], $item); } } return $tree; } </code></pre> <p>Now we can update our controller to be the following:</p> <p><em>cat_menu.php (Controller)</em></p> <pre><code>&lt;?php class Cat_menu extends Controller { function Cat_menu() { parent::Controller(); } function make_menu($parent = FALSE) //Is this $parent argument needed? { $this-&gt;load-&gt;model('cat_menu_model'); $get_nav_list = $this-&gt;cat_menu_model-&gt;get_categories_nav(); $format_nav_list = $this-&gt;cat_menu_model-&gt;to_hierarchy($get_nav_list); //Load the HTML helper for ul/ol conversion $this-&gt;load-&gt;helper('html'); $data['navlist'] = $format_nav_list; //If you want to parse data to a view you need to state it $this-&gt;load-&gt;view('menu', $data); } } </code></pre> <p>Now we can update our view to be the following:</p> <p>menu.php (View)</p> <pre><code>&lt;?php echo ul($navlist); ?&gt; </code></pre> <p><strong><em>Disclaimer:</strong> 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.</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload