edited for Clar and amended example pseudo-code
我正试图理解休眠的概念,有时它给我一些严重的头痛。
I was facing with a problem and trying to think a solution. I am using codeigniter and the problem is how to make different page titles and descriptions for different categories and searches in my web site.
这里我想到的是解决办法(我知道,它不是最好的表现方式,而只是详细看待基本思想):
控制员
$data[ results ] = call model and get results
this->load->view(ad_details,$results);
类别观点:
foreach ($results as $key => $row) {
$ad_title = $row->title;
$ad_id = $row->id;
$ad_price = $row->price;
$ad_status = $row->status;
$ad_city = $row->city;
$ad_user = $row->user;
if ($key<1) {
// let s be sure even customers enter same info we got unique titles and descriptions for search engines
$data[ title ] = "$ad_title $ad_id $ad_price";
$data[ description ] = "Second Hand Autos for $ad_status from $ad_user in $ad_city";
this->load->view(header,$data);
<body>
}
$ad_description = $row->description;
<h2>$ad_title</h2>
<p>$ad_description</p>
}
</body>
<? this->load->view(footer); ?>
Header_view file
<!doctype html>
<head>
<meta charset="utf-8">
<title><?=$title?></title>
<META NAME="description" CONTENT="<?=$description">
<META NAME="keywords" CONTENT="<?=$keywords?>" >
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="css/style.css">
<script src="js/libs/modernizr-2.0.6.min.js"></script>
</head>
<body>
实际标题和说明可能差别很大,有一些例外,我可能不得不使用不同类别和不同搜索页的不同代码。 因此,以这种方式打击多国军委会,还是有更好的办法这样做?
In that way, I’m trying to avoid using same foreach loops multiple times in 控制员 or in views. the actual titles and descriptions can be quite different, there can be some exceptions and i may have to use different codes for different categories and different search pages. So, is doing it in that way against mvc or is there better way to do that ?