The symfony Cookbook

Hoe maak je een task?

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


About

You are currently reading "The symfony Cookbook" which is licensed under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License license.

Master symfony

Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).
trainings.sensiolabs.com

Books on symfony

Learn more about symfony with the official guides.
books.sensiolabs.com

L'audit Qualité par SensioLabs

200 points de contrôle de votre applicatif web.
audit.sensiolabs.com

Chapter Content

Laten we onze eerste task schrijven

Wat command line interactie

Een aantal andere handige functionaliteiten

symfony training
Be trained by symfony experts
May 29: Paris (Web Development with Symfony2 - Français)
May 31: Paris (Mastering Symfony2 - Français)
Jun 06: Paris (Introduction to Symfony2 - Français)
Jun 06: Paris (Introduction to Symfony2 - English)
Jun 06: Paris (Going Further with Symfony2 - English)
and more...

Search


powered by google
You are currently browsing "The symfony Cookbook" in Dutch for the 1.1 version - Switch to version: - Switch to language:
Creative Commons License This work is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License.
Translation of this work into another language is explicitly allowed.
This version of symfony is not maintained anymore.
If some of your projects still use this version, consider upgrading as soon as possible.

Net als iedere web applicatie zal je project een aantal terugkerende onderhoudstaken, database operaties of andere console scripts regelmatig moeten draaien.

Symfony 1.1 breid de symfony 1.0 pake tasks uit om een krachtige en uniforme command line utility voor je projecten te bieden, volledig geintegreerd met de symfony Command Line Interface (CLI).

Laten we onze eerste task schrijven

Open je symfony 1.1 project directory en typ:

$ php symfony generate:task doNothing

Dit zal een lege task aanmaken in lib/task/doNothingTask.class.php. Laten we die eens wat gaat aanpassen.

class doNothingTask extends sfBaseTask
{
  protected function configure()
  {
    $this->namespace        = 'project';
    $this->name             = 'do-nothing';
    $this->briefDescription = 'Does strictly nothing';
 
    $this->detailedDescription = <<<EOF
This task is completely useless, and should be run as often as possible.
EOF;
  }
 
  protected function execute($arguments = array(), $options = array())
  {
    $this->logSection('do-nothing', 'I did nothing successfully!');
  }
}

Deze taak doet zeker niet veel, maar het demonstreert de eerste basis concepten:

Je kan een beetje hiermee spelen: $ php symfony help project:do-nothing $ php symfony project:do-nothing

Wat command line interactie

Argumenten en opties zijn een manier om parameters aan een task mee te geven.

$ php symfony project:hello-world --name="Romain"

Hier draaien we de project:hello-world task met de name optie gezet naar Romain

$ php symfony project:hello-world Hi

Nu draaien we dezelfde task met het eerste argument gezet als Hi.

Opties en argumenten kunnen standaard waardes hebben, optioneel of verplicht zijn en hun doel tonen in de syntax van de task.

Laten we onze project:hello-world task schrijven:

class doHelloWorldTask extends sfBaseTask
{
  protected function configure()
  {
    $this->addArgument('verb', sfCommandArgument::OPTIONAL, 'Customize the verb used to say hello', 'hello');
    $this->addOption('name', null, sfCommandOption::PARAMETER_OPTIONAL, 'Customize the person to say hello to', 'world');
 
    $this->namespace        = 'project';
    $this->name             = 'hello-world';
    $this->briefDescription = 'Spread the (hello) world';
 
    $this->detailedDescription = <<<EOF
Runs an evolved hello world display, with customisable name and word.
EOF;
  }
 
  protected function execute($arguments = array(), $options = array())
  {
    $this->logSection('do', ucfirst($arguments['verb']).' '.ucfirst($options['name']));
  }
}

Kijk nu hoe symfony helpt om een verdwaalde gebruiker hoe ze onze nieuwe task moeten gebruiken:

$ php symfony project:hello-world invalid arguments given
$ php symfony help project:hello-world

En speel wat met de task:

$ php symfony project:hello-world
$ php symfony project:hello-world --name="romain"
$ php symfony project:hello-world --name=romain hi
$ php symfony project:hello-world hi --name=romain

Een aantal andere handige functionaliteiten

Questions & Feedback

If you find a typo or an error, please register and open a ticket.

If you need support or have a technical question, please post to the official user mailing-list.