Working with objects - Component overview - Table - Custom finders.php 636 Bytes
Newer Older
doctrine's avatar
doctrine committed
1 2 3 4 5 6
<?php
class UserTable extends Doctrine_Table {
    /**
     * you can add your own finder methods here
     */
    public function findByName($name) {
7
        return $this->getConnection()->query("FROM User WHERE name LIKE '%$name%'");
doctrine's avatar
doctrine committed
8 9 10 11
    }
}
class User extends Doctrine_Record { }

12 13
$conn = Doctrine_Manager::getInstance()
           ->openConnection(new PDO("dsn","username","password"));
doctrine's avatar
doctrine committed
14

15 16
// doctrine will now check if a class called UserTable exists 
// and if it inherits Doctrine_Table
doctrine's avatar
doctrine committed
17

18
$table   = $conn->getTable("User");
doctrine's avatar
doctrine committed
19 20 21 22 23 24

print get_class($table); // UserTable

$users   = $table->findByName("Jack");

?>