think\View::assign PHP Method

assign() public method

模板变量赋值
public assign ( mixed $name, mixed $value = '' )
$name mixed 变量名
$value mixed 变量值
    public function assign($name, $value = '')
    {
        if (is_array($name)) {
            $this->data = array_merge($this->data, $name);
        } else {
            $this->data[$name] = $value;
        }
        return $this;
    }

Usage Example

 /**
  * 随便看看
  */
 public function look()
 {
     $prefix = C('DB_PREFIX');
     $sql = "select * from {$prefix}forum_post where status=1 order by rand() LIMIT 0 , " . modC('FORM_POST_SHOW_NUM_PAGE', '10', 'Forum');
     $post = M('')->query($sql);
     $post = $this->forumPostModel->assignForumInfo($post);
     if (IS_POST) {
         $view = new View();
         $view->assign('posts', $post);
         $view->display(T('Forum@Index/_look'));
         exit;
     }
     $this->assign('tab', 'look');
     $this->assign('posts', $post);
     $this->display();
 }
All Usage Examples Of think\View::assign