3

I need to lo the Zend Framework and its MVC application in a PHP script so I could do some models to query the database. The framework and some libs are loaded this way (the script was created by someone else):

    /** Initialise Zend  */
define( 'BRIDGE_BASE_DIR', dirname( __FILE__ ) );
set_include_path( get_include_path().PATH_SEPARATOR.BRIDGE_BASE_DIR.'/../library' );

require_once('Zend/Loader/Autoloader.php');
require_once 'Zend/Config/Ini.php';

$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('XYz');
$autoloader->registerNamespace('Yxz');

I would like to call a model this way: Franchisee_Model_Franchisee::find($franchiseeId)

which is located under: application/modules/franchisee/models/franchisee

I tried many ways but I cannot load the full stack. Is there a simple way to load ZF in a script, including everything under application and application/modules?

UPDATE

I tried this too:

<?php
error_reporting( E_ALL & ~E_NOTICE );

/** Initialise Zend  */
define( 'BRIDGE_BASE_DIR', dirname( __FILE__ ) );
set_include_path( get_include_path().PATH_SEPARATOR.BRIDGE_BASE_DIR.'/../library' );

require_once('Zend/Loader/Autoloader.php');
require_once 'Zend/Config/Ini.php';

$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('Xyz');
$autoloader->registerNamespace('Yzx');


/** Handle arguments */
if ($argc < 2) {
  echo 'LOG: ' . Zend_Date::now()->toString('YYYY-MM-ddTHH:mm:ss') . ' Please set the environment.'.PHP_EOL;
    exit(1);
}

define("APPLICATION_ENV", $argv[1]);
// echo 'LOG: ' . Zend_Date::now()->toString('YYYY-MM-ddTHH:mm:ss');
// echo " Current environment is: ".APPLICATION_ENV.PHP_EOL;

/** Zend_Application */
define(APPLICATION_PATH, dirname( __FILE__ ).'/../application');
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);

$application->bootstrap();

echo "Running ZF version: " . Zend_Version::VERSION;

new Admin_Contract_Table();

but I get

Fatal error: Class 'Admin_Contract_Table' not found in /Users/myuser/dev/htdocs/Admin/current/vend_bridge/zend.php on line 42
4

2 回答 2

4

您还需要引导(但不运行)应用程序。在你拥有之后,添加:

$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap();

你可能需要设置APPLICATION_ENVAPPLICATION_PATH如果你还没有设置。

于 2012-07-12T10:04:48.493 回答
0

你还没有Admin在自动加载器中注册你的命名空间..

$autoloader->registerNamespace('Admin');

于 2012-07-12T12:50:39.717 回答