summaryrefslogtreecommitdiff
path: root/demos/quickstart/protected/controls/SearchBox.php
blob: b579cd9155cb164c7d04c9132921b1f4ab08de7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php

class SearchBox extends TTemplateControl 
{
	public function getText() 
	{
        $this->ensureChildControls();
        return $this->getRegisteredObject('search')->getText();
    }
    
    public function getTextBox()
    {
        $this->ensureChildControls();
        return $this->getRegisteredObject('search');
    }
	
	public function getButton()
	{
		$this->ensureChildControls();
        return $this->getRegisteredObject('find');
	}
	
	public function onInit($param)
	{
		parent::onInit($param);
		if(strlen($q = $this->Page->Request['q']) > 0)
			$this->search->setText($q);
	}

	public function doSearch($sender, $param)
	{
		if(strlen($query = $this->search->getText()) >0)
		{
			$ps = $this->getApplication()->getPageService();
			$page = $ps->constructUrl('Search', array('q' => $query));			
			$this->getApplication()->getResponse()->redirect($page);
		}
	}
}

?>