Trait location in bundle Symfony 2 project - php

I have a design doubt about Symfony 2. The fact is I want to use a trait into a bundle of mine but I am not sure where to locate the trait. It is not a controller, it is not a model or entity.
I have a solutions on mind but I am not sure if it follows the best practice. The idea is create a new folder called /Trait. It is correct?
<your-bundle>/
├─ AcmeBlogBundle.php
├─ Controller/
├─ Entity/
├─ Trait/ <- My thought
├─ README.md
├─ LICENSE
├─ Resources/
│ ├─ config/
│ ├─ doc/
│ │ └─ index.rst
│ ├─ translations/
│ ├─ views/
│ └─ public/
└─ Tests/
Thank you very much

You can't use Trait, since it's a php keyword, so you'll have to use Traits, but apart from that, your suggestion is fine.
Bundle structure is only there for your convenience, it shouldn't be something limiting you, feel free to create any namespaces as you like. In fact you can use Symfony without bundles at all.

Related

How to override errors templates for Symfony

I want to override the error templates in Symfony 3. I've started by creating a TwigBundle folder withe the personalised twig.
app/
└─ Resources/
└─ TwigBundle/
└─ Exception/
├─ error404.html.twig
├─ error403.html.twig
├─ error.html.twig
Then I checked the routing_dev file which contains this lines :
_errors:
resource: "#TwigBundle/Resources/config/routing/errors.xml"
prefix: /_error
Symfony still displays the default error templates. I want to know if I should verify something else.
PS : I have already checked this documentation : How to Customize Error Pages
EDIT :
The overriden files should reside in a subfolder named views. The correct file tree would look like this:
app/
└─ Resources/
└─ TwigBundle/
└─ views/
└─ Exception/
├─ error404.html.twig
├─ error403.html.twig
├─ error.html.twig
Clear your cache afterwards.
Be aware that those overriden error templates do NOT show up in the dev environment.
If you want to test the templates in your dev environment you must ensure you have imported the following in routing_dev.yml:
_errors:
resource: "#TwigBundle/Resources/config/routing/errors.xml"
prefix: /_error
Now you can access /_error/<error-code>.html (i.e. localhost:8000/_error/404.html with the integrated webserver)

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');
});

Symfony 2 FOSUserBundle: Override form without defining service

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

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.

how to configure zf cli tool to recognize multiple application sub-directories?

I am developing an application using Zend Framework 1.11.10. I have used this article to make sub-directory tree. The problem I'm facing now is that I can't use provided CLI ZF tool to generate controller-view stubs. I am developing an application which's functionality will vary depending on the accessing method. When the base www.example.com address will be prepended with letter m (m.example.com) I would like to serve mobile content which will be lightweight tailored for smart-phones. Please tell me, how to manage to change cli zf tool configuration, I would like to be able to issue commands similar with *zf create view|controller|action ObjectName --application_name desktop|mobile*
└─ rdp
├─ .svn
├─ application
│ ├─ .svn
│ ├─ desktop
│ │ ├─ .svn
│ │ ├─ configs
│ ├─ controllers
│ │ ├─ models
│ │ └─ views
│ └─ mobile
│ ├─ .svn
│ ├─ configs
│ ├─ controllers
│ ├─ models
│ └─ views
├─ docs
├─ library
├─ public
└─ tests
You could use modules for this. Zend_Tool supports creating controllers within modules. The manual has a good explanation.
To use Zend_Tool to create the mobile module:
zf create module mobile
To use Zend_Tool to create the IndexController within the mobile module:
zf create controller Index 1 mobile
(The "1" is important!)

Categories