加载不在Elements或View文件夹内的文件? [英] Load files that aren't within the Elements or View folders?

查看:65
本文介绍了加载不在Elements或View文件夹内的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用小部件制作CMS之类的东西,因此我的app文件夹中有一个文件夹小部件,其中有我的小部件,例如app / Widgets / UsersOnline / UserOnline.php
我使用小部件模型在appController中的beforefilter方法中进行建模,然后将它们传递给视图,因此我希望借助小部件助手在位置上呈现它们。但是我无法使用view-> element()方法进入小部件/UserOnline/view.ctp文件夹,此方法要求文件位于Elements /中。

Hi I'm trying to make something like CMS with widgets so I have a folder widgets in my app folder there are my widgets for example app/Widgets/UsersOnline/UserOnline.php I loading them from db with widgets model in beforefilter method in appController and there i pass them to the view, so with a widget helper I would like to render them on the position. But i can't get to the folder widgets/UserOnline/view.ctp with view->element() method this method require file to be in Elements/.

TLDR /实际问题:

有什么方法可以加载文件在视图/和/元素之外查看?

Is there any way to load files in view outside the view/ and /elements ? Thanks in advance.

推荐答案

在调用元素时可以使用相对路径:

You can use relative paths when calling the element:

<?php echo $this->Element('../../Widgets/UsersOnline/UserOnline'); ?>

也不要忘记将元素文件命名为 UserOnline.ctp。

Don't forget to name your element file 'UserOnline.ctp' too.

这篇关于加载不在Elements或View文件夹内的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