我使用迷你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