Symfony 2 FOSUserBundle: Override form without defining service - php

I' m trying to set up FOSUserBundle for my new application, so I want to override the default FOSUser form. As stated in the FOSUser documentation, I have to define my new form as a service before set up the app/config.yml appropriately. My question is why can't I just set up config.yml like this:
fos_user:
db_driver: orm
firewall_name: admin_area
user_class: abc\abcBundle\Entity\User
registration:
form:
type: abc\abcBundle\Form\Type\UserType
In my last application, I used FOSUserBundle along with PUGXMUltiUserBundle and then my (perfectly working) configuration for PUGXM was:
users:
agents:
entity:
class: abc\NikBundle\Entity\agents
registration:
form:
type: abc\NikBundle\Form\Type\UserType
name: agent_user_registration_form
template: abcNikBundle:ManageUsers:newUser.html.twig
so I supposed this can also be done with FOSUserBundle. Is it impossible and if yes why?

FOSUserBundle allows you to override it's controllers as described in the doc below
https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_controllers.md
This doc actually shows you how to override registration controller and from there it's simply injecting your custom form for validation as in any normal controller.
You can also override the templates by finding the original FOSUserBundle templates under "{ROOT_DIR}/vendor/friendsofsymfony/user-bundle/Resources/views" and copying them into "{ROOT_DIR}/app/Resources/FOSUserBundle/views".
https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_templates.md
It should look like this
Resources
└── FOSUserBundle
└── views
├── ChangePassword
│ ├── changePassword.html.twig
│ └── changePassword_content.html.twig
├── Registration
│ ├── confirmed.html.twig
│ ├── register.html.twig
│ └── register_fail.html.twig
├── Resetting
│ ├── checkEmail.html.twig
│ ├── email.txt.twig
│ ├── passwordAlreadyRequested.html.twig
│ ├── request.html.twig
│ ├── request_content.html.twig
│ ├── reset.html.twig
│ └── reset_content.html.twig
├── Security
│ └── login.html.twig
└── layout.html.twig

Related

Laravel folders for versioning

I am implementing versioning in Laravel. Now my doubt is, where should I create the V1 subfolders within the various main folders? For example, is it okay for controllers (Controllers/Api/V1) but what about Models, Resources, Request, Services etc...?
There is a very well maintained package specifically for what you are trying to do, called Laravel Modules: https://github.com/nWidart/laravel-modules
You can accomplish subversions of the application inside of it, and everything like "Models, Resource, Routes, etc.." is packaged seperately from one module to another.
Modules/
├── Blog/
├── Config/
├── Console/
├── Database/
├── factories/
├── Migrations/
├── Seeders/
├── Entities/
├── Http/
├── Controllers/
├── Middleware/
├── Requests/
├── Providers/
├── PostsServiceProvider.php
├── RouteServiceProvider.php
├── Resources/
├── assets/
├── lang/
├── views/
├── Routes/
├── api.php
├── web.php
├── Tests/
├── composer.json
├── module.json
├── package.json
├── webpack.mix.js
Check the documentation on how to use it: https://docs.laravelmodules.com/v9/creating-a-module
Also laravel-daily made a video on what it is here: https://www.youtube.com/watch?v=RVApkrYMcAg

laravel route work wrong to direct to views

I am a new laraveler, now I work with a problem about laravel. I want the / direct to a anguler index.html. and others route to laravel controller. but when the \ direct well . the others routes work wrong to a views directory.
the \app\Http\route.php like follows :
Route::get('/',function(){
return File::get(public_path().('/views/index.html'));
});
Route::get('scan', "userController#Scan");
Route::get('check', "userController#Check");
Route::get('login', "userController#Login");
the directy is something like follows:
├── app
│ ├── Http
│ │ ├── route.php //route file
│ ├── Library
│ ├── Providers
│ ├── Services
│ ├── User.php
│ └── views
│ │ ├── Index.php // php index file , the entry for nginx server
│ └── ..........
├── bootstrap
│ ├── app.php
│ ├── autoload.php
│ └── cache
├── config
│ ├── app.php
│ └── view.php
│ └── ..........
├── public
│ ├── bower_components
│ ├── css
│ ├── data
│ ├── index.bak
│ ├── index.html //angular index file
│ └── scripts
│ └── ..........
now when I access to http://hostname/scan it comes 404 no found.
and the log like follows:
```
*2221 open() "/service/angular-laravel/app/views/scan" failed (2: No such file or directory), client: x.x.x.x, server: hostname, request: "GET /scan HTTP/1.1", host: "banliyun.com:8081"
```
as I was a little confuse with how the route work. can someone tell me why it will route to /views directory where place the laravel index page.
Save your index.html as index.blade.php in /resources/views/index.blade.php and you change your route to the following code:
Route::get('/', function(){
return view('index');
});
In AppServiceProvider class boot method add below line:
View::addLocation(public_path('views'));
Rename index.html file as index.blade.php and then follow below line in your route.php
Route::get('/', function(){
return view('index');
});

