Welcome Guest, Not a member yet? Register   Sign In
my own helper creating menu
#9

[eluser]Lorin[/eluser]
For example I made simple script to create menu from database:

model:
Code:
<?php
    class Test_model extends CI_Model {

        function __construct() {
            parent::__construct();
        }

        function display_menu() {

            $this->load->database();

            $query = $this->db->get('users');
            return $query->result();
        }

    }
?>

controller:
Code:
<?php
    class Test extends CI_Controller {

        function __construct(){
            parent::__construct();
        }

        public function index() {

            $this->load->model('test_model','menu');

            $data['title'] = 'Elcometer';
            $data['menu'] = $this->menu->display_menu();

            $this->load->view('test_view', $data);
        }

    }
?>

and view:
Code:
<html>
    <head>
        <title><?php echo $title; ?></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <h1>&lt;?php echo $title; ?&gt;</h1>
        <ul>
            &lt;?php foreach($menu as $menus) { ?&gt;
                <li> &lt;?php echo $menus->nick; ?&gt; </li>
            &lt;?php } ?&gt;
        </ul>
    &lt;/body&gt;
&lt;/html&gt;

I know, it is really simple.

Note: It's using my 'user' table, because I'm too lazy to create another table for testing.


Messages In This Thread
my own helper creating menu - by El Forum - 08-13-2011, 07:05 AM
my own helper creating menu - by El Forum - 08-13-2011, 10:37 AM
my own helper creating menu - by El Forum - 08-13-2011, 11:25 AM
my own helper creating menu - by El Forum - 08-13-2011, 12:04 PM
my own helper creating menu - by El Forum - 08-13-2011, 12:10 PM
my own helper creating menu - by El Forum - 08-13-2011, 12:14 PM
my own helper creating menu - by El Forum - 08-13-2011, 12:23 PM
my own helper creating menu - by El Forum - 08-13-2011, 12:42 PM
my own helper creating menu - by El Forum - 08-13-2011, 12:51 PM
my own helper creating menu - by El Forum - 08-13-2011, 01:17 PM
my own helper creating menu - by El Forum - 08-13-2011, 01:33 PM
my own helper creating menu - by El Forum - 08-13-2011, 07:06 PM
my own helper creating menu - by El Forum - 08-14-2011, 02:31 AM
my own helper creating menu - by El Forum - 08-14-2011, 04:04 AM
my own helper creating menu - by El Forum - 08-14-2011, 05:53 AM
my own helper creating menu - by El Forum - 08-14-2011, 06:28 AM
my own helper creating menu - by El Forum - 08-15-2011, 07:11 AM
my own helper creating menu - by El Forum - 08-15-2011, 07:34 AM
my own helper creating menu - by El Forum - 08-15-2011, 07:37 AM



Theme © iAndrew 2016 - Forum software by © MyBB