2015-09-05 63 views
1

我想以下this答案笨 - 站點地圖錯誤

這裏創建我笨的應用程序的站點地圖是我的控制器方法:

public function siteMap() { 

    $this->load->helper('url'); 

    $urls = array("test"); 

    $data['urls'] = $urls; 
    $data['frontend'] = $this->getFronendItems(); 

    $this->load->template('front/site_map.php', $data); 

} 

而我的觀點:

<?php header('Content-type: text/xml'); ?> 
<?= '<?xml version="1.0" encoding="UTF-8" ?>' ?> 

<url> 
    <loc><?= base_url() ?></loc> 
    <priority>1.0</priority> 
</url> 

<?php foreach($urls as $url) { ?> 
<url> 
    <loc><?= base_url() . $url ?></loc> 
    <priority>0.5</priority> 
</url> 
<?php } ?> 

這引起以下錯誤:

This page contains the following errors:

error on line 41 at column 8: Opening and ending tag mismatch: link line 0 and head

試圖刪除標題和URL只是呼應在屏幕上的字符串。我究竟做錯了什麼 ?

回答

0

您應該始終在任何視圖文件上方放置一個標頭,通常我將其放置在控制器方法的頂部。

public function siteMap() { 
    header("Content-Type: text/xml;charset=iso-8859-1"); 

    $this->load->helper('url'); 

    $urls = array("test"); 

    $data['urls'] = $urls; 
    $data['frontend'] = $this->getFronendItems(); 

    $this->load->template('front/site_map.php', $data); 

} 
在視圖文件

,添加

<?php print '<?xml version="1.0" encoding="utf-8"?>';?> 
<?php print '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';?> 

<url> 
    <loc><?=base_url()?></loc> 
    <priority>1.0</priority> 
</url> 

<?php foreach($urls as $url) { 
    ?> 
    <url> 
     <loc><?=base_url().$url?></loc> 
     <priority>0.5</priority> 
    </url> 
    <?php 
} 
?> 

<?php print '</urlset>';?> 

這是我究竟該怎麼辦我的地圖。

+0

仍然收到相同的錯誤:(我使用模板,因爲我有共同的頁眉和頁腳的所有意見 – stackUnderflow

+0

什麼是第41行第8列的頁面? – timothymarois