Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8657511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:32:18+00:00 2026-06-12T15:32:18+00:00

I have a very simple class that derives off of the example Say class

  • 0

I have a very simple class that derives off of the example “Say” class given on the Restler website. It is as follows:

 <?php
class Say {
  function hello($to='world') {
    return "Hello $to!";
  }
  function hi($to) {
    return  "Hi $to!";
  }

  function nothing($to='the ground') {
    return "Looks at {$to} quietly but without saying a word.";
  }
}

Because the “hi” function does NOT have a default value for the $to variable it largely works as it should:

http://localhost/api/say/hi/Jack

returns

Hi Jack!

Great. The problem is when you have a default value like the “hello” or “nothing” functions then it seems you can’t pass in the parameter anymore:

http://localhost/api/say/hello          -- WORKS, returns "Hello world!"
http://localhost/api/say/hello/Jack     -- FAILS, returns a JSON error of 404

Any help would be greatly appreciated.

On a side note, I also noticed that if you don’t use a parameter with “hi” (which requires that $to be set to something) that it returns a 404 error as well. I’m not sure if that’s expected behaviour but it seems like the wrong error message for this kind of error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:32:20+00:00Added an answer on June 12, 2026 at 3:32 pm

    Restler 2 worked exactly like you expect, for the above hello method it generates the following routes

    GET say/hello      ⇠ Say::hello()
    GET say/hello/{to} ⇠ Say::hello()
    

    But Restler 3 only makes one route

    GET say/hello   ⇠ Say::hello()
    

    This is happening because of smart routing, where we do not map optional parameters to url, so optional parameters can be passed as a query string

    In the case of hi method Restler 2 routes it as

    GET say/hi      ⇠ Say::hi()
    GET say/hi/{to} ⇠ Say::hi()
    

    Where as Restler 3

    GET say/hi/{to} ⇠ Say::hi()
    

    Thus making say/hi to fail as the required parameter is missing

    Reason for doing this is to avoid ambiguity. It is explained here in the routing example

    If you want Restler 2 behaviour for all you API in Restler 3 add the following to index.php

    Defaults::$smartAutoRouting = false;
    

    If you just want to turn off smart auto routing at method level or class level, add the following php doc comment

    @smart-auto-routing false
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a very simple PrototypeJS class that looks like this: var
So I have a very simple class that has a method called getThumbUrl() but
i'm missing something fundamental here. i have a very simple custom class that draws
I have a class that uses org.apache.ant and the class is very simple, it's
I have a very simple javascript class that does an ajax call to a
Let's say we have very simple Java class MyClass . public class MyClass {
I have a class that generates a text file. It is very simple class
I have a class that is meant to be a very simple in-game level
I have a very simple template class that allows me to set some values
I have a very simple class named person which is given below , I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.