Closed giammbo closed 8 years ago
Hello, your $login
variable is not the same as your $app
variable.
As the error message suggests, your login var is an instance of ControllerCollection
class, it is not an Application
or a Pimple
one.
You have to use $app instead of $login in your controller function
$login->post('/apiv1/user/login', function (Request $request) use ($app) {
$userinfo = array(
'email' => $request->request->get('email'),
'mode' => $request->request->get('mode'),
'password' => $request->request->get('password'),
);
$passwordcoding = sha1($userinfo['email']."66643asd");
$emailverification = "SELECT email,password FROM user WHERE email='".$userinfo['email']."'";
$selectemail = $app['db']->$fetchAll('SELECT * FROM user');
});
i have changed the second file (login.php) like this: <?php $app = $app['controllers_factory']; $app->post('/', function (Request $request) use ($app) { $userinfo = array( 'email' => $request->request->get('email'), 'mode' => $request->request->get('mode'), 'password' => $request->request->get('password'), ); $passwordcoding = sha1($userinfo['email']."66643asd"); $emailverification = "SELECT email,password FROM user WHERE email='".$userinfo['email']."'"; $selectemail = $app['db']->$fetchAll('SELECT * FROM user'); var_dump($emailverification); }); return $app;
and now i receive this error:
[Sun Jan 17 05:01:27 2016] [error] [client 192.168.13.1] PHP Warning: Missing argument 1 for Silex\\Route::run() in /mnt/hgfs/Share_Folder/frontend/vendor/silex/silex/src/Silex/Route.php on line 51
[Sun Jan 17 05:01:27 2016] [error] [client 192.168.13.1] PHP Notice: Undefined variable: to in /mnt/hgfs/Share_Folder/frontend/vendor/silex/silex/src/Silex/Route.php on line 53
[Sun Jan 17 05:01:27 2016] [error] [client 192.168.13.1] PHP Warning: Missing argument 1 for Silex\\Route::run() in /mnt/hgfs/Share_Folder/frontend/vendor/silex/silex/src/Silex/Route.php on line 51
[Sun Jan 17 05:01:27 2016] [error] [client 192.168.13.1] PHP Notice: Undefined variable: to in /mnt/hgfs/Share_Folder/frontend/vendor/silex/silex/src/Silex/Route.php on line 53
$app = $app['controllers_factory'];
This is wrong, you are overriding your app variable.
Use $app variable only inside your controller function (use $app as a container), and for your factory creation. Use $login to create your route.
$login= $app['controllers_factory'];
$login->post('/', function (Request $request) use ($app) {
$userinfo = array(
'email' => $request->request->get('email'),
'mode' => $request->request->get('mode'),
'password' => $request->request->get('password'),
);
$passwordcoding = sha1($userinfo['email']."66643asd");
$emailverification = "SELECT email,password FROM user WHERE email='".$userinfo['email']."'";
$selectemail = $app['db']->$fetchAll('SELECT * FROM user');
var_dump($emailverification);
});
return $login;
ok works but, now the app.php have this code:
$app->mount('/', include __DIR__.'/login.php');
and the in the login.php
use Symfony\Component\HttpFoundation\Request;<-- i needed to add this
$login->post('/apiv1/user/login', function (Request $request) use ($app) {
in the documentation it's write like this: app.php
$app->mount('/apiv1/user/login', include __DIR__.'/login.php');
login.php
$login->post('/', function (Request $request) use ($app) {
but if i write like the documentation i recieve a 404 only on a post request the get works fine.why?
Because the "post" in "$login->post()" sets the allowed method for that route to POST. The documentation explains this pretty well: http://silex.sensiolabs.org/doc/usage.html#routing
PS. imo you are misusing this issue tracker as a method to get help on implementation. I suggest you read the documentation carefully and join us on freenode irc in channel #silex-php if you have some more implementation questions. We are happy to help you :)
ok thanks. you can close this issue
Can someone close this issue?
Hi im using silex php framework,
i have 2 file:
the first is the app.php with this:
and the second is the login.php:
when i run the select on db i receive this error:
solutions?
and the second questions is why if i change in app.php from this
to this:
and in the login.php
like the silex documentation, the framework doesnt works??
thanks.