Quantcast

underscore in URL

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

underscore in URL

ashish.sharma
Hello Everybody, I would like to know that can we use underscores in URL (specially in controller & action) like can we have a URL like .. Http://localhost/my_application/my_module/my_controller/my_action As ZF removes underscores from the controller and action automatically. Do we have any alternative / solution for this, so that we can use underscores in controller and action name. looking for your suggestion ... Ashish
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: underscore in URL

weierophinney
Administrator
-- ashish.sharma <[hidden email]> wrote
(on Sunday, 10 February 2008, 11:27 PM -0800):
> Hello Everybody, I would like to know that can we use underscores in URL
> (specially in controller & action) like can we have a URL like .. Http://
> localhost/my_application/my_module/my_controller/my_action As ZF removes
> underscores from the controller and action automatically. Do we have any
> alternative / solution for this, so that we can use underscores in controller
> and action name. looking for your suggestion ... Ashish

Currently, there are two rules in play:

 * When referring to controllers, underscores are used to indicate that
   the controller lives in a subdirectory. In your example,
   'my_controller' refers to a module living in
   'My/ControllerController.php' in the module directory.

 * When referring to modules and actions, underscores are one of three
   "word separators". Within the dispatcher, these are transliterated
   such that the words are camelCased and smashedTogether. In your
   examples, my_module becomes myModule, and my_action becomes
   myActionAction().

You can alter these within the dispatcher pretty easily by calling the
setPathDelimiter() and setWordDelimiter() methods of the dispatcher.
From your bootstrap, try the following:

    $dispatcher = $front->getDispatcher();
    $dispatcher->setWordDelimiter(array('.', '-'))
               ->setPathDelimiter('');

The above sets the word delimiters to solely the '.' and '-' characters,
and effectively disables path delimiters.

--
Matthew Weier O'Phinney
PHP Developer            | [hidden email]
Zend - The PHP Company   | http://www.zend.com/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: underscore in URL

tkuben
Hi,

I am trying to create a controller with an underscore. I've added the specified code to my bootstrap:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

    protected function _initDoctype()
    {
    $dispatcher = $front->getDispatcher();
    $dispatcher->setWordDelimiter(array('.', '-'))->setPathDelimiter('');        
    }
}

However, when I do the following:  zf create controller press_release

I still get Note:
PHPUnit is required in order to generate controller test stubs.
                          An Error Has Occurred
 Controller names should be camel cased.

Zend Framework Command Line Console Tool v1.11.4
Details for action "Create" and provider "Controller"
  Controller
    zf create controller name index-action-included[=1] module

Any thoughts.

Thanks.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: underscore in URL

Petar Dzhambazov
I don't know how much this will help, but what you set in your bootstrap
has nothing to do with zend tool.
Zend tool operates according its own providers and does not take any
insight from your application

You can try to create the controller manually but I think you will have
only headache if you use underscore in its actual name.

You are better off with using routes to point underscore links to
correct controllers.

regards
Petar

On 03/08/2011 06:53 PM, tkuben wrote:

> Hi,
>
> I am trying to create a controller with an underscore. I've added the
> specified code to my bootstrap:
>
> class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
> {
>
>      protected function _initDoctype()
>      {
>       $dispatcher = $front->getDispatcher();
>       $dispatcher->setWordDelimiter(array('.', '-'))->setPathDelimiter('');
>      }
> }
>
> However, when I do the following:  zf create controller press_release
>
> I still get Note:
> PHPUnit is required in order to generate controller test stubs.
>                            An Error Has Occurred
>   Controller names should be camel cased.
>
> Zend Framework Command Line Console Tool v1.11.4
> Details for action "Create" and provider "Controller"
>    Controller
>      zf create controller name index-action-included[=1] module
>
> Any thoughts.
>
> Thanks.
>
> --
> View this message in context: http://zend-framework-community.634137.n4.nabble.com/underscore-in-URL-tp648359p3341777.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
Loading...