我使用迷你php MVC。 bootstrap
的變量不包含在生成的view
中。我可以包括entityManager
到index.php
, 但我不能包括entityManager
來查看文件。爲什麼?如何將教條實體管理器包含在View生成的文件中?如何將教條實體管理器包含到View生成的文件中?
如何在以下文件中包含實體管理器到_register1Db.php
文件? 正確顯示視圖,它不顯示沒有找到bootstrap.php的錯誤(如果我chaneg路徑,這樣的錯誤顯示),但視圖不包括從bootstrap.php實體管理器
// 1 。 \ src \ bootstrap.php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
$isDevMode = true;
$entitiesPaths = array(__DIR__.'/CrmBundle/Entity');
$dbParams = array(
'dbname' => 'dbname',
'user' => 'user',
'password' => 'pswd',
'host' => 'localhost',
'driver' => 'pdo_mysql',
); // 'pdo_mysql',
$config = Setup::createAnnotationMetadataConfiguration($entitiesPaths, $isDevMode);
$em = \Doctrine\ORM\EntityManager::create($dbParams, $config);
$some='some';
// 2。 \ public \ index.php
require_once '../src/bootstrap.php'; //which requires autoload.php
print_r('<br><br> index some='.$some); // works
var_dump($em); //works
use core\App;
$app = new App(); //App from urk identifines controller and action and pass url paramteters to them, controller action analize parameters and displays views, in this case security\register
// 3。 src \ CrmBundle \ Resources \ views \ security \ register.php
include ('_register1Db.php');
// 4。 SRC \ CrmBundle \資源\視圖\ security_register1Db.php
require_once '/../../../../bootstrap.php'; //
var_dump($em); // Undefined variable: em
print_r('<br><br> register some='.$some); //Undefined variable: some
//我生成視圖的方法:SRC \芯\ View.php
ob_start();
include_once(__DIR__.'/../bootstrap.php');
include_once($this->viewTemplatePath.$this->file);
ob_end_flush();
//視圖產生與從自舉調試變量.php:src \ core \ View.php
include_once(__DIR__.'/../bootstrap.php');
ob_start();
// think how to render extract variable in order to pass to the file
include_once(__DIR__.'/../bootstrap.php');
var_dump($em); //undefined
print_r('<br><br> parseViewPhpinside some=' . $some); //undefined
print_r('<br><br> parseViewPhpinside __DIR__=' . __DIR__); // ....apache2\htdocs\own\log\src\core
include_once($this->viewTemplPath.$this->file);
if($store) return ob_get_clean();
else ob_end_flush();
var_dump($em); //undefined
print_r('<br><br> parseViewPhp some='.$some); //undefined