Welcome Guest, Not a member yet? Register   Sign In
Calling a view in another view with variables: Against mvc or a good way for SEO?
#1

[eluser]parvus[/eluser]
edited for clarification

I was trying to understand the concept of mvc and sometimes it gives me some serious headaches.

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.


here is the solution i thought (i know it's not the best way the demonstrate it but don't stuck in details just look at the basic idea):

controller

Code:
$data['results'] = call model and get results
     this->load->view(ad_details,$data);

ad_categories view:


Code:
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);
         &lt;body&gt;
        }
      $ad_description = $row->description;
      <h2>$ad_title</h2>
      <p>$ad_description</p>
      }
      &lt;/body&gt;
     &lt;? this->load->view(footer); ?&gt;

header_view file

Code:
<!doctype html>
     &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;title&gt;&lt;?=$title?&gt;&lt;/title&gt;
      &lt;META NAME="description" CONTENT="&lt;?=$description"&gt;
      &lt;META NAME="keywords" CONTENT="&lt;?=$keywords?&gt;" &gt;
      &lt;meta name="viewport" content="width=device-width,initial-scale=1"&gt;
      &lt;link rel="stylesheet" href="css/style.css"&gt;
      [removed][removed]    
     &lt;/head&gt;
         &lt;body&gt;

In that way, I'm trying to avoid using same foreach loops multiple times in controller 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 ?




Theme © iAndrew 2016 - Forum software by © MyBB