I have this error when I submit the connexion form (I use FOSUserBundle latest version) :
No encoder has been configured for account "MyApp\UtilisateurBundle\Entity\Utilisateur
here is my entity :
<?php
namespace MyApp\UtilisateurBundle\Entity;
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
*/
class Utilisateur extends BaseUser
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\generatedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
}
and here is my app/config/security.yml :
imports:
- { resource: "#MyAppFilmothequeBundle/Resources/config/security.yml" }
and here is my src/MyApp/FilmothequeBundle/Ressources/config/security.yml :
security:
providers:
fos_userbundle:
id: fos_user.user_manager
firewalls:
main:
pattern: .*
form_login:
provider: fos_userbundle
login_path: /myapp/login
use_forward: false
check_path: /myapp/login_check
failure_path: null
default_target_path: /myapp
logout:
path: /myapp/logout
target: /myapp
anonymous: true
I followed this tutorial to doing that : http://j-place.developpez.com/tutoriels/php/ameliorez-vos-applications-developpees-avec-symfony2/#LVI-B-1
How can I achieve this?
thank you in advance
Try adding this to the security key in security.yml
encoders:
FOS\UserBundle\Model\UserInterface: sha512
so it's
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
providers:
...
firewalls:
...
I was getting this error on LexikJWTAuthenticationBundle.
It helps me (config/packages/security.yaml):
security:
encoders:
App\Entity\User:
algorithm: bcrypt
You need juste add this code in the security.yml
encoders:
# use your user class name here
App\Entity\User:
# Use native password encoder
# This value auto-selects the best possible hashing algorithm
# (i.e. Sodium when available).
algorithm: auto
Im use symfony 4.4
Working for me
Related
I try writing functional tests for my controllers using Codeception testing framework. I want to replace real service in DI with fake one.
Controller code example:
<?php
namespace App\Controllers;
class IndexController extends ControllerBase
{
public function indexAction()
{
// some logic here
$service = $this->getDI()->get('myService');
$service->doSomething();
// some logic here
}
}
Test code example:
<?php
namespace App\Functional;
class IndexControllerCest
{
public function testIndexAction(FunctionalTester $I)
{
// Here i want to mock myService, replace real object that in controller with fake one
$I->amOnRoute('index.route');
}
}
I already try different combinations with Codeception Phalcon module like addServiceToContainer.
I setup Codeception using bootstrap.php file almost the same as for real app.
Phalcon version: 3.4.1
Codeception version: 3.1
So my question in last code fragment on comment section. Thank you for any help.
I would like suggest you start from creating a separated helpers to create and inject dependencies as follows:
# functional.suite.yml
class_name: FunctionalTester
modules:
enabled:
- Helper\MyService
- Phalcon:
part: services
# path to the bootstrap
bootstrap: 'app/config/bootstrap.php'
# Another modules ...
Create a separated service:
<?php
namespace Helper;
use Codeception\Module;
/** #var \Codeception\Module\Phalcon */
protected $phalcon;
class MyService extends Module
{
public function _initialize()
{
$this->phalcon = $this->getModule('Phalcon');
}
public function haveMyServiceInDi()
{
$this->phalcon->addServiceToContainer(
'myService',
['className' => '\My\Awesome\Service']
);
}
}
And use it in tests as follows:
<?php
namespace App\Functional;
use Helper\MyService;
class IndexControllerCest
{
/** #var MyService */
protected $myService;
protected function _inject(MyService $myService)
{
$this->myService = $myService;
}
public function testIndexAction(FunctionalTester $I)
{
$I->wantTo(
'mock myService, replace real object that in controller with fake one'
);
$this->myService->haveMyServiceInDi();
$I->amOnRoute('index.route');
}
}
I am facing this issue while adding blog post in Zend Framework 2 using the link Making use of Forms and Fieldsets. I have double checked whether anything is missed by me. Can anybody help where i am going wrong or anything missing please. As i am new Zend Framework its little hard to track the issue.
Fatal error: Declaration of Blog\Service\PostService::savePost() must be compatible with Blog\Service\PostServiceInterface::savePost(Blog\Model\PostInterface $blog) in D:\xampp\htdocs\zf\module\Blog\src\Blog\Service\PostService.php on line 9
The required file to fix this bug is given below:
<?php
// Filename: /module/Blog/src/Blog/Service/PostService.php
namespace Blog\Service;
use Blog\Model\PostInterface;//this clause is missing in the tutorial link
use Blog\Mapper\PostMapperInterface;
class PostService implements PostServiceInterface {
/**
* #var \Blog\Mapper\PostMapperInterface
*/
protected $postMapper;
/**
* #param PostMapperInterface $postMapper
*/
public function __construct(PostMapperInterface $postMapper) {
$this->postMapper = $postMapper;
}
/**
* {#inheritDoc}
*/
public function findAllPosts() {
return $this->postMapper->findAll();
}
/**
* {#inheritDoc}
*/
public function findPost($id) {
return $this->postMapper->find($id);
}
/**
* {#inheritDoc}
*/
public function savePost(PostInterface $post) {
return $this->postMapper->save($post);
}
}
I if saw correctly, it looks like that in the example you are following, in the PostServiceClass, a use Blog\Model\PostInterface; clause is missing.
This is causing the PostInterface used in the savePost method to be a Blog\Service\PostInterface and not a Blog\Model\PostInterface and hence the implementation of the savePost method is not complatible with its declaration in the interface
While creating a scope function with name 'scopeList' in the Model to return a data collection (has select) laravel throws a T_List error. Can I know why?
My code:
namespace project1;
use Illuminate\Database\Eloquent\Model;
class Lookup extends Model
{
protected $fillable = array('type','code','description','listorder');
public $timestamps = false;
/**
* List lookup entries for a given type
*
* #param $type
*
* #return \Illuminate\Support\Collection
*/
public function scopeEntries($query,$type){
return $query->select('code','description')
->where('type',$type)->get();
}
}
If instead of 'scopeEntries', I want to call it 'scopeList' I encounter an error.
I created a sort base module in my ZF2 vendor library. So far everything is working the way I want it to work. I do have a problem. While I am able to extend the base module's controllers, I am unable to access the base service. I am using Doctrine 2 as my database layer.
After implementing the ServiceLocator, I am getting Fatal error: Call to a member function get() on a non-object in my base service file. My BaseService file is shown as below:
namespace MyResource\Service;
use Doctrine\ORM\Mapping as ORM;
use Zend\ServiceManager\ServiceManager;
use Zend\ServiceManager\ServiceManagerAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class BaseService implements ServiceLocatorAwareInterface
{
/**
* Entity manager instance
*
* #var Doctrine\ORM\EntityManager
*/
protected $_em;
protected $_serviceLocator;
public function __construct()
{
$this->getEntityManager();
}
/**
* Returns an instance of the Doctrine entity manager loaded from the service
* locator
*
* #return Doctrine\ORM\EntityManager
*/
public function getEntityManager()
{
if (null === $this->_em) {
$this->_em = $this->getServiceLocator()
->get('doctrine.entitymanager.orm_default');
}
return $this->_em;
}
/**
* Set serviceManager instance
*
* #param ServiceLocatorInterface $serviceLocator
* #return void
*/
public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
$this->serviceLocator = $serviceLocator;
}
/**
* Retrieve serviceManager instance
*
* #return ServiceLocatorInterface
*/
public function getServiceLocator()
{
return $this->serviceLocator;
}
}
Can anyone help?
Thanks
1):
Your property is called
protected $_serviceLocator;
but you are assigning your values to
protected $serviceLocator;
2)
Are you creating your Service via DI or the service manager? If you do then the ServiceLocator should be automatically injected for you, if you are creating it manually using the "new" keyword then it will not have the ServiceLocatior attached.
There seems to be a glitch in ZF2 .If you try setting the properties
as below the problem will be fixed. Try like this
foreach ($resultSet as $row) {
$entity = new Countrypages();
$entity->setId($row->id);
$entity->setName($row->name);
$entity->setSnippet($row->snippet);
$entity->setSortorder($row->sortorder);
$entity->setActive($row->active);
$entity->setCreated($row->created);
$entity->setModified($row->modified);
$entity->setFirstname($row->firstname);
$entity->setCreatedby($row->createdby);
$entities[] = $entity;
}
ignore this
foreach ($resultSet as $row) {
$entity = new Countrypages();
$entity->setId($row->id);
->setName($row->name);
->setSnippet($row->snippet);
->setSortorder($row->sortorder);
->setActive($row->active);
->setCreated($row->created);
->setModified($row->modified);
->setFirstname($row->firstname);
->setCreatedby($row->createdby);
$entities[] = $entity;
}
I hope this help you save your time.
You're using use use Zend\ServiceManager\ServiceManagerAwareInterface but you're implementing ServiceLocatorAwareInterface (and there's no "use" statement for that one).
I'm trying to add relationships to my database using the annotation method in my User Entity and Role Entity classes, however when I update the meta data and run an update from the command line and then go to phpMyAdmin there are no relationships present using the designer tool. I'm trying to write all database changes using Symfony2 and Doctrine to keep it consistent. Here is what I currently have:
<?php
namespace XXX\XXXBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Role
*
* #ORM\Table(name="role")
* #ORM\Entity
* #ORM\HasLifecycleCallbacks()
*/
class Role
{
/**
*
* #ORM\OneToMany(targetEntity="User", mappedBy="role")
*/
private $users;
}
<?php
namespace XXX\XXXBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* User
*
* #ORM\Table(name="user",indexes={#ORM\Index(name="role", columns={"role_id"})})
* #ORM\Entity
* #ORM\HasLifecycleCallbacks()
*/
class User
{
/**
* #var integer
*
* #ORM\Column(name="role_id", type="integer")
* #ORM\ManyToOne(targetEntity="Role", inversedBy="users")
* #ORM\JoinColumn(name="role_id", referencedColumnName="id")
*/
private $role;
}
$role should not contain an #ORM\Column definition. The role_id column will be automatically created by the ORM based on the name parameter in #JoinColumn. $role will be used to populate the associated Role entity, not an integer.