Snippets

Create an account or login to be able to add, comment and rate snippets.

Navigation

Snippets by user brikou Snippets by user brikou

baseurl_for with an external application

Here is a usefull helper to calculate url for another application :

function baseurl_for($application, $absolute = false)
{
    $url = $absolute ? 'http://' . $_SERVER["HTTP_HOST"] : '';
    $url .= '/' . $application . (SF_ENVIRONMENT != 'prod' ? '_' . SF_ENVIRONMENT : '') . '.php/';
    return $url;
}

in the action :

<?php echo link_to('Whatever', baseurl_for('application', true) . 'module/action') ?>

I really feel like this feature is missing, hope this could added soon ;) ... example corrected (but sadly not so usefull) according to francois's comment.

by brikou on 2006-11-24, tagged application  base  helper  url 
(3 comments)

Minimal CSS pagination helper

This is helper is mostly inspired by Pagination navigation helper, but there are some differences:

PaginationHelper.php

function pagination($pager)
{
    $uri = sfRouting :: getInstance()->getCurrentInternalUri();
    $html = '';
 
    if ($pager->haveToPaginate())
    {
        $uri .= strstr($uri, '?') ? '&page=' : '?page=';
 
        if ($pager->getPage() != 1)
        {
            $html .= '<li>' . link_to('first', $uri . '1') . '</li>';
            $html .= '<li>' . link_to('previous', $uri . $pager->getPreviousPage()) . '</li>';
        }
 
        foreach ($pager->getLinks() as $page)
        {
            if ($page == $pager->getPage())
                $html .= '<li><strong>' . link_to($page, $uri . $page) . '</strong></li>';
            else
                $html .= '<li>' . link_to($page, $uri . $page) . '</li>';
        }
 
        if ($pager->getPage() != $pager->getLastPage())
        {
            $html .= '<li>' . link_to('next', $uri . $pager->getNextPage()) . '</li>';
            $html .= '<li>' . link_to('last', $uri . $pager->getLastPage()) . '</li>';
        }
 
        $html = '<ul class="pagination">' . $html . '</ul>';
    }
 
    return $html;
}

Minimal CSS

ul.pagination li {
    display: inline;
    list-style-type: none;
    padding-right: 1em;
}

In your template

<?php echo use_helper('Pagination') ?>
<?php echo pagination($pager) ?>
by brikou on 2006-07-19, tagged css  helper  pager  pagination  propel 
(5 comments)

Debug an object or variable (easy way)

This in the easiest way (I found) to debug an object (or variable).

In an action

$this->debugMessage(sprintf('<h1>object</h1><pre>%s</pre>', print_r(@$this->object, true)));

In a template

<?php use_helper('Debug') ?>
<?php echo debug_message(sprintf('<h1>object</h1><pre>%s</pre>', print_r(@$object, true))) ?>

Based on symfony book debug page.

by brikou on 2006-06-24, tagged debug  object 
(1 comment)