CodeIgniter - Calling a function from inside a view

后端 未结 7 1483
长情又很酷
长情又很酷 2021-01-06 13:25

Is it possible to call a function which is located in a controller from a view?

This is what i have in my controller, as an example

function checkKey         


        
7条回答
  •  情话喂你
    2021-01-06 14:07

    Like Widox said, I think a Helper is the best way out. Something like this:

    db->query("SELECT $keyFROM $table WHERE id = $userid LIMIT 1");
        if($query->num_rows() > 0)
        {
            return true;
        }else
        {
            return false; 
        }
    }
    
    ?>
    

    Then you can freely use on your views, just loading in your respective controllers like: $this->load->helper('test');.

提交回复
热议问题