PHP - Silex: Fatal error: Class not found

I've made a PHP application with Silex. I'm using a WAMP solution on my laptop to develop, in combination with Composer.
Now, when I upload the application (maps 'app', 'src' and 'web') and upload the database, change the config.php to the correct database credentials I issue the composer command (composer.phar -o install) to install the vendor dependencies.
Until this point everything works, Composer makes the 'vendor' map and installs the dependencies without errors. But when I visit the website it shows me the error:
Fatal error: Class 'WanaKo\Provider\Controller\HomeController' not found in /home/wanako/domains/wanako.net/app/app.php on line 37
What can I do to fix that error? I must add that the server is running DirectAdmin with PHP 5.5.16 and that I've made a symlink from 'public_html/' to 'web/'
The directory structure is:
/home/wanako/domains/wanako.net/
├── app
├── logs
├── public_ftp
│ └── incoming
├── public_html -> web/
├── src
│ ├── wanako
│ │ ├── provider
│ │ │ └── controller
│ │ └── repository
│ └── views
│ ├── errors
│ └── home
├── vendor
│ ├── composer
│ ├── doctrine
│ │ ├── common
│ │ └── dbal
│ ├── igorw
│ │ └── config-service-provider
│ ├── imagine
│ │ └── imagine
│ ├── ircmaxell
│ │ └── password-compat
│ ├── knplabs
│ │ └── repository-service-provider
│ ├── monolog
│ │ └── monolog
│ ├── neutron
│ │ └── silex-imagine-provider
│ ├── pimple
│ │ └── pimple
│ ├── psr
│ │ └── log
│ ├── silex
│ │ └── silex
│ ├── swiftmailer
│ │ └── swiftmailer
│ ├── symfony
│ │ ├── config
│ │ ├── debug
│ │ ├── event-dispatcher
│ │ ├── filesystem
│ │ ├── form
│ │ ├── http-foundation
│ │ ├── http-kernel
│ │ ├── icu
│ │ ├── intl
│ │ ├── locale
│ │ ├── options-resolver
│ │ ├── property-access
│ │ ├── routing
│ │ ├── security-core
│ │ ├── security-csrf
│ │ ├── translation
│ │ ├── twig-bridge
│ │ └── validator
│ └── twig
│ └── twig
└── web
├── css
├── font
├── images
└── js
composer.json
{
"name": "Wanako/Wakano.net",
"require": {
"silex/silex": "1.0.*#dev",
"twig/twig": ">=1.8,<2.0-dev",
"doctrine/dbal": "2.*",
"knplabs/repository-service-provider": "dev-master",
"symfony/twig-bridge": "~2.1",
"symfony/form": "~2.1",
"symfony/validator": "~2.1",
"symfony/config": "~2.1",
"symfony/translation": "~2.1",
"symfony/locale": "~2.1",
"monolog/monolog": ">=1.0.0",
"igorw/config-service-provider": "~1.1",
"swiftmailer/swiftmailer": ">=4.1.2,<4.2-dev",
"ircmaxell/password-compat": "dev-master",
"neutron/silex-imagine-provider": "~0.1"
},
"autoload": {
"psr-0": {
"WanaKo": "./src/"
}
}
}
At line 37 of app/app.php I've got:
$app->mount('/', new WanaKo\Provider\Controller\HomeController());
homecontroller.php (in the folder src/wanako/provider/controller/)
<?php
namespace WanaKo\Provider\Controller;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
use Symfony\Component\Validator\Constraints as Assert;
class HomeController implements ControllerProviderInterface {
$controllers = $app['controllers_factory'];
// Bind sub-routes
$controllers->get('/', array($this, 'home'))->method('GET')->bind('home.news');
return $controllers;
}
public function home(Application $app) {
// STUFF
}
I've got no clue on this one. Is there something I did wrong? Wrong folder structure? Something I forgot? If anyone needs more info, just ask. Thanks for helping out!
I believe you have to name your folder structure and files in the correct case for psr0 to work correctly, like this:
src/WanaKo/Provider/Controller/HomeController.php

cakephp: running diffrent cakephp verison on same domain

I have already installed cakephp verion 1.3 on root of domain for Application1.
Now i want to develop another music application, that i want to store in a sub-directory. Now i want to use latest cakephp version for this application.
I am new to cakephp, and donot want to use same cakephp core for both application. First root application was not developed by me.
Directory structure is a s follow.
ROOT
├── .htaccess
├── cake
│ ├── config
│ ├── console
│ ├── libs
│ ├── tests
├── app
│ │ ├── .htaccess
│ │ ├── libs
│ │ ├── vendors
│ │ ├── config
│ │ ├── plugins
│ │ ├── views
│ │ ├── models
│ │ ├── controllers
│ │ ├── temp
│ │ ├── WEBROOT
│ │ │ ├── .htaccess
├──music (this one i want to use for latest version cakephp installation).
I installed cakephp 2.5.2 in music directory, but unable to access this by www.example.com/music/
It redirect to first root application i.e. example.com/member/index.
In
├── app
│ │ ├── config
│ │ ├ ├──routes.php
I have this:
Router::connect('/', array('controller' => 'members', 'action' => 'index'));
If unable to understand what i want:
My Question:
How can i run two different cakephp version, one on root of the domain
and second in subdirectory (music).
If not possible i will use same version, but one application will be in music sub directory.
Both the versions should work fine, just make sure you have not written a htaaccess rule to redirect all incoming request to the first cakephp folder.

Using a Zend partial view helper in Qunit tests

I'm quite new to both Zend and QUnit and I've got a bit stuck when it comes to setting up my QUnit tests to test my JavaScript.
I'm trying to test to some DOM manipulation and I understand that I have to put the html I'm testing against inside a #qunit-fixture div in my Qunit test file. However I've got a partial view helper used in my main Zend application (works fine in my view scripts) which I just want to echo out rather than having to rewrite the html used in the helper itself (to avoid duplication). The JavaScript I am attempting to test is used in the partial view helper hence wanting to use it.
Here's the folder structure for my application with just the important files and a few others remaining:
├── application
│   ├── Bootstrap.php
│   ├── configs
│   ├── controllers
│   ├── layouts
│   │   └── scripts
│   ├── models
│   ├── plugins
│   └── views
│   ├── helpers
│   └── scripts
│   ├── error
│   ├── index
│   └── partials
│   └── partialViewHelperIWantToUse.phtml
├── docs
├── features
├── Gemfile
├── Gemfile.lock
├── js-tests
│   ├── qunitTestFile.html
│   └── vendor
│   └── qunit
│   ├── qunit.css
│   └── qunit.js
├── library
│   ├── Custom
├── public
│   ├── css
│   ├── img
│   ├── index.php
│   └── js
│   ├── jquery
│   │   └── jquery-1.7.2.min.js
│   └── javaScriptIWantToTest.js
├── Rakefile
├── tasks
└── tests
├── application
│   ├── controllers
│   └── models
├── bootstrap.php
├── library
│   └── Custom
└── phpunit.xml
I want to do something like this in my qunitTestFile.html (found in js-tests)
<div id="qunit-fixture">
<?php echo $view->partial('partialViewHelperIWantToUse.phtml') ?>
</div>
but it currently doesn't work. Renaming the qunitTestFile to have a .phtml extension causes nothing to echo out but the error "call to a member function partial() on a non-object" appears in the apache error log (I expected that but it was a simple thing to try!). I have a hunch that I might need to create another bootstrap file or something but both and Zend and Qunit are new to me so I'm a bit lost. =)
I hope that's clear and I've given enough information but let me know if it isn't.
Thanks!
Since I do not exactly know which Zend version you use, I am not sure if this helps you:
The partial()-Function is a helper of your view. Since a View .phtml File is called in a Zend_View-Context (if you use an Controller-Action to show the View) you should use
$this->partial('...');
You can setup a Zend_View for yourself, but according your directory structure, I assume you use an MVC-Pattern.

Categories