1

i have one issue i make a component and i add data add component data table that i want to fetch that data in my site how to do and i have one other issue how to put query in view.html.php file in components i have code i add my code i have one error i add my error

500 - View class not found [class, file]: team_memberViewteam_member, C:\wamp\www\Joomla_2.5.8-Stable-Full_Package\components\com_team_member\views\team_member\view.html.php

this is my code please help me how to fetch data in database....

// import Joomla view library
jimport('joomla.application.component.view');

/**
 * HTML View class for the HelloWorld Component
 */
class HelloWorldViewHelloWorld extends JView
{
        // Overwriting JView display method
        function display($tpl = null) 
        {
                // Assign data to the view
                 $db = JFactory::getDbo();

// Create a new query object.
                $query = $db->getQuery(true);

// Select all records from the user profile table where key begins with "custom.".
// Order it by the ordering field.
            $query->select(array('id', 'member_name', 'member_pic', 'member_des','member_description'));
            $query->from('#__gztqw_team_member_datadetails');
            $query->where('profile_key LIKE \'custom.%\'');
            $query->order('ordering ASC');

// Reset the query using our newly populated query object.
            $db->setQuery($query);

// Load the results as a list of stdClass objects.
            $results = $db->loadObjectList();

                // Display the view
                parent::display($tpl);
        }
}
4

2 回答 2

1

尝试简单的方法:-

$db = JFactory::getDbo();
$query = 'SELECT data FROM #__gztqw_team_member_datadetails WHERE profile_key LIKE "custom.%" order by ASC';
$db->setQuery($query);
$results = $db->loadObjectList();

此外,您还没有在函数中恢复任何值,并且在哪里显示它是在视图中显示数据的最佳方式,使用控制器功能并分配结果值以在视图中显示

你需要阅读http://docs.joomla.org/Developing_a_Model-View-Controller_%28MVC%29_Component_for_Joomla!2.5

于 2013-04-24T05:36:26.383 回答
0

首先,您视图中的类称为HelloWorldViewHelloWorld,它应该称为Team_memberViewTeam_member,这就是导致您的错误的原因。

其次,理想情况下,您应该将数据库查询放入您的模型中,但是如果您将其放入您的视图中,它仍然可以工作。我已经为您提供了一个示例,说明如何使其与视图中的查询一起使用。我创建了一个名为 $items 的受保护变量,并将数据库中的结果分配给该变量。

在您的模板中,您将使用以下方式访问数据库中的数据

foreach($this->items as $item):
       echo $item->id;
endforeach();

在你看来你应该有

class Team_memberViewTeam_member extends JView
{
    protected $items;

    // Overwriting JView display method
    public function display($tpl = null) 
    {
         $db = JFactory::getDbo();

           // Create a new query object.
            $query = $db->getQuery(true);

     // Select all records from the user profile table where key begins with "custom.".
// Order it by the ordering field.
        $query->select(array('id', 'member_name', 'member_pic','member_des','member_description'));
        $query->from('#__gztqw_team_member_datadetails');
        $query->where('profile_key LIKE \'custom.%\'');
        $query->order('ordering ASC');

  // Reset the query using our newly populated query object.
        $db->setQuery($query);

// Load the results as a list of stdClass objects.
        $this->items = $db->loadObjectList(); 
         parent::display($tpl);
    }
}
于 2013-04-26T15:35:11.790 回答