summaryrefslogtreecommitdiff
path: root/demos/quickstart/protected/controls/SearchBox.php
blob: e13d5e46b84683be7145bf6d7bfe67a0ffa3becf (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()->getService();
			$page = $ps->constructUrl('Search', array('q' => $query), false);
			$this->getApplication()->getResponse()->redirect($page);
		}
	}
}

?>