Welcome Guest, Not a member yet? Register   Sign In
OMG Noob stuck again!!!
#1

[eluser]JimmyJ[/eluser]
Ok, I've created a browse page that im looking to display database info passed from the id in the url.

The url looks like: http://localhost/index.php/browse/2

My browse.php controller looks like this:

Code:
<?php

class Browse extends Controller {
        
    
    function index()
    {        
        
        parent::Controller();
    }
    
    
    function browse()
    {        
        
        //parent::Controller();    
        //$this->db->where('region_id', $this->uri->segment(2));
        //$data['query'] = $this->db->get('counties');
        
        //$data['title'] = "My Title";
        $this->load->view('browse_props');
        
        echo 'hello';
    }
    
}
?>

This gives me the following error:

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Browse::$load

Filename: controllers/browse.php

Line Number: 21

Fatal error: Call to a member function view() on a non-object in E:\wamp\www\system\application\controllers\browse.php on line 21

I have my browse_props.php in the views folder.

If I edit the code above and hide the load->view, it will echo "hello" but with a 404 message below?

Anyone know what i'm doing wrong? Am I a total noob?
#2

[eluser]tonanbarbarian[/eluser]
Code:
function index()
    {        
        
        parent::Controller();
    }


should be

Code:
function Browse()
    {        
        
        parent::Controller();
    }

the problem is that the load property of the controller does not exist because it has not be instantiated correctly
Once the parent:Controller is called correctly it will make the loader and other default objects available.
#3

[eluser]JimmyJ[/eluser]
Ok, that seemed to work a little:

It's now echoing the hello message, but i still get a 404 below the hello. Weird??

My code now looks like this

Code:
<?php

class Browse extends Controller {
        

    function browse()
    {        
        
        parent::Controller();    
        //$this->db->where('region_id', $this->uri->segment(2));
        //$data['query'] = $this->db->get('counties');
        
        //$data['title'] = "My Title";
        $this->load->view('browse_props');
        
        echo 'hello';
    }
    
}
?>
#4

[eluser]rvent[/eluser]
you need to have the constructor and then the function index
Code:
class Myclass extends Controller
{
       function Myclass()
       {
             parent::Controller();
       }

       function index()
       {
              .... code here .....
       }
}
#5

[eluser]JimmyJ[/eluser]
Think i got it with:

Code:
<?php

class Browse extends Controller {
            
    
    function browse()
    {        
        
        parent::Controller();    
        
    }
    
    
    function index()
    {        
            
        $data['title'] = "Browse Index";
        $this->load->view('browse_props');

        
    }
    
    function property()
    {        
            
        $region_id = $this->uri->segment(3);
        $query = $this->db->query("SELECT * FROM regions WHERE region_id=$region_id");
        
        foreach ($query->result() as $row) {
        
        $data['title'] = 'Property for sale in ' . $row->region_name;
        
        }
        
        $this->load->view('browse_props', $data);
        
    }
    
}
?>

by passing the url: http://localhost/index.php/browse/proper...tland.html
#6

[eluser]rvent[/eluser]
function Browse
not
function browse
#7

[eluser]JimmyJ[/eluser]
Yeh fixed that, now onto:

Code:
<?php

class Browse extends Controller {
            
    
    function Browse()
    {        
        
        parent::Controller();    
        
    }
    
    
    function index()
    {        
            
        $this->load->view('emptyresult');

        
    }
    
    function property()
    {        
                    
        $region_id = $this->uri->segment(3);
        $sql = "SELECT counties.county_id, counties.region_id, counties.county_name, regions.region_id, regions.region_name FROM counties LEFT JOIN regions ON counties.region_id = regions.region_id WHERE counties.region_id=$region_id";
        $query = $this->db->query($sql);
        
         if ($query->num_rows() > 0) {

        // I NEED THIS TITLE TO BE A STATIC NAME FROM THE QUERY ABOVE???
        $data['title'] = 'Property for sale in...';
        
                    foreach ($query->result() as $county) {
                    
                    $county_name = strtolower($county->county_name);
                    $data['links'][] = anchor(base_url().'/browse/property/' . $county->region_id . '/county/'.$county->county_id.'/property-in-'.url_title($county_name, 'dash'),$county->county_name);
        
                        
                    }
                
                $this->load->view('browse_props', $data);
                
            }
            else {
            
                $this->load->view('emptyresult');
            
            }
        
        
        
    }
    
    function county()
    {        
                    
        $county_id = $this->uri->segment(5);
        echo 'info for region page...';
        
    }
    
}
?>

Now trying to figure out, how to pass the region.region_name as the page title outwith the foreach. Any clues????
#8

[eluser]Jon Parker[/eluser]
Its in the User Guide under the db class
Code:
$query = $this->db->query('SELECT name FROM my_table LIMIT 1');

$row = $query->row();
echo $row->name;
So...
Code:
$row = $query->row();  
$data['title'] = $row->region_name;
#9

[eluser]JimmyJ[/eluser]
Man it was late and my eyes were glazing over!!! Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB