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

  • Home
  • SEARCH
  • 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 4265972
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:41:49+00:00 2026-05-21T06:41:49+00:00

I am working on my first MVC framework, and want to define 4 constants

  • 0

I am working on my first MVC framework, and want to define 4 constants for BASE_PATH, APP_PATH, LIB_PATH & PUBLIC_PATH. My file structure looks like this:

/
/app
    /controllers
    /models
    /views
/config
/db
/lib
/public_html
    /css
    /js
    /img

My index.php file is located in the public_html directory. And currently has the following code:

error_reporting(E_ALL);
define('BASE_PATH',dirname(realpath(__FILE__)) . "/../");
define('APP_PATH',dirname(realpath(__FILE__)) . "/../app/");
define('LIB_PATH',dirname(realpath(__FILE__)) . "/../lib/");
define('PUBLIC_PATH',dirname(realpath(__FILE__)) . "/");

require LIB_PATH . 'core.php';

This works, but I feel like there must be a better way of doing it without all of the “..”. Any suggestions or is this the best way of going about it? Let me know. Thank you!


ANSWER

Thank you to @fireeyedboy and @KingCrunch, I have come up with the solution I was looking for. This is my final code:

define('PUBLIC_PATH', dirname(__FILE__) . "/");
define('BASE_PATH', dirname(PUBLIC_PATH) . "/");
define('APP_PATH', BASE_PATH . "app/");
define('LIB_PATH', BASE_PATH . "lib/");
  • 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-05-21T06:41:49+00:00Added an answer on May 21, 2026 at 6:41 am

    How about this:

    define('PUBLIC_PATH',dirname(realpath(__FILE__)) . "/");
    define('BASE_PATH',dirname(PUBLIC_PATH));
    define('APP_PATH',BASE_PATH . "/app/");
    define('LIB_PATH',BASE_PATH . "/lib/");
    

    In other words use dirname() again. And re-order defining the constants to make direct use of them. Not sure it helps readability though.

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

Sidebar

Related Questions

I'm working on an MVC site with Entity Framework Code First, using Ninject for
I working on my first ASP.net MVC project and and i got some problems
I'm working on a project in MVC 3 (first time using!). One question I
I am working on my second multitenant MVC application. My first did not use
I'm working through the ASP.NET MVC article at http://weblogs.asp.net/scottgu/archive/2007/11/13/asp-net-mvc-framework-part-1.aspx . (Note: Some of the
I am working in ASP.Net MVC 1.0 and SQL Server 2000 using Entity Framework.
I'm working on my first real MVC application and I'm trying to follow general
I am working on my first asp MVC project that will ultimately end up
First I want to refer to this post: Where to put Entity Framework Data
I'm building a MVC 3 application and use Entity Framework 4.3 code-first. My context

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.