CI framework adds Dynamic Data to the view _ php instance

Source: Internet
Author: User
This article describes how to add dynamic data to a view by using the CI framework. For more information about how to import data to a view by using an array or object, this array or object acts as the second parameter of the view loading function. If you use an object, the class variable is converted to an array element. Okay. Let's try it with your controller. Open the controller and add the following code

<? Php class Blog extends CI_Controller {

Function index ()
{
$ Data ['title'] = "My Real title ";
$ Data ['heading'] = "My Real heading ";

$ This-> load-> view ('blogview', $ data );
}
}
?>

Open your view file and Replace the text with the variable corresponding to the array. Note that $ key is directly used when the foreground page value is used instead of $ data.

 

<? Php echo $ title;?>


<? Php echo $ heading;?>

Summary: when the class variable $ data is passed, it is converted to an array element.


The method is very simple. You can join your project to make the best of your friends.

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.