稍后返回? PHP查看文件
假设我有一个像这样构建的视图文件:
<html>
...
<title><?= Functions::Text('title'); ?></title>
....
<body>
....
<?= Functions::Text('sometext'); ?>
</body>
</html>
Functions::Text - 将在表 texts
中为我提供一个数据库条目,其中包含标题和某些文本的 search_string
。
我想立即提取数据,而不是按请求提取数据(这意味着 - 收集给予文本的字符串数组(这并不难) - 但我希望数据在选择查询之后转到请求数据的确切位置
意味着 -
$query = select ... ;
... fetch ...
$results_of_fetch = array ('title'=>'Welcome!','sometext' => 'sometext!!');
以及视图文件 -
<html>
...
<title>Welcome!</title>
....
<body>
....
sometext!!
</body>
</html>
Lets say I have a view file that is built like this:
<html>
...
<title><?= Functions::Text('title'); ?></title>
....
<body>
....
<?= Functions::Text('sometext'); ?>
</body>
</html>
Functions::Text - would give me a db entry in table texts
with search_string
of title and sometext.
I want to pull out the data at once, and not per request (which mean - to collect an array of strings given to Texts (which is not that hard) - but I want the data, after the select query, to go to the exact places which requested the data.
which mean -
$query = select ... ;
... fetch ...
$results_of_fetch = array ('title'=>'Welcome!','sometext' => 'sometext!!');
And the view file -
<html>
...
<title>Welcome!</title>
....
<body>
....
sometext!!
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你的问题与对象而不是 MVC 更相关。
所以,我想提出建议。
如果必须多次重用对象,请不要使用静态方法。
通过有效地使用非静态方法,您不必一遍又一遍地查询数据库。
在您的布局(或视图)文件中
,我可能不理解您的必要性,您可以发表评论,并请检查您的问题。
I think your question is more related to Object rather than MVC.
So, i would like to make suggestion.
Don't use static method if you have to reuse object more that one time.
By using non static method efficiently, you don't have to query database over and over again.
And in you layout(or view) file
And I might not be understanding your necessity, you can comment, and please review your question.
您可以使用 AJAX 和 jQuery 来完成此操作。 jQuery,这样就容易多了。
完全未经测试,但输出应该如下所示。
You can do this with AJAX and jQuery. jQuery, so that it'll be much easier.
Totally untested but output should look like this.