class breadcrumbs สำหรับไว้บอกเส้นทาง ของหน้าเว็บว่าตอนนี้เราอยู่ที่เนื้อหาที่ไห

PHP Result Center PHP Result Center เป็นหมวด ที่ไว้รวบรวม โปรแกรม Code php Javascript CSS CMS

Moderator: mindphp, ผู้ดูแลกระดาน

ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41232
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

class breadcrumbs สำหรับไว้บอกเส้นทาง ของหน้าเว็บว่าตอนนี้เราอยู่ที่เนื้อหาที่ไห

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

class breadcrumbs สำหรับไว้บอกเส้นทาง ของหน้าเว็บว่าตอนนี้เราอยู่ที่เนื้อหาที่ไหน
ตัอวย่าง หน้าเว็บบอร์ด » Result Center » Free PHP Code Download script
จะมีลิงค์กลับไปที่ หมวดหลักของแต่ละลิงค์ หรือออกไปที่หน้าหลักของเว็บ เช่น home
หรือตามตัวยอย่างนี้ หน้าหลักจะเป็น หน้าเว็บบอร์ด
breadcrumbs

โค้ด: เลือกทั้งหมด

<?php
/**
 *
 * @Create Breadcrumbs Trail.
 *
 * @copyright Copyright (C) 2008 PHPRO.ORG. All rights reserved.
 *
 * @version //autogentag//
 *
 * @license new bsd http://www.opensource.org/licenses/bsd-license.php
 *
 * @filesource
 *
 * @package Breadcrumbs
 *
 * @Author Kevin Waterson
 *
 */

class breadcrumbs{

    /*
     * @string $breadcrumbs
     */
    public $breadcrumbs;

    /*
     * @string $pointer
     */
    private $pointer = '&raquo;';

    /*
     * @string $url
     */
    private $url;

    /*
     * @array $parts
     */
    private $parts;


    /*
     * @constructor - duh
     *
     * @access public
     *
     */
    public function __construct()
    {
        $this->setParts();
        $this->setURL();
        $this->breadcrumbs = '<a href="'.$this->url.'">Home</a>';
    }


    /*
     *
     * @set the base url
     *
     * @access private
     *
     */
    private function setURL()
    {
        $protocol = $_SERVER["SERVER_PROTOCOL"]=='HTTP/1.1' ? 'http' : 'https';
        $this->url = $protocol.'://'.$_SERVER['HTTP_HOST'];
    }


    /*
     * @set the pointer 
     *
     * @access public
     *
     * @param string $pointer
     * 
     */
    public function setPointer($pointer)
    {
        $this->pointer = $pointer;
    }


    /**
     *
     * @set the path array
     *
     * @access private
     *
     * @return array
     *
     */
    private function setParts()
    {
        $parts = explode('/', $_SERVER['REQUEST_URI']);
        array_pop($parts);
        array_shift($parts);
    $this->parts = $parts;
    }


    /**
     *
     * @create the breadcrumbs
     *
     * @access public
     *
      */
    public function crumbs()
    {
        foreach($this->parts as $part)
        {
            $this->url .= "/$part";
            $this->breadcrumbs .= " $this->pointer ".'<a href="'.$this->url.'">'.$part.'</a>';
        }
    }

} /*** end of class ***/

?>
ตัวอย่างการใช้งาน

โค้ด: เลือกทั้งหมด

<?php

/*** a new breadcrumbs object ***/
$bc = new breadcrumbs;

/*** set the pointer if you like ***/
$bc->setPointer('->');

/*** create the trail ***/
$bc->crumbs();

/*** output ***/
echo $bc->breadcrumbs;

?>
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 44