I have the following controller view method for my posts:
function view($id = null)
{
$this->Portfolio->id = $id;
$this->set('posts', $this->Portfolio->read());
}
So currently I pass the id to the view and it shows a post e.g. /portfolio/view/1
However I want to use the Tiny Lib here: https://github.com/kylebragger/tiny/blob/master/tiny.php
for the set I’m using 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
The url I wish to create is e.g. driz.co.uk/portfolio/view/8az/Paperview_Magazine
So basically the 8az part is where Tiny compares the value to the ID in the database
I have created a test link e.g. <?php echo $this->Html->link($post['Portfolio']['title'], array('controller' => 'portfolio', 'action' => 'view', Inflector::slug($post['Portfolio']['title'])), array('title' => $post['Portfolio']['title'])); ?> but not added the Tiny part yet just the inflected post title.
I’ve had a guess at it’s something like the following to do this:
function view ( $tiny_id )
{
$id = $this->Tiny->reverseTiny($tiny_id);
$post = $this->Portfolio->id = $id;
$this->set('post', $this->Portfolio->read());
}
But I’m stuck with the following:
1.) How to add the Tiny value to my link so I can pass it to the controller/view as currently I’m just passing the inflected URL and not the post id or tiny id
2.) How to use the lib in my method and make sense of it to show the correct post
If anyone can help me with this it’d be much appreciated. Thanks
First, to load the Tiny library in your controller, you’ll have to use App::import. I would suggest that you copy the Tiny library in your vendors folder and then use the following in the view action:
Make sure that the file named tiny.php is in the vendors folder or it won’t work.
To generate the link, you should be able to use:
To read the post, do the following:
The reason why I’m using $id in the reverseTiny call and not $tiny_id like you posted above is because the “view” action expects the first parameter to be the $id (which is the tiny id.) The second parameter, would be the slug, which you function did not explicitly declare. You may want to change the function to: