Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8500383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:55:49+00:00 2026-06-11T00:55:49+00:00

I have a problem now with building a mechanism that allows to build console

  • 0

I have a problem now with building a mechanism that allows to build console scripts with zend for app. For example like:

–scripts

—-index.php

—-basecmd.php

When basecmd contains main class for other scripts, and file structure is

include index.php
....
MyClass extends Zend_Console_Getopt{

but in index.php i need to setup APPLICATION_ENVOIRMENT with param send as –application_env to script
My problem is that I can set it when parsing params with getopt, but how to make it in index.php?
Info: I need to show error like:
‘application_env must me always set when running script’
I’d appreciate any guides for doing it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:55:51+00:00Added an answer on June 11, 2026 at 12:55 am

    If I’ve understood correctly, you are trying to run your application from CLI/CMD, by calling basecmd.php that will setup variables/constants for index.php to work correctly

    Your basecmd.php should look something like this:

    #!/usr/bin/env php
    <?php
    // basecmd.php
    require_once 'path/to/Zend/Console/Getopt.php';
    try {
        $opts = new Zend_Console_Getopt(
            array(
                'app-env|e=s' => 'Application environment',
                'app-path|ap=s' => 'Path to application folder',
                'lib-path|lp=s' => 'Path to library',
                // more options
            )
        );
        $opts->parse();
        if (!($path = $opts->getOption('ap'))) { // cli param is missing
            throw new Exception("You must specify application path");
        }
        define('APPLICATION_PATH', $path);
        // process other params and setup more constants/variables
    } catch (Zend_Console_Getopt_Exception $e) {
        echo $e->getUsageMessage();
        exit;
    } catch (Exception $e) {
        echo $e->getMessage() . "\n";
        exit;
    }
    // it is wise to setup another constant so application can determine is it a web or cli call
    define('RUN_VIA', 'cli');
    // if all done correctly include application loader script
    include 'index.php';
    

    And in your index.php you should just test if constants or variables are already defined:

    <?php
    // index.php
    defined('APPLICATION_PATH') // is it defined
        or define('APPLICATION_PATH', '../application'); // no? then define it
    defined('RUN_VIA')
        or define('RUN_VIA', 'web');
    // ... rest of the code
    

    I hope this helps you get on the track 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

recently i'm building an app and now i have some problem with layout and
I have a dynamic list code that works just fine. My only problem now
I have a problem that I'm working on for quite some time now. I
I have a problem that I had working in a test but now in
I have a problem that I can't figure out. I'm building a small framework
I'm wrestling with building a custom membership provider that allows me to have the
So I feel like a serious rookie right now, but I have a problem
I'm now building a webapp for iPhone, and I have problem with the scrolling
Building on this question , now I have another problem. Given this, shipments =
I'm building my first rails app just right now and now I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.