CI controller calls internal methods and loads corresponding templates. ci Controller

Source: Internet
Author: User
Tags php template

CI controller calls internal methods and loads corresponding templates. ci Controller

When I open the link: http: // localhost/3g/index/open/a/B? After from = timeline, determine whether the from in the link is equal to timeline. If it is equal to timeline, call the timeline method in the Controller and load the timeline. php template.

class Index extends CI_Controller {    function __construct() {        parent::__construct();    }    public function open($a=0,$b=0) {        if ($_GET['from'] == 'timeline') {            $this -> timeline($a);            die;        } else {            $data['b'] = $b;            $this -> load -> view('3g/index/open',$data);        }    }    public function timeline($a=0) {        $data['a'] = $a;        $this -> load -> view('3g/index/timeline',$data);    }}
The output page is blank and the timeline. php template is not loaded. The correct method is:

class Index extends CI_Controller {    function __construct() {        parent::__construct();    }    public function open($a=0,$b=0) {        if ($_GET['from'] == 'timeline') {            $this -> timeline($a);            die;        } else {            $data['b'] = $b;            $this -> load -> view('3g/index/open',$data);        }    }    public function timeline($a=0) {        $data['a'] = $a;        echo $this -> load -> view('3g/index/timeline',$data,true);die;    }}

Get View content

View function thirdOptionalParameters can change the function behavior, so that data is returned as a string instead of sent to the browser. This is useful if you want to use other methods to further process data. If the third parameter of view is set to true (Boolean), the function returns data. The default action of the view function is false, which sends data to the browser. If you want to return data, remember to assign it to a variable:

$string = $this->load->view('myfile', '', true);

Example: in some cases, you don't want to output the view directly, but just want to get the View content for future use. You can refer to the following code.

<? Phpclass Blog extends CI_Controller {function index () {$ data ['todo _ list'] = array ('clean house', 'Call Ms', 'Run errands '); $ data ['title'] = "My Real title"; $ data ['heading'] = "My Real heading "; $ buffer = $ this-> load-> view ('blogview', $ data, true) ;}}?>

The third parameter in the view method indicates that the view is not output, but the result is returned to a variable.




Php ci framework development. The content is not displayed when the template is called.

Right-click the source code to see if it is blank or what?
<? Php?> Go

Template reinforcement practices, pay attention to how it is done, not those solutions such as beam side template take Steel

Are you still in trouble? Simple and clear
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.