我是Joomla的新手,我想知道Joomla控制器如何将数据传递给模型,模型以控制器和控制器来查看。虽然这可能是一个愚蠢的问题,但我真的试图找到答案。我希望我能从stackoverflow系列获得一些帮助。Joomla模型视图控制器(MVC)如何工作?
回答
控制器拾取在url视图变量和使用这些确定哪个视图需要被使用。然后它设置要使用的视图。该视图然后调用模型来获取它所需的数据,然后将其传递给tmpl以进行显示。
下面是这一切是如何一起工作进行简单的设置:
组件/ com_test/Controller.php这样
class TestController extends JController
{
// default view
function display() {
// gets the variable some_var if it was posted or passed view GET.
$var = JRequest::getVar('some_var');
// sets the view to someview.html.php
$view = & $this->getView('someview', 'html');
// sets the template to someview.php
$viewLayout = JRequest::getVar('tmpl', 'someviewtmpl');
// assigns the right model (someview.php) to the view
if ($model = & $this->getModel('someview')) $view->setModel($model, true);
// tell the view which tmpl to use
$view->setLayout($viewLayout);
// go off to the view and call the displaySomeView() method, also pass in $var variable
$view->displaySomeView($var);
}
}
组件/ com_test /视图/ someview/view.html.php
class EatViewSomeView extends JView
{
function displaySomeView($var) {
// fetch the model assigned to this view by the controller
$model = $this->getModel();
// use the model to get the data we want to use on the frontend tmpl
$data = $model->getSomeInfo($var);
// assign model results to view tmpl
$this->assignRef('data', $data);
// call the parent class constructor in order to display the tmpl
parent::display();
}
}
组件/ com_test /模型/ someview.php
class EatModelSomeView extends JModel
{
// fetch the info from the database
function getSomeInfo($var) {
// get the database object
$db = $this->getDBO();
// run this query
$db->setQuery("
SELECT
*
FROM #__some_table
WHERE column=$var
");
// return the results as an array of objects which represent each row in the results set from mysql select
return $db->loadObjectList();
}
}
个
组件/ com_test /视图/ someview/TMPL/someviewtmpl.php
// loop through the results passed to us in the tmpl
foreach($this->data as $data) {
// each step here is a row and we can access the data in this row for each column by
// using $data->[col_name] where [col_name] is the name of the column you have in your db
echo $data->column_name;
}
查看本网站的详细教程,了解如何使用Joomla的MVC制作组件和模块。希望它有助于
死链接......可能不是当你发布所以没有降票时。 – araisbec 2014-02-18 14:29:05
每当你连接到其他地方时,请张贴链接的回顾。 – 2014-07-24 16:19:06
也可参考有关如何让使用Joomla的MVC组件和模块的详细教程Joomla官方文档。希望它有帮助 http://docs.joomla.org/Developing_a_Model-View-Controller_Component/1.5/Introduction
- 1. (模型/视图/控制器)MVC
- 2. 模型视图控制器
- 3. 如何通过knockoutjs视图模型为MVC控制器
- 4. 如何在控制器/视图mvc中使用多个模型?
- 5. 如何使用模型/视图/控制器方法制作GUI?
- 6. 模型 - 视图 - 控制器(MVC)优于模型 - 视图的优点是什么?
- 7. Angular.js模型 - 视图 - 控制器动态更新不工作
- 8. 的UIView和模型 - 视图 - 控制器(MVC)模式
- 9. iPhone手工制作视图/控制器
- 10. 如果mvc模型视图控制器有一个参数getJSON不起作用
- 11. 父视图控制器和模型 - 视图 - 控制器解雇检测工作不
- 12. 使用视图控制器既作为模式视图控制器和作为标签栏视图控制器
- 13. JavaScript中的模型 - 视图 - 控制器
- 14. MVCS - 模型 - 视图 - 控制器服务
- 15. 视图模型属性在控制器
- 16. 模型,视图,控制器混乱
- 17. GWT模型视图控制器
- 18. PHP视图 - 控制器类模型
- 19. 了解模型 - 视图 - 控制器
- 20. MVC范例:从视图中揭示模型和控制器
- 21. 通用ASP.NET MVC模型,控制器和视图
- 22. jsp中的MVC模型视图控制器
- 23. MVC部分视图将模型传递给控制器
- 24. MVC - 从视图刷新控制器SQL数据模型?
- 25. PHP MVC - 从模型或控制器调用视图函数?
- 26. MVC从模型通过控制器传递对象到视图
- 27. MVC:无法回发视图模型到控制器
- 28. Asp.net视图模型和控制器MVC继承
- 29. MVC控制器/视图删除模型属性
- 30. 通过模型在MVC视图中创建到控制器
顺便说一句MVC代表模型视图控制器 – Martin 2011-04-19 08:32:01