php oo,可变的环境和发送参数在PHP OO

我对使用PHP OO通过页面使用参数非常困惑。

我正在关注一个关于创建框架的教程(它就像Zend Framework一样);但是,我不明白的是什么时候发生这种情况:

例如,索引:

// File: sourcefiles/index.php

define('DS', DIRECTORY_SEPARATOR);

define('ROOT', realpath(dirname(__FILE__)).DS );

define ('APP_PATH',(ROOT.'aplicacion'));

require_once APP_PATH. DS.'Config.php';

require_once APP_PATH. DS.'Request.php';

require_once APP_PATH. DS.'BootStrap.php';

require_once APP_PATH. DS.'Controller.php';

require_once APP_PATH. DS.'View.php';

try

{

BootStrap::run(new Request());我有:

// File: sourcefiles/controladores/IndexController.php

class IndexController extends Controller

{

public function __construct() {

parent::__construct();

}

public function indexAction()

{

$this->view->titulo='Homepage';

$this->view->contenido='Whatever';

$this->view->renderizar('index');

}

}

?>和这个:

// file : sourcefiles/aplicacion/View.php

class View

{

private $controlador;

private $layoutparams;

public function __construct(Request $peticion)

{

$this->controlador = $peticion->getControlador();

}

public function renderizar($vista,$item=false)

{

$rutaview = ROOT.'vistas'.DS.$this->controlador.DS.$vista.'.phtml';

if (is_readable($rutaview))

{

include_once $rutaview;

}

else

{

throw new Exception('Error de vista');

}

}

}

?>这里是视图:

// file : sourcefiles/vistas/index/index.phtml

Vista index..

echo $this->titulo;

echo $this->contenido;

?>

现在我的问题是:

IndexController如何使用该行? $this->view->titulo = blabla;

视图类没有“titulo”属性;但是,我可以做到这一点。但是,这是一件很奇怪的事情,如果我在调用$this->view->renderizar('index')之后这样做,我会得到这个错误。

index.phtml文件如何知道这一点? echo $this->titulo;因为没有包含或需要调用,这让我感到困惑。

当我在文件中执行require或include调用时,所需或包含的文件是否知道调用者的变量?

如果有人能向我解释这些,我会非常感激:D

或者将我与关于这方面官方信息的讨论联系起来,或者如何调用?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值