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)
Related
I’m new to php and codeception and I wanted to use Gherkin with Codeception, and I’ve already setup the bare minimum to make feature files run in Codeception. I now find myself trying to make a scalable structure and make use of the PageObject framework. I created a Steps Folder and I wanted my step implementations kept in that folder. By default running codecept run some.feature loads the class defined in the acceptance.suite.yml file.
Motivation: I want to be able keep my step implementations into it’s own separate folder
Given I have an acceptance.suite.yml file configuration of:
gherkin:
contexts:
default:
- AcceptanceTester
modules:
enabled:
- WebDriver:
url: https://www.google.com/
browser: chrome
- \Helper\Acceptance
And I have a codeception.yml file configuration of:
paths:
tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
actor_suffix: Tester
extensions:
enabled:
- Codeception\Extension\RunFailed
And I have my Steps folder under _support:
How do I change the configuration to allow my step implementation to be
called from the Steps folder?
In the gherkin: section of the suite configuration, you need to list your steps classes organised under default:, role: and/or tag: sections. There are example configurations in the official documentation: Gherkin options.
Below is an example from a recent project (using Codeception 2.5.6):
file structure
/app/common
├── codeception.yml
├── tests
│ ├── acceptance.suite.yml
│ ├── _bootstrap.php
│ ├── _data
│ │ └── user.php
│ ├── _support
│ │ ├── AcceptanceTester.php
│ │ ├── Step
│ │ │ └── Acceptance
│ │ │ └── CuratorSteps.php
The layout above for the step class is the default one when generating step object using codecept generate:stepobject command like so:
$ /app/vendor/bin/codecept -c /app/common generate:stepobject acceptance CuratorSteps
acceptance.suite.yml:
# acceptance.suite.yml
namespace: common\tests
suite_namespace: common\tests\acceptance
bootstrap: false
actor: AcceptanceTester
modules:
enabled:
- PhpBrowser:
url: http://example.com/
gherkin:
contexts:
default:
- common\tests\AcceptanceTester
role:
curator:
- common\tests\Step\Acceptance\CuratorSteps
The documentation doesn't mention it, but I notice I have to list the full namespace of the step classes, otherwise I'll get "Step definition for ... not found in contexts" errors when running the tests and the gherkin:steps codecept command won't return the step definitions.
output
$ /app/vendor/bin/codecept -vvv -c /app/common gherkin:steps acceptance
Steps from role:curator context:
+--------------------------------------------------------------------+------------------------------------------------------------------------------------------+
| Step | Implementation |
+--------------------------------------------------------------------+------------------------------------------------------------------------------------------+
| I sign in as an admin | common\tests\Step\Acceptance\CuratorSteps::iSignInAsAnAdmin |
| I should see a :arg1 button | common\tests\Step\Acceptance\CuratorSteps::iShouldSeeAButton |
+--------------------------------------------------------------------+------------------------------------------------------------------------------------------+
Steps from default context:
+-------------------------------------+---------------------------------------------------------+
| Step | Implementation |
+-------------------------------------+---------------------------------------------------------+
| I take a screenshot with name :arg1 | common\tests\AcceptanceTester::itakeAScreenshotWithName |
+-------------------------------------+---------------------------------------------------------+
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.
I have this folder structure (symfony 2 application):
src
|-- Application
| |-- UserBundle
| | |-- Admin
| | |-- Api
| | |-- SomeController.php
| | |-- Controller
| | |-- DefaultController.php
| | |-- DependencyInjection
| | |-- Entity
| | |-- Resources
| | |-- Tests
I want to call some controller from Api folder. How i can do this?
UPD.
I use symfony routing to provide the controller:
application_homepage:
path: /hello/{name}
defaults: { _controller: ApplicationUserBundle:Default:index }
application_some:
path: /api/{slug}
defaults: { _controller: ApplicationUserBundle:../Api/Some:index }
I want to load controller from Api folder
If the namespace of your controller is : Application\UserBundle\Api,
that the className is SomeController and the action is indexAction
You can use this syntax in your routing file :
application_some:
path: /api/{slug}
defaults: { _controller: Application\UserBundle\Api\SomeController::indexAction }
This solution will work too:
application_some:
resource: "#ApplicationUserBundle/Api"
type: annotation
or:
application_some:
resource: "#ApplicationUserBundle/Api/SomeController.php"
type: annotation
see http://symfony.com/doc/current/book/routing.html#including-external-routing-resources
If both controller sit within the same namespace, you could simply do
$controller = new ControllerInApiFolder();
$conotroller->someFunction();
if they do not, then you need to include the controller via use-statement.
use Namespace\My\Controller\Sits\In\ControllerInApiFolder;
If you are trying to access the controller not from another controller, but from a template, an url or a testcase, you should refer to the symfony2 documentation.
Symfony2 Doc
From the edited question above I take it you want to call the controller via the url.
In your browser you can simply type in
path/to/my/web/api/something
or
path/to/my/web/app_dev.php/api/something
where "path/to/my/web" referes to the path of the web folder within your project
EDIT: I think now I am getting the problem...
Symfony2 routing always defaults to the /Controller folder to look for the controller (which is quite nice).
I am not quite sure you should add another folder to this. Instead, the documentation suggests having multiple folders inside the /Controller folder.
If you take a look at the folder structure displayed here: Symfony2 Controller, you will notice that there is an API folder within the /Controller folder.
<your-project>/
├─ ...
└─ src/
└─ AppBundle/
├─ ...
└─ Controller/
├─ DefaultController.php
├─ ...
├─ Api/
│ ├─ ...
│ └─ ...
└─ Backend/
├─ ...
└─ ...
In a Yii project I have the structure:
project/
... default Yii structure here ...
themes/
css/
font/
images/
js/
views/
admin/
layouts/
site/
How to configure Gii to generate CRUD in themes folder?
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!)