2016-06-06 18 views
1

In meinem Controller habe ich diesen Code hinzugefügt.Für verschiedene Ansichtsdateien gibt es verschiedene Funktionen.Wie kann ich Meta-Tags für verschiedene Funktionen für verschiedene Ansichten hinzufügen? Dies ist mein Controller:Hinzufügen von Metadaten zu einer Codeigniter-Ansicht von einem Controller aus

<?php 
class home extends CI_Controller { 



    function index() 
    { 
       $data['meta_title'] = 'Tracenow | iOS Version'; 
       $data['meta_description'] = 'Responsive HTML5 Theme in iOS Style'; 
       $data['meta_keywords'] = 'responsive html5 theme, ios, android, material design, landing, application, mobile, blog, portfolio, bootstrap 3, css, jquery, flat, modern'; 
       $data['meta_author'] = '8Guild'; 
       $data['meta_viewport'] = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no'; 
     $this->load->view('home_page/home_page'); 


    } 

     function about() 
    { 
     $this->load->view('home_page/about'); 

    } 

     function blog() 
    { 
     $this->load->view('home_page/blog'); 

    } 

     function blog_single() 
    { 
     $this->load->view('home_page/blog-single'); 

    } 


} 
?> 
+0

Gibt es eine Möglichkeit, dies auf eine andere Weise zu tun? – Priya2026

Antwort

0
For this you can simply use this in your controller: 

$data['meta_title'] = 'Your meta title'; 
$data['meta_description'] = 'Your meta description'; 
$data['meta_keywords'] = 'Your meta keywords'; 

And you view should be like: 

<title><?php echo $meta_title; ?></title> 
<meta name="description" content="<?php echo $meta_description; ?>" /> 
<meta name="keywords" content="<?php echo $meta_keywords; ?>" /> 

Hoffentlich wird es Ihnen helfen. oder wenn Sie Hilfe benötigen, bitte unten kommentieren.

+0

Wenn ich diesen Code in die Index-Funktion hinzufügen funktioniert es nicht – Priya2026

+0

Bitte zeigen Sie mir Ihren Controller –

+0

wo meinen Code hinzufügen? – Priya2026

0

auf dem Controller

$data['metas'] = array(
      array('name'=>'description', 'content'=>'A short but sweet DEFAULT description of this fine site'), 
      array('name' =>'keywords', 'content'=>'some awesome DEFAULT keywords for those rascally web crawlers') 
    ); 

Auf Ihrer Ansicht

<?php 
     foreach($metas as $meta) 
     {?> 
     <meta name="<?=$meta['name']?>" content="<?=$meta['content']?>" /> 
<?php }?> 
0
class Home extends CI_Controller{ 
    public function __construct(){ 
     parent::__construct(); 
     $this->load->helper('html'); //Load global helper 'html' 
    } 
[...] 
//in controller: meta tag 
$meta = array(
     array(
       'name' => 'robots', 
       'content' => 'no-cache' 
     ), 
     array(
       'name' => 'description', 
       'content' => 'My Great Site' 
     ), 
     array(
       'name' => 'keywords', 
       'content' => 'love, passion, intrigue, deception' 
     ), 
     array(
       'name' => 'robots', 
       'content' => 'no-cache' 
     ), 
     array(
       'name' => 'Content-type', 
       'content' => 'text/html; charset=utf-8', 'type' => 'equiv' 
     ) 
); 

//HTML 
<!DOCTYPE html> 
<head> 
    <title></title> 
    <?= meta($meta) ?> //use helper HTML to show meta tag 
</head> 
// Generates: 
// <meta name="robots" content="no-cache" /> 
// <meta name="description" content="My Great Site" /> 
// <meta name="keywords" content="love, passion, intrigue, deception" /> 
// <meta name="robots" content="no-cache" /> 
// <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> 

Font:https://codeigniter.com/userguide3/helpers/html_helper.html?highlight=helper