PHP code example of axis / axis-curly-routing-plugin

1. Go to this page and download the library: Download axis/axis-curly-routing-plugin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

axis / axis-curly-routing-plugin example snippets


 echo url_for('curly_route', array('name' => 'world')) 

 echo url_for('blog_post', $post) 

class blogActions extends sfActions
{
  public function executeShowPost($request)
  {
    $post = $this->getRoute()->getObject();
  }
}

 echo url_for('blog_post', array('post' => $post, 'username' => 'anonymous')) 

class blogActions extends sfActions
{
  public function executeShowPost($request)
  {
    $post = $this->getRoute()->getObject('post');
  }
}

show_product:
  url: /shop/{category.path}/{product.slug}-{product.id}.html
  param: { ... }
  class: CurlyObjectRoute
  options:
    transform:
      product:
        model: Product
        query_methods: [ filterPublished, filterInStock ]
      # or you can use short syntax if there is only model option for a namespace
      category: Category
  

 echo url_for('show_product', array('category' => $category, 'product' => $product)) 

class shopActions extends sfActions
{
  public function executeShowProduct($request)
  {
    /** @var $category Category */
    $category = $this->getRoute()->getObject('category');
    /** @var $product Product */
    $product = $this->getRoute()->getObject('product');
  }
}

class myProjectWeirdRouteVarTransformer implements \Axis\S1\CurlyRouting\Transformer\DataTransformerInterface
{
  public function transformForUrl($params, $variables, $options = array())
  {
    $params['weird_word'] = 'foo'.$params['word'].'bar'
    unset($params['word']);
    return $params;
  }

  public function transformForController($params, $variables, $options = array())
  {
    $weird = $params['weird_word'];
    if (substr($weird, 0, 3) == 'foo') $weird = substr($weird, 3);
    if (substr($weird, -3) == 'bar') $weird = substr($weird, 0, -3);

    unset($params['weird_word']);
    $params['word'] = $weird;
    return $params;
  }
}

This code:
 echo url_for('weird_route', array('word' => 'hello')) 

class weirdActions extends sfActions
{
  public function executeSay($request)
  {
    $this->renderText($request['word']); // this will output 'hello'
  }
}