2014-02-13 41 views
0

好的,所以我提供了有关用户条目的摘要信息的视图。用户可以为不同的“程序”(类别或多或少)和不同的“供应商”等创建条目。因此,程序视图将显示每个程序的一些摘要信息以及每个程序有多少条目。供应商视图将显示每个供应商的摘要信息以及每个供应商有多少个条目。Codeigniter MVC。从一个视图的摘要信息到另一个视图的详细信息

如何编码一个按钮,用户可以单击该按钮将它们带到该程序或供应商的条目视图。我感到困惑,因为我认为你不应该从视图访问控制器,但我希望用户能够以不同方式查看摘要信息,然后单击以获取详细数据。

所以程序查看可能看起来像: 页面标题:所有程序

方案:方案一点 开始日期:13年5月5日 结束日期:14年5月5日 按钮:|点击查看条目|

计划:计划2 开始日期:13年6月1日 结束日期:14年2月15日 按钮:|点击查看条目|

我真正想做的是调用我创建的模型,它接受一个充当过滤器的数组。它可以很好地从一个控制器调用,但我不认为我能做到这一点看起来像这样的时候:

public function get_entries($filter, $option = false) 
{ 
$this->db->where($filter); 
$this->db->from('item i'); 
$this->db->join('program p', 'p.Id=i.program_Id'); 
$this->db->join('vendor v', 'v.Id=i.vendor_Id'); 
$this->db->join('item_type it', 'it.Id=i.item_type_Id'); 
$this->db->join('item_type_category itc', 'itc.item_type_Id=it.Id'); 
$this->db->join('category c', 'c.Id=itc.category_Id'); 
$this->db->select('i.*, p.programName, v.VENDNM, it.name, c.catName'); 
$this->db->select('(SELECT FORMAT(i.cost, "c")) AS cost', FALSE); 
$query = $this->db->get(); 
$result = $query->result_array(); 
if ($option === false){ 
return $result; 
} 
elseif ($option === "count"){ 
return count($result); 
} 
} 
+0

如果您想查看程序1的所有条目,则可以使用ajax。 –

回答

0

这很容易 - 只需使用有确定的范围,你要搜索的字段的窗体。您在表单上使用的地址将首先转到您的控制器 - 然后是方法。使用Codeigniters形式帮手,如果你的控制器是“报告”和方法“搜索”:

echo form_open('reports/search'); 

然后在方法的“报告”控制器称为“搜索”

Verify the Form Using the Form Validation class. 
ALWAYS verify user input even if you are just using drop down menus. 

If the form does not verify 
    show the form view again with an error message 

Else 
    do the search with the values provided by the form. 
    Typically doing this search and passing back the results 
    (or False for no results) will happen in the Model 

If there are no database results 
    show the form view again with a no results message 

Else if there are results 
    pass results to a view page which will display them. 

表单辅助 http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html

表单验证 http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html

,并采取看看这个啧啧orial - 将向您展示您需要的许多基本代码模式 - http://ellislab.com/codeigniter/user-guide/tutorial/index.html

相关问题