0

I am using Symfony 1.4 and already created schema.yml, 3 of them, and created the database.yml with multiple connection.

And executed the build --model of symfony and created classes one of them is "Schedule" which came from the schema having columns: id, name, description....

How do use that class to use its method or function, the setter and getters? Books says that there are setters and getter if a model was generated.

How do I retrieve data with filters?

4

1 回答 1

1

你的问题有点含糊。但是从您的模型中,您可以执行以下操作:

创建条目:

$schedule = new Schedule();
$schedule->setName('foo');
$schedule->setDescription('bar');
$schedule->save();

查找所有条目

$schedules = Doctrine_Core::getTable('Schedule')->findAll();

检索一项(如果我们假设Schedule存在 id 为 1 的一项)

$schedule = Doctrine_Core::getTable('Schedule')->find(1);
$schedule = Doctrine_Core::getTable('Schedule')->findOneByName('foo');

访问模型内​​的字段

$name        = $schedule->getName();
$description = $schedule->getDescription();

编辑:

自定义吸气剂,在ScheduleTable.class.php

public function findByStatusAndRangeTime($status, $start, $end)
{
  $q = $this->createQuery('s');
  $q->where('s.status = ? AND s.time_start < ? AND s.time_end > ?', array($status, $start, $end));

  return $q->execute();
}

然后,您可以使用以下方法调用它:

$schedule = Doctrine_Core::getTable('Schedule')->findByStatusAndRangeTime('pending', '1:00', '5:00');
于 2012-10-17T08:10:18.443 回答