I’m attempting to make an API type app in Symfony 1.4. My goal is to accept a username/password combination, retrieving the object based upon the provided query parameters.
Here’s what I’ve got set up for my route:
login:
url: /user/login
class: sfDoctrineRoute
options: { model: User, type: object }
param: { module: user, action: login }
requirements:
sf_method: post
username: .+
password: .+
In my executeLogin() method, when I call $this->getRoute()->getObject(), it always returns the first object from the table, regardless of what values I pass in the POST data for username and password. (I also attempted doing a GET in the query string with sf_format set to “get” above, and had the same results.)
I did some digging and found that ultimately it is the getObjectsForParameters($parameters) method of sfDoctrineRoute that is being called. The query is performed based upon the array keys/values in the $parameters array (only for those keys with matching column names in the table). However, regardless of me calling the URL with parameter values for username and password, the value of $parameters here always equals:
Array (
'module' => 'user',
'action' => 'login'
)
If I change the url value to something like “/user/login/:username/:password”, I no longer have this issue: the $parameters array then includes the username/password data as expected. However, I don’t want to include these pieces of data in the URL. Any advice is appreciated.
Only get data is used with the routes. It makes sense if you think about it. Only get variables are part of the URL.
You could include login in the URL. Object would be retrieved by login and the only additional thing you would need to do is to check if password is correct.
In most cases sfDoctrineGuardPlugin is more than enough for handling profile related features, including logging in. Even if you don’t want to use it grab its source code and see how it works. It’ll help you a lot.