English 中文(简体)
它是针对MVC模式,在另一种观点中对变数的看法?
原标题:Is it against to MVC pattern calling a view in another view with variables?

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 ?

最佳回答

<><>Edit>: 我从阅读本意见中了解到,你可以在《国际公认标准》中使用<代码>(0],你必须使用<代码> $results->row(。 显然,我只剩下我的答案,因为那只是说,它应该是 CI的100%,而是铭记这一点。


下面是我提出以下意见的方式:

<?php $this->load->view( header , array(
   title  => $results[0]->title.   .$results[0]->id.   .$results[0]->price,
   description  =>  Second hand autos for  .$results[0]->status.  from  .$results[0]->user.  in  .$results[0]->city
)); ?>
<body>
  <h2><?php echo htmlspecialchars($results[0]->title); ?></h2>
  <p><?php echo htmlspecialchars($results[0]->description); ?></p>

  <?php foreach($results as $row): ?>
    <!-- Deal with results -->
  <?php endforeach; ?>
  </body>
 <? this->load->view( footer ); ?>

在这里,你可以看到,除你实际处理每个结果外,我已经消除了 for。 尽管如此,我的个人意见是,如果你为了维护法典的可读性/可维持性,你会再把“登机重复”的门槛太远。 如果将多处海滩环形结合到一起,则该守则就更难以理解,而没有。

我也试图削减购买力平价和不同任务的数量,这通常是一件好事,但如果推向太远,这也可能不方便。 例如,你可能想在你看来,通过行使这一权利而缩小所有<代码>年限值;:

$r = $results[0];

那么,你可能不会。 不管 qua子是什么样子:

问题回答

由于MVC是一种设计模式,而不是一种yn子规则,你在此享有一定程度的自由。 我认为,在使用一种观点方面没有任何错误,不仅在 CI中是空洞的,而且深思熟虑的是,你可以提出不同的观点,而不必通过“次要”来看待其一套数据,因为意见是缓冲的,而且所有途径都可以查阅。

缩略语

controller:

$data[ results ] = $this->your_model->get_details();
// this will be in the form of an array returned directly from the model 
// i.e. the model code would look someting like:
// $data = array();
// foreach($query->result() as $row)
// {
//   $data[] = $row;
// }
// return $data;

$this->load->view( ad_details ,$data);

In ad_details.php:

<?php $this->load->view( header );?>
<!-- html code -->
<? $this->load->view( footer ); ?>

如果是的话,你会看到两位领导人。 php和脚本。 现在,在不必再通过后,将产生一个可变的成果。

如果你不能把你从控制层调离,并且允许把你称之为控制点,那么图瓦卢失踪人员调查委员会就能够使你的生活更加容易和更快的发展。

总的来说,你希望有一个模式——一种看法是,某些控制者控制了关系和数据/流量。 管理人员可以管理多种模式和观点,但每一种不同观点都应有相应的模式。

最好是在ASP NET MVC上读。

在控制器中处理你的逻辑。

一般来说,这意味着休息和条件, 决定什么是,以表明偏离观点。 这一观点可以使用逻辑决定如何显示障碍、坐下来制作表格等。

所有这一切都由控制者承担。

$data[ results ] = call model and get results
$this->load->view(ad_details,$results);
foreach ($results as $key => $row) {
    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);
    }
this->load->view(body, data);




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签