FAQ
Hi

I'm on CakePHP 2.2.x and I've built all my site links in the format...

$this->Html->link( 'Contact', array('controller' => 'pages', 'action' => 'contact'));

…which generates URLs like http://www.example.com/pages/contact and everything works. ie: /pages/contact shows my contact page.

I've then added the line…

Router::connect('/*', array('controller' => 'pages', 'action' => 'display'));

…as the last rule in my routes file and so now I can use a URL like http://www.example.com/contact (without the /pages bit) and still get my contact page. All great so far.

What I would like to do now is somehow set my links to generate the shortened URLs so $this->Html->link( 'Contact', array('controller' => 'pages', 'action' => 'contact')); generates a URL http://www.example.com/contact rather than http://www.example.com/pages/contact

Is this possible? I'm struggling to find a way to do it. If it is can someone point me to an example?

Regards

PW

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.

Search Discussions

  • Chetan Varshney at Nov 7, 2012 at 5:08 pm
    Use as following-

    In routes.php

    Router::connect('/contact', array('controller' => 'pages', 'action' =>
    'contact'));

    or

    Router::connect('/contact/*', array('controller' => 'pages', 'action' =>
    'contact'));

    and generate link as

    One way

    $this->Html->link( 'Contact', array('controller' => 'contact'));

    Other way

    <a href="<?php echo $this->Html->url('/contact'); ?>">Contact</a>


    On Wed, Nov 7, 2012 at 10:17 PM, Paul Willis wrote:

    Hi

    I'm on CakePHP 2.2.x and I've built all my site links in the format...

    $this->Html->link( 'Contact', array('controller' => 'pages', 'action' =>
    'contact'));

    …which generates URLs like http://www.example.com/pages/contact and
    everything works. ie: /pages/contact shows my contact page.

    I've then added the line…

    Router::connect('/*', array('controller' => 'pages', 'action' =>
    'display'));

    …as the last rule in my routes file and so now I can use a URL like
    http://www.example.com/contact (without the /pages bit) and still get my
    contact page. All great so far.

    What I would like to do now is somehow set my links to generate the
    shortened URLs so $this->Html->link( 'Contact', array('controller' =>
    'pages', 'action' => 'contact')); generates a URL
    http://www.example.com/contact rather than
    http://www.example.com/pages/contact

    Is this possible? I'm struggling to find a way to do it. If it is can
    someone point me to an example?

    Regards

    PW

    --
    Like Us on FaceBook https://www.facebook.com/CakePHP
    Find us on Twitter http://twitter.com/CakePHP

    ---
    You received this message because you are subscribed to the Google Groups
    "CakePHP" group.
    To post to this group, send email to cake-php@googlegroups.com.
    To unsubscribe from this group, send email to
    cake-php+unsubscribe@googlegroups.com.
    Visit this group at http://groups.google.com/group/cake-php?hl=en.


    --
    Chetan Varshney
    Ektanjali Softwares Pvt Ltd

    --
    Like Us on FaceBook https://www.facebook.com/CakePHP
    Find us on Twitter http://twitter.com/CakePHP

    ---
    You received this message because you are subscribed to the Google Groups "CakePHP" group.
    To post to this group, send email to cake-php@googlegroups.com.
    To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
    Visit this group at http://groups.google.com/group/cake-php?hl=en.
  • Jeremy Burns : Class Outfit at Nov 7, 2012 at 5:11 pm
    Try this:

    $staticPages = array(
    'contact',
    'another_page'
    );

    $staticList = implode('|', $staticPages);

    Router::connect(
    '/:static',
    array(
    'plugin' => false,
    'controller' => 'pages',
    'action' => 'display'
    ),
    array(
    'static' => $staticList,
    'pass' => array('static')
    )
    );
    On 7 Nov 2012, at 17:08, Chetan Varshney wrote:

    Use as following-

    In routes.php

    Router::connect('/contact', array('controller' => 'pages', 'action' => 'contact'));

    or

    Router::connect('/contact/*', array('controller' => 'pages', 'action' => 'contact'));

    and generate link as

    One way

    $this->Html->link( 'Contact', array('controller' => 'contact'));

    Other way

    <a href="<?php echo $this->Html->url('/contact'); ?>">Contact</a>



    On Wed, Nov 7, 2012 at 10:17 PM, Paul Willis wrote:
    Hi

    I'm on CakePHP 2.2.x and I've built all my site links in the format...

    $this->Html->link( 'Contact', array('controller' => 'pages', 'action' => 'contact'));

    …which generates URLs like http://www.example.com/pages/contact and everything works. ie: /pages/contact shows my contact page.

    I've then added the line…

    Router::connect('/*', array('controller' => 'pages', 'action' => 'display'));

    …as the last rule in my routes file and so now I can use a URL like http://www.example.com/contact (without the /pages bit) and still get my contact page. All great so far.

    What I would like to do now is somehow set my links to generate the shortened URLs so $this->Html->link( 'Contact', array('controller' => 'pages', 'action' => 'contact')); generates a URL http://www.example.com/contact rather than http://www.example.com/pages/contact

    Is this possible? I'm struggling to find a way to do it. If it is can someone point me to an example?

    Regards

    PW

    --
    Like Us on FaceBook https://www.facebook.com/CakePHP
    Find us on Twitter http://twitter.com/CakePHP

    ---
    You received this message because you are subscribed to the Google Groups "CakePHP" group.
    To post to this group, send email to cake-php@googlegroups.com.
    To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
    Visit this group at http://groups.google.com/group/cake-php?hl=en.





    --
    Chetan Varshney
    Ektanjali Softwares Pvt Ltd

    --
    Like Us on FaceBook https://www.facebook.com/CakePHP
    Find us on Twitter http://twitter.com/CakePHP

    ---
    You received this message because you are subscribed to the Google Groups "CakePHP" group.
    To post to this group, send email to cake-php@googlegroups.com.
    To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
    Visit this group at http://groups.google.com/group/cake-php?hl=en.
    --
    Like Us on FaceBook https://www.facebook.com/CakePHP
    Find us on Twitter http://twitter.com/CakePHP

    ---
    You received this message because you are subscribed to the Google Groups "CakePHP" group.
    To post to this group, send email to cake-php@googlegroups.com.
    To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
    Visit this group at http://groups.google.com/group/cake-php?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcake-php @
categoriesphp
postedNov 7, '12 at 4:48p
activeNov 7, '12 at 5:11p
posts3
users3
websitecakephp.org
irc#cakephp

People

Translate

site design / logo © 2022 Grokbase