How to call codeigniter controller function from view

后端 未结 14 1784
小蘑菇
小蘑菇 2020-11-27 05:53

How to call codeigniter controller function from view? When i call the function in a controller, get a 404 page.

14条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 06:52

    One idea i can give is,

    Call that function in controller itself and return value to view file. Like,

    class Business extends CI_Controller {
        public function index() {
                $data['css'] = 'profile';
    
                $data['cur_url'] = $this->getCurrURL(); // the function called and store val
                $this->load->view("home_view",$data);
         }
         function getCurrURL() {
                    $currURL='http://'.$_SERVER['HTTP_HOST'].'/'.ltrim($_SERVER['REQUEST_URI'],'/').'';
                return $currURL;
         }
    
    }
    

    in view(home_view.php) use that variable. Like,

    echo $cur_url;
    

提交回复
热议问题