Changeset 2594 for trunk/application

Show
Ignore:
Timestamp:
04/28/2008 03:14:09 PM (7 months ago)
Author:
Geert
Message:

Follow-up to r2593. Fixing stuff. Everybody mind your CodingStyle please, I don't like to do systemwide search and replace commits.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/application/controllers/welcome.php

    r2593 r2594  
    1313        // Disable this controller when Kohana is set to production mode. 
    1414        // See http://doc.kohanaphp.com/installation/deployment for more details. 
    15         // const ALLOW_PRODUCTION = FALSE; 
     15        const ALLOW_PRODUCTION = FALSE; 
    1616 
    17         public function __construct() 
     17        public function index() 
    1818        { 
    19                 parent::__construct(); 
    20                 new Profiler; 
    21 /* 
    22                 $pdo = pdomo::registry('default', new PDO(Config::item('pdodb'))); 
    23                 echo Kohana::debug($pdo); 
     19                // In Kohana, all views are loaded and treated as objects. 
     20                $welcome = new View('welcome'); 
    2421 
    25                 $query = $pdo->prepare('SELECT * FROM :table'); 
    26                 $query->bindValue(':table', 'users'); 
    27                 $query->setFetchMode(PDO::FETCH_NUM); 
    28                 $x = $query->fetch(PDO::FETCH_OBJ); 
     22                // You can assign anything variable to a view by using standard OOP 
     23                // methods. In my welcome view, the $title variable will be assigned 
     24                // the value I give it here. 
     25                $welcome->title = 'Welcome to Kohana!'; 
    2926 
    30                 echo Kohana::debug($x); 
     27                // An array of links to display. Assiging variables to views is completely 
     28                // asyncronous. Variables can be set in any order, and can be any type 
     29                // of data, including objects. 
     30                $welcome->links = array 
     31                ( 
     32                        'Home Page'     => 'http://kohanaphp.com/', 
     33                        'Documentation' => 'http://doc.kohanaphp.com/', 
     34                        'Forum'         => 'http://forum.kohanaphp.com/', 
     35                        'License'       => 'Kohana License.html', 
     36                        'Donate'        => 'http://kohanaphp.com/donate.html', 
     37                ); 
    3138 
    32                 foreach ($query as $row) 
    33                 { 
    34                         echo $row[0], ', ', $row[1], '<br />'; 
    35                 } 
    36 */ 
     39                // Using views inside of views is completely transparent. In the welcome 
     40                // view, printing the $content variable will render the welcome_content view. 
     41                $welcome->content = new View('welcome_content'); 
     42 
     43                // Using render(TRUE) forces the view to display now, instead of 
     44                // returning an HTML string. 
     45                $welcome->render(TRUE); 
    3746        } 
    3847 
    3948        public function _default() 
    4049        { 
    41                 echo html::email('geertdd@gmail.com'); 
    42                 echo html::mailto('geert@link.com'); 
     50                // By defining a method called _default, all pages routed to this controller 
     51                // that result in 404 errors will be handled by this method, instead of 
     52                // being displayed as "Page Not Found" errors. 
     53                echo 'This is a _default handler. If you expected the index page, you need to use: welcome/index/'.substr(Router::$current_uri, 8); 
    4354        } 
    4455 
    45         public function pdo() 
    46         { 
    47                 $dbh = new PDO('mysql:host=localhost;dbname=kohana', 'root', 'html123'); 
    48 /* 
    49                 echo Kohana::debug($dbh); 
    50  
    51                 $query = $dbh->query('SELECT * FROM users LIMIT 3'); 
    52                 $query = $dbh->query('SELECT COUNT(*) FROM users ORDER BY id DESC LIMIT 3'); 
    53                 echo Kohana::debug($query); 
    54                 echo Kohana::debug($query->queryString); 
    55                 // $query = $query->fetchAll(PDO::FETCH_OBJ); 
    56                 echo Kohana::debug($query); 
    57                 foreach ($query as $row) 
    58                 { 
    59                         echo Kohana::debug($row); 
    60                 } 
    61  
    62                 $query = $dbh->exec('DELETE FROM users WHERE id = 2'); 
    63                 echo Kohana::debug($query); 
    64  
    65                 $query = $dbh->prepare('INSERT INTO users (email, username) VALUES (?, ?)'); 
    66                 $query->bindParam(1, $email); 
    67                 $query->bindParam(2, $username); 
    68                 $email = 'joske3@host.com'; 
    69                 $username = 'josse3'; 
    70                 $execute = $query->execute(array($email, $username)); 
    71                 echo Kohana::debug($execute); 
    72  
    73                 $id = $dbh->lastInsertId(); 
    74                 echo Kohana::debug($id); 
    75 */ 
    76                 $query = $dbh->prepare('SELECT ? FROM users WHERE id = ?'); 
    77                 echo Kohana::debug($query); 
    78                 $query->bindValue(1, 'username'); 
    79                 $query->bindValue(2, 3); 
    80                  
    81                 $query->execute(); 
    82                 $result = $query->fetchAll(PDO::FETCH_OBJ); 
    83                 echo Kohana::debug($result); 
    84                 foreach ($result as $row) 
    85                 { 
    86                         echo $row->username; 
    87                 } 
    88                 echo Kohana::debug($query->rowCount()); 
    89         } 
    9056}