-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Cookbook] How to use components #1899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ Workflow | |
|
||
new_project_git | ||
new_project_svn | ||
new_project_components |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
.. index:: | ||
single: Workflow; Components | ||
|
||
How to start a new project using Symfony2 Components | ||
==================================================== | ||
|
||
Using Finder Component | ||
---------------------- | ||
|
||
1. Create a new empty folder. | ||
|
||
2. Create a new file called ``composer.json`` and paste the following into it: | ||
|
||
.. code-block:: json | ||
|
||
{ | ||
"require": { | ||
"symfony/finder": "2.1.*" | ||
} | ||
} | ||
|
||
3. Download vendor libraries and generate ``vendor/autoload.php`` file: | ||
|
||
.. code-block:: bash | ||
|
||
$ php composer.phar install | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can combine these two steps (2 and 3) by using:
|
||
|
||
4. Write your code: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should remove line 29 and 30 and replace the single colon by 2 colons. |
||
|
||
.. code-block:: php | ||
|
||
<?php | ||
|
||
// File: src/script.php | ||
|
||
require_once '../vendor/autoload.php'; | ||
|
||
use Symfony\Component\Finder\Finder; | ||
|
||
$finder = new Finder(); | ||
$finder->in('../data/'); | ||
|
||
... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be |
||
|
||
.. tip:: | ||
|
||
If you want to use all the Symfony2 Component, then instead of adding them one by one: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't recommend this because it requries not only the components, but the complete Symfony2 core Framework including Twig, the Doctrine-, Monolog-, Propel-, Swiftmailer- and Twig Bridges and the Framework-, Security-, Twig- and WebProfiler Bundles. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but all the components are in the same folder. Otherwise they are in separate folders. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, but who cares when using composer ? you don't need to bother about the way stuff are stored in the vendor/ folder There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stof Ok. You're right. Nevertheless, I still think, that the best method to write a script that can access any component is to use:
|
||
|
||
.. code-block:: json | ||
|
||
{ | ||
"require": { | ||
"symfony/finder": "2.1.*", | ||
"symfony/dom-crawler": "2.1.*", | ||
"symfony/css-selector": "2.1.*" | ||
... | ||
} | ||
} | ||
|
||
use: | ||
|
||
.. code-block:: json | ||
|
||
{ | ||
"require": { | ||
"symfony/symfony": "2.1.*" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dot should be a semi colon.