How to setup Bootstrapping in a project
Sorry if this may have been asked here already, I did search and did not find much.
I am somewhat new to PhpStorm. Switching IDE's and attempting to setup the first project.
Lets say that a portion of the structure is as follows, and is based at DocRoot:
├── app │
├── API │
├── admin │
├── assets │
├── client │
├── grids │
├── includes │
├── library │
├── libs │
├── logs │
├── membership │
├── reports │
└── utils
/app : contains the sites application.
We have a php index.php in the /app/client directory.
That index file will "require_once" the /app/bootstrap.inc.php file.
bootstrap.inc.php will include all the required includes, autoload classes, instantiate required classes, setup a database singleton ($db), etc.
In PhpStorm, how do I get this to work in the IDE. Site files are on a local drive.
I have the includes setup to include the /app/includes /app/libs /app/library.
Still have items show up as unresolved in the IDE.. Ex.. $Db is a singleton that was created in the bootstrap.inc.php.
I have this in my bootstrap.inc.php
---------------------
/** @var MySingletonClass $db */
$db = db_driver\Db::instance('app_1');
---------------------
An example use in a file, shows “Undefined varialbe ‘$db’”
---------------------
<?php
require_once( $_SERVER['DOCUMENT_ROOT'] . '/app/bootstrap.inc.php');
$tRow = $db->query( "SELECT * FROM system_text WHERE st_id=5" )->fetchAll()->results;
---------------------
Even tried a simple php in the same directory as the bootstrap.inc.php
---------------------
<?php
//require_once( $_SERVER['DOCUMENT_ROOT'] . '/app/bootstrap.inc.php');
require_once( 'bootstrap.inc.php');
$tRow = $db->query( "SELECT * FROM system_text WHERE st_id=5" )->fetchAll()->results;
---------------------
Remote site is a remote almalinux lamp stack. Database is a mariadb located on the remote server.
Thanks!!
请先登录再写评论。
Hi Jsprinceiii
Try enabling the appropriate option for that inspection – so the IDE will use such variables from other places:
You can manually locate that inspection in the IDE settings/preferences: "Editor | Inspections | PHP | Undefined symbols" or jump right there directly from the Editor via context menu: