Ver Mensaje Individual
  #5 (permalink)  
Antiguo 22/06/2011, 15:45
Avatar de GatorV
GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: Ejecutar Controller Action desde consola

No no, en el modelo es donde tiene que estar todo eso, verifica el ejemplo que viene en el Quickstart:

Código PHP:
Ver original
  1. // scripts/load.sqlite.php
  2.      
  3.     /**
  4.     * Script for creating and loading database
  5.     */
  6.      
  7.     // Initialize the application path and autoloading
  8.     defined('APPLICATION_PATH')
  9.         || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
  10.     set_include_path(implode(PATH_SEPARATOR, array(
  11.         APPLICATION_PATH . '/../library',
  12.         get_include_path(),
  13.     )));
  14.     require_once 'Zend/Loader/Autoloader.php';
  15.     Zend_Loader_Autoloader::getInstance();
  16.      
  17.     // Define some CLI options
  18.     $getopt = new Zend_Console_Getopt(array(
  19.         'withdata|w' => 'Load database with sample data',
  20.         'env|e-s'    => 'Application environment for which to create database (defaults to development)',
  21.         'help|h'     => 'Help -- usage message',
  22.     ));
  23.     try {
  24.         $getopt->parse();
  25.     } catch (Zend_Console_Getopt_Exception $e) {
  26.         // Bad options passed: report usage
  27.         echo $e->getUsageMessage();
  28.         return false;
  29.     }
  30.      
  31.     // If help requested, report usage message
  32.     if ($getopt->getOption('h')) {
  33.         echo $getopt->getUsageMessage();
  34.         return true;
  35.     }
  36.      
  37.     // Initialize values based on presence or absence of CLI options
  38.     $withData = $getopt->getOption('w');
  39.     $env      = $getopt->getOption('e');
  40.     defined('APPLICATION_ENV')
  41.         || define('APPLICATION_ENV', (null === $env) ? 'development' : $env);
  42.      
  43.     // Initialize Zend_Application
  44.     $application = new Zend_Application(
  45.         APPLICATION_ENV,
  46.         APPLICATION_PATH . '/configs/application.ini'
  47.     );
  48.      
  49.     // Initialize and retrieve DB resource
  50.     $bootstrap = $application->getBootstrap();
  51.     $bootstrap->bootstrap('db');
  52.     $dbAdapter = $bootstrap->getResource('db');
  53.      
  54.     // let the user know whats going on (we are actually creating a
  55.     // database here)
  56.     if ('testing' != APPLICATION_ENV) {
  57.         echo 'Writing Database Guestbook in (control-c to cancel): ' . PHP_EOL;
  58.         for ($x = 5; $x > 0; $x--) {
  59.             echo $x . "\r"; sleep(1);
  60.         }
  61.     }
  62.      
  63.     // Check to see if we have a database file already
  64.     $options = $bootstrap->getOption('resources');
  65.     $dbFile  = $options['db']['params']['dbname'];
  66.     if (file_exists($dbFile)) {
  67.         unlink($dbFile);
  68.     }
  69.      
  70.     // this block executes the actual statements that were loaded from
  71.     // the schema file.
  72.     try {
  73.         $schemaSql = file_get_contents(dirname(__FILE__) . '/schema.sqlite.sql');
  74.         // use the connection directly to load sql in batches
  75.         $dbAdapter->getConnection()->exec($schemaSql);
  76.         chmod($dbFile, 0666);
  77.      
  78.         if ('testing' != APPLICATION_ENV) {
  79.             echo PHP_EOL;
  80.             echo 'Database Created';
  81.             echo PHP_EOL;
  82.         }
  83.      
  84.         if ($withData) {
  85.             $dataSql = file_get_contents(dirname(__FILE__) . '/data.sqlite.sql');
  86.             // use the connection directly to load sql in batches
  87.             $dbAdapter->getConnection()->exec($dataSql);
  88.             if ('testing' != APPLICATION_ENV) {
  89.                 echo 'Data Loaded.';
  90.                 echo PHP_EOL;
  91.             }
  92.         }
  93.      
  94.     } catch (Exception $e) {
  95.         echo 'AN ERROR HAS OCCURED:' . PHP_EOL;
  96.         echo $e->getMessage() . PHP_EOL;
  97.         return false;
  98.     }
  99.      
  100.     // generally speaking, this script will be run from the command line
  101.     return true;

Ese esta como dice en /scripts/load.sqllite.php, y lo ejecutas desde la consola navegando a esa ruta e invocando el script.

Saludos.