开发者

php bind data explanation (possibly kohana specific?)

开发者 https://www.devze.com 2023-01-18 16:27 出处:网络
Attempting to dive in to Kohana and I\'m reading the Unofficial 3.0 Kohana wiki as it\'s more user friendly than the user docs atm imo.

Attempting to dive in to Kohana and I'm reading the Unofficial 3.0 Kohana wiki as it's more user friendly than the user docs atm imo.

It mentions "Binding Data to a View", like so:

<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Welcome extends Controller {

    public function action_index()
    {
        $about_page = View::factory('pages/about')
                            ->bind('title', $title)
                            ->bind('header', $header);

        $title='This is my title';
        $title='This is my header';
        $this->request->response = $about_page;
    }

} // End Welcome

Which outputs:

<html>
<head> 
<title>This is my title</title> 
</head> 
<body> 
<h1>This is my header</h1> 
</body> 
</html>

How is this possible? Or what's this method/开发者_Go百科process called? The variables are set after they are "used", if you like, hence my confusion.

Thanks for any insight.


It's called passing by reference. See more at http://www.php.net/manual/en/language.references.pass.php.


I came across this when doing research on kohana framework.

Check this link, shadowhand puts it in very basic terms: http://forum.kohanaframework.org/discussion/5038/views-difference-between-assign-bind-and-set/p1

This answer wasn't to help original person, it was to save someone time if they're getting stuck ;)

0

精彩评论

暂无评论...
验证码 换一张
取 消