Welcome Guest, Not a member yet? Register   Sign In
Confusion with MVC in CI
#11

[eluser]mddd[/eluser]
You can't name a controller function 'view' if you are using PHP4. Check the manual page on reserved names.
#12

[eluser]ChaosKnight[/eluser]
Thanks, I missed that part
#13

[eluser]ChaosKnight[/eluser]
It still happened after I changed the function to display()...
And I still couldn't figure out why the database result threw away the country element of the array... Can someone see why?

Edit: fixed the function part, now it's only the database object...
#14

[eluser]ChaosKnight[/eluser]
Solved
#15

[eluser]evstevemd[/eluser]
How did you solve it?
#16

[eluser]ChaosKnight[/eluser]
Changed my code to this...
Model:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Countries_model extends Model
{
    function Countries_model()
    {
        parent::Model();
        $this->load->database();
    }
    function getCountries()
    {
        $this->db->select('id, country');
        $query = $this->db->get('countries');
        return $query;
    }
}
/* End */

Controller:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Countries extends Controller
{
    function Countries()
    {
        parent::Controller();
        $this->load->helper(array('html','url'));
        $this->load->model('countries_model');
    }
    function index()
    {
        $data['page_title'] = 'Countries';
        $query = $this->countries_model->getCountries();
        foreach ($query->result() as $row)
        {
            $data['countries'][] = $row->country;
            $data['ids'][] = $row->id;
        }

        $this->load->view('header',$data);
        $this->load->view('nav');
        $this->load->view('sidebar');
        $this->load->view('countries',$data);
        $this->load->view('footer');
    }
}
/* End */

Don't know how efficient it is, there may be better suggestions, but it got the page working for me :-)

The view is basic:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?>

<div id="content">
  &lt;?php
    $i = -1;
    foreach ($countries as $country)
    {
      $i++;
      echo anchor('countries/'.$ids[$i],$country);
      echo "<br />";
    }
  ?&gt;
</div>

&lt;?php
/* End of Countries.php view */




Theme © iAndrew 2016 - Forum software by © MyBB