Viewed   165 times

I think this script is of big interest to any noob around here :) including me :)

What I want to create is a little code that I can use in any file and will generate a breadcrumb like this:

If the file is called "website.com/templates/index.php" the breadcrumb should show:

Website.com > Templates

 ^^ link                    ^^plain text

If the file is called "website.com/templates/template_some_name.php" the breadcrumb should show:

Website.com > Templates > Template Some Name

 ^^ link                   ^^link                ^^plain text

 Answers

3

Hmm, from the examples you gave it seems like "$_SERVER['REQUEST_URI']" and the explode() function could help you. You could use explode to break up the URL following the domain name into an array, separating it at each forward-slash.

As a very basic example, something like this could be implemented:

$crumbs = explode("/",$_SERVER["REQUEST_URI"]);
foreach($crumbs as $crumb){
    echo ucfirst(str_replace(array(".php","_"),array(""," "),$crumb) . ' ');
}
Thursday, August 25, 2022
3

Not possible. Namespaces, imports and aliases are resolved at compile time.

However, it is possible to create objects from a class name that is built at runtime:

$className = "common\components\cfoBi\i18n\{$countryCode}\gimmea";

$object = new $className();

See PHP docs: http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.new

Saturday, August 6, 2022
 
2

I think you need to use __FILE__ (it has two underscores at the start and at the end of the name) and DIRECTORY_SEPARATOR constants for working with files based on the current file path.

For example:

<?php
  // in this var you will get the absolute file path of the current file
  $current_file_path = dirname(__FILE__);
  // with the next line we will include the 'somefile.php'
  // which based in the upper directory to the current path
  include(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'somefile.php');

Using DIRECTORY_SEPARATOR constant is more safe than using "/" (or "") symbols, because Windows and *nix directory separators are different and your interpretator will use proper value on the different platforms.

Wednesday, November 23, 2022
2
DECLARE @sql NVARCHAR(255);

DECLARE @toStart INT;

SET @sql = N'SELECT @toStart = COUNT(ID) FROM ' + QUOTENAME(@tempTableName);

EXEC sp_executesql @sql, N'@toStart INT OUTPUT', @toStart OUTPUT;

PRINT @toStart;

However there is a much easier and more efficient way to do this, if you're okay with ignoring current in-flight transactions (and you're using SQL Server 2005 or better - please specify the version when asking questions!).

DECLARE @toStart INT;

SELECT @toStart = SUM(rows) 
  FROM sys.partitions
  WHERE [object_id] = OBJECT_ID(@tempTableName)
  AND index_id IN (0,1);

PRINT @toStart;

Just for completeness, here is a solution for SQL Server 2000, which also doesn't require any special privileges (just connect and member of public):

DECLARE @toStart INT;

SELECT @toStart = [rows] 
  FROM sysindexes
  WHERE id = OBJECT_ID(@tempTableName)
  AND indid IN (0,1);

PRINT @toStart;

That said, if you're using a count to determine what the next ID might be, or something like that, I think you're approaching this the wrong way, since rows can be deleted and if it's an identity column values can be skipped due to rollbacks.

Sunday, October 2, 2022
1

BreadCrumb as a model in attribute. This one serves to create menuitem dynamically like this example for MenuBar from Primefaces Documentation (Of course, you have to adapt this one for BreadCrumb):

public class MenuBean {
    private MenuModel model;

    public MenuBean() {
        model = new DefaultMenuModel();
        // First submenu
        DefaultSubMenu firstSubmenu = new DefaultSubMenu("Dynamic Submenu");
        DefaultMenuItem item = new DefaultMenuItem("External");
        item.setUrl("http://www.primefaces.org");
        item.setIcon("ui-icon-home");
        firstSubmenu.addElement(item);
        model.addElement(firstSubmenu);
        // Second submenu
        DefaultSubMenu secondSubmenu = new DefaultSubMenu("Dynamic Actions");
        item = new DefaultMenuItem("Save");
        item.setIcon("ui-icon-disk");
        item.setCommand("#{menuBean.save}");
        item.setUpdate("messages");
        secondSubmenu.addElement(item);
        item = new DefaultMenuItem("Delete");
        item.setIcon("ui-icon-close");
        item.setCommand("#{menuBean.delete}");
        item.setAjax(false);
        secondSubmenu.addElement(item);
        item = new DefaultMenuItem("Redirect");
        item.setIcon("ui-icon-search");
        item.setCommand("#{menuBean.redirect}");
        secondSubmenu.addElement(item);
        model.addElement(secondSubmenu);
    }

    public MenuModel getModel() {
        return model;
    }
}

After this you have just to call the model like this inside your breadcrumb :

model="#{menuBean.model}" 
Tuesday, October 25, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :