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

2 Answers 2

4

You need to bootstrap (but not run) the application as well. After what you have, add:

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

you may need to set APPLICATION_ENV and APPLICATION_PATH as well if you've not already.

Sign up to request clarification or add additional context in comments.

5 Comments

I tired that byt when I use new Admin_Contract_Table(); I get class not found error. I wonder why everything must be so difficult with ZF
Where is the admin contract table class defined? Do you have an 'admin' module?
but it does not load models under /application/models, is it normal?
It depends how you have the autoloaders setup. By default, if you have a bootstrap file for your admin module, application/modules/admin/models/Contacts.php would be a class named Admin_Model_Contacts.
How idiotic is this ZF bootstrap system? Really, I cannot copy with it. I tried everything but I am still failing. I would call it Zend Nightmare instead of Framework. I am reading the ZF quick start and I am seeing how complex and stupid they made it!
0

You haven't registered your Admin namespace in the autoloader..

$autoloader->registerNamespace('Admin');

2 Comments

where should I do it, in the application bootstrap or in the module bootstrap?
I treid $autoloader->registerNamespace('Admin'); but it does nothing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.