티스토리 뷰

웹개발/Php

Kohana Request

yaku 2011. 8. 26. 05:53

1.  Request Routing
$page_name = Request::instance()->param('page');    
$this->request->response = View::factory('page/'.$page_name)
      ->bind('menu', $menu);
$menu = Request::factory('static/menu')->execute()->response;

view 안에서의 사용 

 execute()->response ?>


2. Route 의 흐름을 무시하도록 라우팅 <br /> 기본 controller/action/id <br /> 이라면 controller/action/id/and/anything/else/you/want/to/add/at/random 요렇게 하려면 Route::set('default', '(<controller>(/<action>(/<id>(/<stuff>))))', array('stuff' =&gt; '.*')) -&gt;defaults(array( 'controller' =&gt; 'welcome', 'action' =&gt; 'index', )); 요런식으로 라우팅 Set 해주면 됀다. 3. static 페이지 Routing Route::set('static', '<page>', array('page' =&gt; 'about|faq|locations')) -&gt;defaults(array( 'controller' =&gt; 'page', 'action' =&gt; 'static', )); * This route supports any number of pages. * Each page accessible the following URL where page_name is the * name of the page you want to load. * http://example.com/page/page_name */ Route::set('static2', 'page/<page>', array('page' =&gt; '.*')) -&gt;defaults(array( 'controller' =&gt; 'page', 'action' =&gt; 'static', )); 4. 다국어 Routing 설정 http://example.com/en-us/products // For English http://example.com/fr-fr/products // For French Route::set('default', '(<lang>/)(<controller>)(/<action>(/<id>))', array('lang' =&gt; '(en-us|fr-fr|nl-nl)', 'id'=&gt;'.+')) -&gt;defaults(array( 'lang' =&gt; 'en-us', 'controller' =&gt; 'welcome', 'action' =&gt; 'index', )); $this-&gt;template-&gt;title = __('Hello World'); // Load a language specific view $this-&gt;template-&gt;content = View::factory('page/'.I18n::$lang.'/index'); //OR use the same template for all languages //$this-&gt;template-&gt;content = View::factory('page/index'); 5. sub-directiones 설정 /home/kerkness/application/classes/controller/foo/bar.php url 호출 http://example.com/foo/bar/action/id 라우팅 Route::set('default', '(<directory>(/<controller>(/<action>(/<id>))))') -&gt;defaults(array( 'directory' =&gt; 'foo', 'controller' =&gt; 'bar', 'action' =&gt; 'index', )); 멀티 sub-direcories 설정 http://example.com/my/sub/directory/controller/action/id Route::set('default', '(<directory>(/<controller>(/<action>(/<id>))))', array('directory' =&gt; '.+?')) -&gt;defaults(array( 'directory' =&gt; 'foo', 'controller' =&gt; 'bar', 'action' =&gt; 'index', )); 6. redirect 의 사용 Request::instance()-&gt;redirect('http://kohanaphp.com'); Request::instance()-&gt;redirect('controller/action'); Request::instance()-&gt;redirect( Route::get('demo-sample')-&gt;uri(array('category'=&gt;'books', 'id'=&gt;5)) ); 7. 테스트 route // Here you define the routes // ... Route::set('post', 'post/<id>', array('id' =&gt; '[\d]+')) -&gt;defaults(array( 'controller' =&gt; 'post', 'action' =&gt; 'index', )); // ... // The URI to test $uri = 'post/1'; // This will loop trough all the defined routes and // tries to match them with the URI defined above foreach (Route::all() as $r) { echo Kohana::debug($r-&gt;matches($uri)); } array(3) ( "id" =&gt; string(1) "1" "controller" =&gt; string(4) "post" "action" =&gt; string(5) "index" ) array(2) ( "controller" =&gt; string(4) "post" "action" =&gt; string(1) "1" )

'웹개발 > Php' 카테고리의 다른 글

Kohana Validation 체크  (0) 2011.08.26
Kohana Query Builder  (0) 2011.08.26
Kohana 3.2 Config 얻기..  (0) 2011.08.24
Kohana 3.2 Custom Error Page 만들기.  (1) 2011.08.24
PHP 비트 연산자 사용.  (0) 2011.07.17
댓글
D-DAY
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/12   »
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
글 보관함