简体   繁体   English

Joomla - MVC 模型/视图注册

[英]Joomla - MVC Model/View registration

I have a component that I need to register a second view for.我有一个组件,我需要为其注册第二个视图。 When I encode my url to set the view varialbe from:当我编码我的 url 以从以下位置设置视图变量时:

http://www.mysite.com/index.php?option=com_mycom&view=view1

to

http://www.mysite.com/index.php?option=com_mycom&view=view2

View2 will not display. View2 不会显示。

Do I need to register the second view in the controller?我需要在控制器中注册第二个视图吗? Can you point me to a reference?你能给我指出一个参考吗? Google searches have come up nill.谷歌搜索结果为零。

EDIT编辑

The view2 code:视图2代码:

defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.view');

/**
 * HTML View class for the mls Component
 *
 * @package    UniversalDynamicMedia.com
 * @subpackage  Components
 */
class mlsViewlist extends JView
{
function display($tpl = null)
{
    $model = &$this->getModel();
    $array = $model->mlsListData();
    $disparray =    foreach ($array as list($a,$b,$c,$d,$e)) {
                echo <tr><td>$a</td><td>$b</td><td>$c</td><td>$d</td><td>$e</td></tr>
            }
    $this->assignRef( 'disparray', $disparray );
    parent::display($tpl);
}
}
?>

You have a syntax error here:你在这里有一个语法错误:

echo <tr><td>$a</td><td>$b</td><td>$c</td><td>$d</td><td>$e</td></tr>

Should be应该

echo "<tr><td>$a</td><td>$b</td><td>$c</td><td>$d</td><td>$e</td></tr>";

You need quotes when echoing string literals.回显字符串文字时需要引号。 You shouldn't even be echoing anything here though.你甚至不应该在这里回应任何东西。 All output should be done in the view's Default.php not view.html.php.所有输出都应该在视图的 Default.php 而不是 view.html.php 中完成。 The reason for this is because Joomla needs to output everything before your component (ie page header) first.这样做的原因是因为 Joomla 需要首先输出您的组件(即页眉)之前的所有内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM