I am using laravel 5.3 and auth plugin.
Folder structure
Laravel
App
Customfolder
Utilities
RegisQuesUtility
Http
Controllers
Auth
RegisterController.php
bootstrap
config
database
public
Following code I am using in RegisterController.php
namespace App\Http\Controllers\Auth;
use App;
class RegisterController extends Controller
{
function showRegistrationForm(){
$questionBuilder = App::make('Customfolder\Utilities\RegisQuesUtility');
}
}
But I am getting error Class Customfolder\Utilities\RegisQuesUtility does not exist.
Any suggestions what can be the reasons and possible solutions?
Use the full path in make method as:
$questionBuilder = app()->make('App\Customfolder\Utilities\RegisQuesUtility');
Or
use App\Customfolder\Utilities\RegisQuesUtility;
// rest code
$questionBuilder = app()->make(RegisQuesUtility::class);
Related
I have a problem with FOSUserBundle and HWIOauthBundle. I use custom UserChecker to check whether user is banned (custom table in database as I need a ban history). When I use Facebook to log-in my CustomChecker is not used. It does work when I'm using login and password as authentication.
Issue on GitHub: https://github.com/hwi/HWIOAuthBundle/issues/1358
Anyone has an idea how to fix that?
from the docs
Services & Configuration
If you want to modify service definitions of another bundle, you can
use a compiler pass to change the class of the service or to modify
method calls. In the following example, the implementing class for the
original-service-id is changed to App\YourService:
// src/Kernel.php
namespace App;
// ...
+ use App\Service\YourService;
+ use Symfony\Component\DependencyInjection\ContainerBuilder;
+ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
class Kernel extends BaseKernel implements CompilerPassInterface
{
+ public function process(ContainerBuilder $container)
+ {
+ $definition = $container->findDefinition('original-service-id');
+ $definition->setClass(YourService::class);
+ }
}
I confirm, the solution of #Domagoj work for Symfony 3.4.
# app/config/services.yml
services:
...
security.user_checker:
class: AppBundle\Service\YourUserChecker
With this code, the hwi.user_checker is override by your UserChecker.
Thanks.
First, sorry if my english it's not so good.
I readed a lot of questions like the one i have, but any solution works.
The question is that I'm developing a porject in Symfony 2.3, yes, i'm beginner using it...
I've created a 'Userbundle', and i want to display the info profile of an user.
When I access to the correct URL I have the famous message error:
"The autoloader expected class "Mylife\UserBundle\Entity\UserRepository" to be defined in file "D:\www\Symfony/src\Mylife\UserBundle\Entity\UserRepository.php". The file was found but the class was not in it, the class name or namespace probably has a typo."
That's my default controller code:
namespace Mylife\UserBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Mylife\UserBundle\Entity\User;
use Mylife\UserBundle\Form\Frontend\RegisterType;
class DefaultController extends Controller
{
public function profileAction(){
$user_id=1;
$em=$this->getDoctrine()->getEntityManager();
$profile=$em->getRepository('UserBundle:User')
->findProfile($user_id);
return $this->render('UserBundle:Default:profile.html.twig', array( 'profile' => $profile));
}
And my UserRepository.php code:
// src/Mylife/UserBundle/Entity/UserRepository.php
namespace Mylife\UserBundle\Entity;
use Doctrine\ORM\EntityRepository;
class UserRepository extends EntityRepository
{
public function findProfile($user)
{
$em = $this->getEntityManager();
$consult= $em->createQuery('
SELECT u, nk, n
FROM UserBundle:User u
WHERE u.user= :id');
$consult->setParameter('id', $user);
return $consult->getResult();
}
}
I have the same problem when trying to use a form class in the same bundle, but i no see any error in namesapce or class name.
The project structure is:
-src
-Mylife
-UserBundle
....
-Entity
...
-User.php
-UserRepository.php
I'm going mad trying to solve the problem and reading a lot of forums and examples.
I've tryed to dissable APC, to restart Apache, erase the cache, and nothing of this worked.
Thanks a lot!!
Carlos
PD: I'm not sure why appears a piece of code at the top of the error page and why it begins in "getEntityMAnager();..." row... Why is not showing the text code before it?. Image:http://es.tinypic.com?ref=r0s8k5
IMPORTANT: When I generated the entity USer by console, I say "no" when asked to generate repository. May be this is the problem. Any suggestion now?
Thanks again
Try to add this comment in your User entity file:
/**
*
* #ORM\Entity(repositoryClass="YourProject\UserBundle\Entity\UserRepository")
*/
class User
{
...
}
or something like this:
custom repository class in symfony2
Found it!!
It's was a silly mistake. I've began the PHP repository file with
<?
...
and must be
<?php
...
Sorry at all!
basically I am trying to integrate the thrid party api in symfony2 application. I have the php class from api documention. I want integrate that in my custom bundle controller.
I also looking to add the option to configure the api key and secrets. I don't know how to start. Please look at below that i want to do
Example:-
namespace Acme\DemoBundle\Controller;
class DemoController extends Controller
{
public function indexAction()
{
$myApi = new MyApi($key,$secret); // this is the stuff, I am trying to do!
return array();
}
}
First I try to create the library format symfony package. I don't know how to achive this this type. Can Some one tell me what are thinks I need to do.
TO do this in a proper way, you have to declare you api class as a service & use dependancy injection to inject your parameters :
parameters:
your_api.class: Acme\HelloBundle\Lib\YourApiClass
your_api.key: "key value for your api"
your_api.token: "token value for your api"
services:
yourApiService:
class: "%your_api.class%"
arguments: ["%your_api.key%", "%your_api.token%"]
And in your controller & many other places you'll have access like that :
$api = $this->get('yourApiService');
Take a look for more informations : http://symfony.com/doc/current/book/service_container.html
you can use it as a service:
http://symfony.com/doc/current/book/service_container.html
when i try to implement an extern api, i think about adapter pattern:
http://en.wikipedia.org/wiki/Adapter_pattern
in what file, or where ,is the mapping of controller to model occur in
symfony 1.4
symfony 2
are there any yml/config files that tell the system to recognize the appropriate model?
what I mean is:
let's say a controller looks like this:
class jobActions extends sfActions
{
public function executeIndex(sfWebRequest $request)
{
$user=new PcUser();
$user->username=$request->GetParameters(...);
}
}
and PcUser.php is an entity file that has PcUser class inside.
where is the mapping done? how does the controller jobActions know PcUser?
It's done by symfony's autoloader. If the script doesn't know about class you are trying to use, then autoloader try include appropriate class based on namespace.
So, for your example:
class SomeController
{
public function executeIndex(sfWebRequest $request)
{
$user=new \NamespaceForBundle\Entity\PcUser();
$user->username=$request->GetParameters(...);
}
}
And if you ask about ORM mapping - you can do it in several ways like appropriate yaml configuration file, or annotations inside entities.
I've created a fixtures class inside my bundle's DataFixtures/ORM folder. The actual class looks like this:
use Doctrine\Common\DataFixtures\FixtureInterface,
Company\ShoppingBundle\Entity\Category;
class CategoryFixtures implements FixtureInterface
{
public function load($em)
{
$category1 = new Category()->setName("category1");
$category2 = new Category()->setName("category2");
$em->persist($category1);
$em->persist($category2);
$em->flush();
}
}
I'm not using the AbstractFixture base class, since I don't need references. I've also tried specifying the fixtures path when running the doctrine:fixtures:load console command. I'm following the official docs here.
Nothing wrong with the file naming, or my configuration: I simply forgot to put
<?php
at the top of my file :-D