【发布时间】:2014-06-28 17:19:01
【问题描述】:
我的数据库中有两张表,一张用于“LOUNGES”,一张用于“CITIES”。它们之间没有明确的联系。我的意思是我没有在“LOUNGES TABLE”中放置“city_id”列。我只是从“CITIES”中取出“name”列并选择它作为“LOUNGE”。
我正在使用 Codeigniter 和 DataMapperPHP,所以目前我在 Lounge.php 中的索引函数列出了“CITIES”表中的所有“CITIES”,并且我有一个名为“search”的列,它是Lounge.php 中的函数名称,从那里很容易我只需说“where('city','London'),我在伦敦的所有休息室都列出了它。
我的问题是如何让它变得更好。我的意思是让它只有一个功能“查看”,例如,当我必须添加一个新城市时,无需我添加一个带有城市名称的新功能就可以自动生成链接?
任何想法这应该如何工作?
这是在代码中看到它的整个例子:
public function index()
{
$cities = new City_model();
$cities->where('active', '1')->order_by('id', 'ascen')->get();
$recent_cities = array();
foreach ($cities as $city)
{
$single_city = array
(
'id' => $city->id,
'city_name' => $city->city_name,
'search' => $city->search,
);
array_push($recent_cities, $single_city);
}
$data = array
(
'cities' => $recent_cities,
'main_content' => 'templates/city_lounges',
'active_state' => 'lounge',
);
$this->parser->parse('template_main', $data);
}
public function london()
{
$lounges = new Lounge_model();
$lounges->where('city', 'London')->order_by('date_added', 'desc')->get();
$recent_lounges = array();
foreach ($lounges as $lounge)
{
$id = $lounge->id;
$fetch_slug = $lounge->club_slug;
$trimpdate = $lounge->date_added;
$date = explode(" ", $trimpdate);
$single_lounge = array
(
'id' => $lounge->id,
'club_name' => $lounge->club_name,
'club_logo' => $lounge->club_logo,
'facebook_page' => $lounge->facebook_page,
'date_added' => $date[0],
'city' => $lounge->city,
);
array_push($recent_lounges, $single_lounge);
}
$data = array
(
'lounges' => $recent_lounges,
'main_content' => 'templates/content_lounges',
'active_state' => 'lounge',
);
// Parse it to the template
$this->parser->parse('template_main', $data);
}
【问题讨论】:
-
请添加两个表的表结构
标签: php mysql sql codeigniter codeigniter-datamapper