Object view with routing

Define / Create / Use Object-Classes, Fieldcollections, Object-Bricks, Variants, Inheritance, Custom Fields, ...

Object view with routing

Postby twalzer » Wed May 30, 2012 4:25 pm

Hello ,
could someone help me or give me the right links?
I want to make an objectview , I know I have/could do these with static routing

Url is like:

/produkte/(subkategorie/)*/productnr

RegEx like this : |/produkte/{(a-z)^/}(.*) | ?
and how do I add an view to the controller/action ?

Greetings Thomas
Last edited by twalzer on Tue Jun 12, 2012 2:10 pm, edited 1 time in total.
twalzer
 
Posts: 15
Joined: Thu May 10, 2012 10:26 am

Re: Object view with routing

Postby johan.lindgren@ateles.se » Wed May 30, 2012 10:37 pm

Hi,


if you create a static route

Code: Select all
name: product
pattern: /\/produkte\/(.*)\/(.*)/
reverse: /produkte/%s/%s
controller: product
action: default
variables: subkategorie,productnr


you will for example get the url "/produkte/foo/bar" forwarded to the "default" action in the "product" controller.

In that action you could expect to see the parameters "subkategorie" with value "foo" and "productnr" with value "bar".

Below is a working controller (if we asume that we in this example mean that this url should view an object with path "/products/foo/bar").


Code: Select all
<?php
class ProductController extends Website_Controller_Action {
        public function defaultAction () {

                $productnr = $this->_getParam("productnr");

                $subkategorie = $this->_getParam("subkategorie");


                $this->view->product = Object_Abstract::getByPath("/products/".$subkategorie."/".$productnr)

                $this->enableLayout();

        }

}



Note that there is also a nice url helper to help you to create the url

Code: Select all

<?php echo $this->url(array("foo","bar"),"product") ?>



will create a valid url "/produkte/foo/bar".



Please check the docs on

http://www.pimcore.org/wiki/display/PIM ... +Routes%29


Another way is to install the 1.4.2 demo found in the download archive and checkout the NewsController...


Cheers,

Johan
---------------------------------------------------------------------
Ateles Consulting AB - a Pimcore Professional Partner
User avatar
johan.lindgren@ateles.se
Community Support
 
Posts: 468
Joined: Fri Apr 27, 2012 8:18 am
Location: Sweden

Re: Object view with routing

Postby twalzer » Tue Jun 12, 2012 10:21 am

Thanks for you answer it helped.I learn every day a bit more about pimcore and like it more and more ,but I just did one mistake I have /products then 1-3 "folder" and then the productnr

e.g.

/products/foo/12234234

/products/foo/bar/12234234

so is it possible ??
twalzer
 
Posts: 15
Joined: Thu May 10, 2012 10:26 am

Re: Object view with routing

Postby rafalgalka » Tue Jun 12, 2012 1:29 pm

I have similar issue. I'm building blog plugin for pimcore and I wan't to allow unlimited nesting of object directories.

I created static route:
Code: Select all
name: blog-show
pattern: |^/blog/entry/([-_/\w]+)|
reverse: /blog/entry/%key/
module: Blog
controller: entry
action: default
variables: key

Now I want to pass full object path (without blog entries root directory) to url view helper:
Code: Select all
<?=$this->url(array('key' => str_replace('/blog/', '', $entry->getFullPath())), 'blog-show')?>

But this won't work without modification of Staticroute::assemble() becouse urlencode() is used and "/" is forbidden character.

I think that unconditional usage of urlencode() is a bug. It should be called only when $encode == true, just like in Zend_Controller_Router_Route.
And I don't know why "/" is in $forbiddenCharacters = array("#","/",":","?");, it's regular path separator and should be acceptable, I think.
rafalgalka
 
Posts: 8
Joined: Wed Dec 28, 2011 5:30 pm

Re: Object view with routing

Postby johan.lindgren@ateles.se » Tue Jun 12, 2012 10:14 pm

Hi,

one way might be to use the url

http://pimcore.tintin.ateles.se/blog-one-two-three-four

to view object with path "/one/two/three/four"

With a connfig like this one

name: blog
pattern: /\/blog(.*)/
reverse: /blog%path
variables: path

and controller code like this picking up the path and replacing all "-" with "I"

$path = str_replace("-","/",$this->_getParam("path"));

When creating the urls we "encode" it the oter way around and replaces "/" with "-"

$this->url(array("path" => str_replace("/","-", $path),"blog");


Not exactly what you where asking for, but quite a good workaround :-)

/Johan
---------------------------------------------------------------------
Ateles Consulting AB - a Pimcore Professional Partner
User avatar
johan.lindgren@ateles.se
Community Support
 
Posts: 468
Joined: Fri Apr 27, 2012 8:18 am
Location: Sweden

Re: Object view with routing

Postby rafalgalka » Wed Jun 13, 2012 9:50 am

johan.lindgren@ateles.se wrote:Hi,

one way might be to use the url

http://pimcore.tintin.ateles.se/blog-one-two-three-four

to view object with path "/one/two/three/four"

/Johan


I was thinking about this. But this won't work for /one/two-some/three/four :(

PS: I created pull requests and problem is now solved, see:
https://github.com/pimcore/pimcore/pull/25
https://github.com/pimcore/pimcore/pull/26
rafalgalka
 
Posts: 8
Joined: Wed Dec 28, 2011 5:30 pm

Re: Object view with routing

Postby johan.lindgren@ateles.se » Wed Jun 13, 2012 7:41 pm

Ok, thats even better :-)

/Johan
---------------------------------------------------------------------
Ateles Consulting AB - a Pimcore Professional Partner
User avatar
johan.lindgren@ateles.se
Community Support
 
Posts: 468
Joined: Fri Apr 27, 2012 8:18 am
Location: Sweden


Return to Objects

Who is online

Users browsing this forum: No registered users and 0 guests