Hy!
i am using where query and check where user is exist or not in my login system and save the data in a variable $user and then i compact this variable to my view to get the name of logged in user but the query just return in my variable 1 or 0.
what i do. how can I use model for such type of queries please guide me..
here is my little code....
$user = new user();
$user = DB::table('users')->where('name', $request->name)->first() && DB::table('users')->where('password', $request->password)->first() ;
if($user==null){
return redirect('/login');
}
return view('user.dashboard',compact('user'));
You are performing Boolean logic in that long line assigning to $user, hence the true/false you're seeing.
// using eloquent
if ( $user = User::where(['name' => $request->name, 'password' => Hash::make($request->password)])->first()) {
return view('user.dashboard',compact('user'));
}
return redirect('/login');
Related
In my config.yml I have this:
parameters:
gitek.centro_por_defecto: 1
Now, I want to change this value from my controller using a form, like this:
public function seleccionAction(Request $request)
{
$entity = new Centro();
$form = $this->createForm(new SeleccionType(), $entity);
$centro = $this->container->getParameter('gitek.centro_por_defecto');
if ($this->getRequest()->getMethod() == 'POST') {
$form->bind($this->getRequest());
if ($form->isValid()) {
$miseleccion = $request->request->get('selecciontype');
$this->container->setParameter('gitek.centro_por_defecto', $miseleccion['nombre']);
// return $this->redirect($this->generateUrl('admin_centro'));
}
}
return $this->render('BackendBundle:Centro:seleccion.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
}
I´m getting Impossible to call set() on a frozen ParameterBag. error all the time.
Any help or clue?
You can't modify Container once it has been compiled, which is done before invoking the controller.
The DIC parameters are intended for configuration purposes - not a replacement for global variables. In addition it seems you want to persist some kind of permanent modification. In that case consider using session if it's a per-user modification or persisting it (e.g. into DB) if it's supposed to be application-wide.
If you need to modify DIC parameters or services, you can do so using a compiler pass. More info on how to write custom compiler passes can be found at:
http://symfony.com/doc/master/cookbook/service_container/compiler_passes.html
You can set $_ENV variables and get that after
putenv("VAR=1");
And to get
getenv("VAR");
I am busy with a site built on Code Igniter that needs integration with Prestashop. In the site, when creating a user account, I save a "shop_id" to the database, which is then retrieved as a session variable when logging in.
I am using the Prestashop API to retrieve the customer successfully (using above "shop_id")
$xml = $this->PSWebService->get(
array('resource' => 'customers', 'id' => (int)$this->user['shop_id'])
);
This successfully returns the user in question, but there is no Cart IDs in this result.
Logging in to the back-end of my shop, I see that there are multiple carts associated with the logged in user.
My question is: How to I retrieve the LATEST cart ID using the API?
$userId = (int) $this->user['shop_id'];
$opt['resource'] = 'carts';
$xml = $this->PSWebService->get($opt);
$carts = $xml->carts->children();
foreach ($carts as $cart) {
$cartIds[] = $cart['id'];
}
for ($i = count($cartIds) - 1; $i > -1; $i--) {
$opt['id'] = $cartIds[$i];
$xml = $this->PSWebService->get($opt);
//since cart ids are descending the first found will be the latest
if ($xml->cart->id_customer == $userId) {
$latestCartId = $cartIds[$i];
break;
}
}
Kind of late, but I struggled a bit with this same problem and found a way to do it just from query, based on yenshirak's tip (since cart ids are descending the first found will be the latest).
I query the API directly using postman like this:
get all carts:
GET webserver/api/carts
get cart for customer:
GET webserver/api/carts?filter[id_customer]=1
get the most recent:
GET webserver/api/carts?filter[id_customer]=1&sort=[id_DESC]&limit=1
for a pretty print, you can also add params:
display=full&output_format=JSON
You can do this in php, I have not tested if the syntax is correct, but based on documentation it looks something like this:
$opt = array(
'resource' => 'carts',
'filter[id_customer]' => '[1]',
'sort' => '[id_DESC]',
'limit' => '1'
);
$xml = $webService->get($opt);
I'm a new guy for zendframework. i am facing zend auth join query issue..
Here I attach my zend_auth login sample code.
My login information's are stored in two tables. I mean email address in separate table and password separate. Here I was try to join my table, but I am getting Following error...
Message: The supplied parameters to Zend_Auth_Adapter_DbTable
failed to produce a valid sql statement, please check table and column
names for validity.
Please advise me.
My code is here...
$authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter());
$authAdapter->setTableName(array('users','details'))
->setIdentityColumn('name')
->setCredentialColumn('pwd');
$name = 'test';
$pwd = '123';
$authAdapter->setIdentity($name)
->setCredential($pwd);
$select = $authAdapter->getDbSelect();
$select->where('pwd = 123')
->joinLeft( array('d' => 'details'),'d.id = users.id');
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authAdapter);
Can someone explain, why I get different results?
$user = new UserEn();
$user->setName("test");
$em->persist($user);
$result1 = $em->find('UserEn', 'test');
$result2 = $em->getRepository('UserEn')->findBy(array('name'=>'test'));
$q = $em->createQuery('select u from UserEn u where u.name = :name');
$q->setParameter('name', 'test');
$result3 = $q->getResult();
Only $result1 holds $user, which is what I expected, and the others are null. What's wrong? (Please don't say that I need to call $em->flush(); )
Because Doctrine can't figure out that you are specifically requesting an User object which has name property set to test from the query, it queries the DB(ignoring caching mechanism), map resultset to entity object, load them in entity manager and return the array of entity object[s] if any data found. So there is no involvement of entity manager here. Things would be different if you used find($id) instead of findBy() because now Doctrine will check entity manager first, query DB if not found.
$result2
This returns an array that holds all entities with test as name:
$result2 = $em->getRepository('UserEn')->findBy(array('name'=>'test'));
In order to get only one record you should use findOneBy instead of findBy:
$result2 = $em->getRepository('UserEn')->findOneBy(array('name'=>'test'));
$result3
In the $result3 you should call $q->getSingleResult() instead of $q->getResult():
$result3 = $q->getSingleResult();
Hi I'm trying to extract the university of the user from their Facebook profile and found this post to be useful - Getting Education with Facebook Graph API in PHP
However, in my implementation the 'education' field is not being recognised for some reason and is throwing an error in the browser of " Undefined index: education". This is odd because the first and last name and gender are all being retrieved fine but not the 'education' field.
Does anyone know why this is happening?
My code:
// Get the app User ID
$user = $facebook->getUser();
if ($user) {
try {
// If the user has been authenticated then proceed
$user_profile = $facebook->api('/me');
// Extracting profile information to store in database
$fname = $user_profile['first_name'];
$lname = $user_profile['last_name'];
$gender = $user_profile['gender'];
$email = $user_profile['email'];
$college = null;
/* Education data is stored in an array so this iterates over
the contents of that array and checks if the entry is for "College".
*/
foreach ($user_profile['education'] as $education) { // <-ERROR HERE
if ($education['type'] == "College") {
$college = $education;
break;
}
}
}
catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
from the user education column you can read facebook users' school name, id and type. just grab the school name in a variable running fql. for further info plz check: https://developers.facebook.com/docs/reference/fql/user/