Suppose we want to check if a user is valid or not, for that we need user name and password, here we are using symfony.
public function executeValidateUser(sfWebRequest $request){ $username = $request -> getParameter("username"); $password = $request -> getParameter("password"); $query = Doctrine_Query::create() ->select("id") ->from("user") ->where("username=$username") ->andWhere("password=$password"); $rowcount= $query -> count(); if( $rowcount == 1 ){ //do something useful, User Authenticated } else{ // do something useful here too even thoug User is Not Authenticated :) } }
here we first get the $username and $passowrd from the form submitted using symfony $request->getParamenter() method then we make a Doctrine query and then we check how many results are returned by the Doctrine Query using Doctrine count() method and lastly we check if it is exactly 1 which mean user name and password is correct and user is a valid user if not then the else part work.
1 comments:
Missing execute() function for the $query object!
Post a Comment