Help! Call to a member function on a non-object in ....

Ok,so I am getting this error
"Fatal error: Call to a member function on a non-object in /home/domain/public_html/****/application/views/areacode_view.php on line 49"

My controller looks like this:
class PhoneNumbers extends Controller {

    function PhoneNumbers()
        function areacode(){
function _formatNumber($format,$areacode,$number){
        if($format ==1){
            return "(".$areacode.") ".substr($number,0,3)."-".substr($number,3,4);
        }else if($format == 2){
            return $areacode."-".substr($number,0,3)."-".substr($number,3,4);
            return $areacode.$number;

My Model is
class AreaCode_model extends Model {

    function AreaCode_model()

function get_All_Numbers()
    if ($this->uri->segment(1) === FALSE)
        $areacode = "000";
            $areacode = substr($this->uri->segment(1),10,3);
        $sql = "Select * from PhoneNumbers where areaCode=?";
        $query = $this->db->query($sql,$areacode);
        return $query->result();
And finally my areacode_view is
<?php foreach($query->result() as $row): ?>

<h3>&lt;?php echo $this->_formatNumber(1,$row->areaCode, $row->phone); ?&gt;</h3>
<p>&lt;?php echo anchor('../phonenumbers/numberpage/'.$this->_formatNumber(2,$row->areaCode, $row->phone),'Phone Number '.$this->_formatNumber(3,$row->areaCode, $row->phone)); ?&gt;</p>
&lt;?php endforeach; ?&gt;</ol>

OK so I don't understand why I am getting this error?
Can anyone see whats going on here?
uri->segment(1) would return area-code-555
so I extract the 555 out of it.


[eluser]Rick Jolly[/eluser]
Instead of calling a private method in your controller from your view:

1) create a helper with that function
2) load the helper in the controller
3) call the helper function in your view.

Helpers are meant for this sort of thing - formatting data in the view. Also, it allows you to reuse that formatting code in various controllers/views.

thanks, I will look into helpers.
I found the problem.
In my view page i had $query->result()
and there was already a "result()" in my model. I removed that and it worked!

ps, I am loving this framework! its so easy

[eluser]RaZoR LeGaCy[/eluser]
I just upgraded my codeignitor from 1.6.1 to 1.6.2 and I am now recieving this message everywhere

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.