Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Route incorrect when at least two Resources doesn't have prefix #26

Open
neptunezx opened this issue Mar 9, 2017 · 2 comments
Open

Comments

@neptunezx
Copy link

neptunezx commented Mar 9, 2017

if i construct two 'resource' without a prefix, then the route may incorrect. because the route name of the resource is conflict. This situation is likely to occur when i making restful design. for example:
i design three restful api:
GET http://www.***.com/users/{user_id}/orders query all orders of user {user_id}
GET http://www.***.com/orders/{order_id} query orders of {order_id}
GET http://www.***.com/orders/ query all orders
these api may designed in the some Controller and Resource, named OrderController and OrderResource.
but i can't give a prefix in the OrderResource created place.
i can only give a full path in the Endpoints created place. for example:

->handler(OrderController ::class)
->endpoint(ApiEndpoint::get('/users/{user_id}/orders', 'allOfUser'))
->endpoint(ApiEndpoint::get('/orders/{order_id} ', 'find'))
->endpoint(ApiEndpoint::get('/orders', 'all'))

the code in PhalconRest\Api\ApiCollection:

protected function createRouteName(ApiEndpoint $endpoint)
{
return serialize([
'collection' => $this->getIdentifier(),
'endpoint' => $endpoint->getIdentifier()
]);
}
public function getIdentifier()
{
return $this->getPrefix();
}
so i recommend that we can replace the getIdentifier() as follows:
public function getIdentifier()
{
return static::class . '/' . $this->getPrefix();
}

@bigoper
Copy link

bigoper commented Mar 31, 2017

Hey @neptunezx

Can you help me with #28 ?

Thanks!

@aprchen
Copy link

aprchen commented Dec 12, 2017

What attributes are protected? if yes ,you can do this
Add a get method for the property in the model,and modify the following

protected function getFieldValue($item, $propertyName, $fieldName)
    {
        $dataType = array_key_exists($propertyName,
            $this->getModelDataTypes()) ? $this->getModelDataTypes()[$propertyName] : null;
        $model = $this->getModel($item);
        if (!isset($model->$propertyName)) { // * @date 2017.12.11 * 修复 bean get
            $propertyName = 'get'.ucfirst($propertyName);
            if(!method_exists($model,$propertyName)){
                return null;
            }
            $value = $model->$propertyName();
        }else{
            $value = $model->$propertyName;
        }
        if($value === null){
            return null;
        }
        $typedValue = $value;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants