1

I have tried all the way to make these run but no use.There is lots of problem and confusion i m going through. I have make api which return all the countries which is working fine.Now need to write api function to list all the states of perticular country.

api : http://phpserver:8090/ssn-project/newzit/api/web/state/customstate?country_id=102

StateController.php

class StateController extends ActiveController{

public $modelClass = 'api\modules\state\models\State'; 

public function actionCustomState($country_id)
{
    $model = new $this->modelClass;
    $result = $model::find()
              ->where(['country_id' => $country_id])
              ->all();
    return $result;
}  
}

main.php

'urlManager' => [
        'enablePrettyUrl' => true,
        'enableStrictParsing' => true,
        'showScriptName' => false,
        'rules' => [
            [
                'class' => 'yii\rest\UrlRule', 
                'controller' => ['country/country','state/state','category/category','seller/seller'],
                'extraPatterns' => [
                    'GET CustomState' => 'CustomState',
                ],  
            ]
        ],        
    ]

Am I doing anything wrong.Please help

2
  • Are you getting a specific error? Commented Apr 18, 2016 at 8:13
  • yes { "name": "Not Found", "message": "Page not found.", "code": 0, "status": 404, "type": "yii\\web\\NotFoundHttpException" } I am constantly facing same error Commented Apr 18, 2016 at 8:41

2 Answers 2

1

What do you mean by 'controller' => ['country/country','state/state','category/category','seller/seller'] ? This will be treated as module/controller. You have placed all controllers inside different modules? With this logic, your api url will be

http://phpserver:8090/ssn-project/newzit/api/web/state/state/customstate?country_id=102

instead of

http://phpserver:8090/ssn-project/newzit/api/web/state/customstate?country_id=102

Sign up to request clarification or add additional context in comments.

2 Comments

Have you tried either customState or custom-state as the action in the urls?
Can you show part of Yii app log? It can be helpful to solve your issue. Logs in standard Yii installation can be found in runtime/logs.
1

Found the solution. made 'pluralize'=>false and used custom-state in url My main.php

'rules' => [
            [
                'pluralize'=>false,
                'class' => 'yii\rest\UrlRule', 
                'controller' => ['country/country','state/state','category/category','seller/seller','contactus/contactus'],
                'extraPatterns' => [
                    'GET custom-state' => 'custom-state',
                ],  

            ]
        ],   

Thank you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.