如何向 Phalcon 应用程序添加新视图?
How to add new view to Phalcon app?
我完全不明白 Phalcon PHP 如何呈现它的视图。我想创建一个名为 "manager".
的新页面
根据我的理解,通过创建控制器,我可以 link 将其添加到视图中。我创建了一个名为 ManagerController.php
的控制器,然后在 views/manager/index.volt
.
中添加了一个视图
我在 volt 文件中添加了一些文本来检查它是否有效。当我去 /manager/
时,什么也没有出现。
我这样做是否正确,还是必须在某处分配视图?
class ManagerController extends ControllerBase
{
public function initialize()
{
$this->tag->setTitle('Files/My Files');
parent::initialize();
}
}
控制器上的初始化函数是一个事件运行在构建控制器
之后
为了显示该控制器的视图,至少需要设置一个索引操作
在您有兴趣渲染 /manager/ 的路由时,这将对应于 indexAction
class ManagerController extends ControllerBase
{
public function initialize()
{
$this->tag->setTitle('Files/My Files');
parent::initialize();
}
public function indexAction()
{
// This will now render the view file located inside of
// /views/manager/index.volt
// It is recommended to follow the automatic rendering scheme
// but in case you wanted to render a different view, you can use:
$this->view->pick('manager/index');
// http://docs.phalconphp.com/en/latest/reference/views.html#picking-views
}
// If however, you are looking to render the route /manager/new/
// you will create a corresponding action on the controller with RouteNameAction:
public function newAction()
{
//Renders the route /manager/new
//Automatically picks the view /views/manager/new.volt
}
}
我完全不明白 Phalcon PHP 如何呈现它的视图。我想创建一个名为 "manager".
的新页面根据我的理解,通过创建控制器,我可以 link 将其添加到视图中。我创建了一个名为 ManagerController.php
的控制器,然后在 views/manager/index.volt
.
我在 volt 文件中添加了一些文本来检查它是否有效。当我去 /manager/
时,什么也没有出现。
我这样做是否正确,还是必须在某处分配视图?
class ManagerController extends ControllerBase
{
public function initialize()
{
$this->tag->setTitle('Files/My Files');
parent::initialize();
}
}
控制器上的初始化函数是一个事件运行在构建控制器
之后为了显示该控制器的视图,至少需要设置一个索引操作
在您有兴趣渲染 /manager/ 的路由时,这将对应于 indexAction
class ManagerController extends ControllerBase
{
public function initialize()
{
$this->tag->setTitle('Files/My Files');
parent::initialize();
}
public function indexAction()
{
// This will now render the view file located inside of
// /views/manager/index.volt
// It is recommended to follow the automatic rendering scheme
// but in case you wanted to render a different view, you can use:
$this->view->pick('manager/index');
// http://docs.phalconphp.com/en/latest/reference/views.html#picking-views
}
// If however, you are looking to render the route /manager/new/
// you will create a corresponding action on the controller with RouteNameAction:
public function newAction()
{
//Renders the route /manager/new
//Automatically picks the view /views/manager/new.volt
}
}