Developed with love by KnpLabs Hire us for your project!
44

TwitterBootstrapBundle

by ruian

A symfony2 bundle for twitter bootstrap

TwitterBootstrapBundle

WARNING

If you use a symfony 2.0.x version please use the correct branch of this bundle (2.0.x in that case)

How to install ?

Add theses lines into your deps

[RuianTwitterBootstrapBundle]
    git=git://github.com/ruian/TwitterBootstrapBundle.git
    version=origin/master
    target=/bundles/Ruian/TwitterBootstrapBundle

[TwitterBootstrap1]
    git=git://github.com/twitter/bootstrap.git
    target=/twitter/bootstrap/v1/
    version=v1.4.0

[TwitterBootstrap2]
    git=git://github.com/twitter/bootstrap.git
    target=/twitter/bootstrap/v2/
    version=v2.0.0

[lessphp]
    git=git://github.com/leafo/lessphp.git
    target=/lessphp/
    version=origin/master

Add autoloading

#app/autoload.php
 <?php
$loader->registerNamespaces(array(
    #...
    'Ruian' => __DIR__.'/../vendor/bundles',
));

 #some code...

 // Add support for lessc
require  __DIR__.'/../vendor/lessphp/lessc.inc.php';

Register this bundle

#app/AppKernel.php
 <?php
$bundles = array(
    #...
    new Ruian\TwitterBootstrapBundle\RuianTwitterBootstrapBundle(),
);

Update and install all the deps

./bin/vendors update
or
./bin/vendors install --reinstall

How to use it ?

Init and compile twitter-bootstrap from source

Replace VERSION by the supported version you want, v1 or v2

php5 app/console twitter-bootstrap:clear
php5 app/console twitter-bootstrap:compile VERSION
php5 app/console assets:install web/

Add your bootstrap to your layout

Replace VERSION by the supported version you want, v1 or v2

<!DOCTYPE html>
<html>
<head>
    <title>Twitter Bootstrap</title>
    <link rel="stylesheet" type="text/css" href="{{ asset('bundles/ruiantwitterbootstrap/css/bootstrapVERSION.css') }}">
</head>
<body>
    <!-- Some code -->
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script type="text/javascript" src="{{ asset('bundles/ruiantwitterbootstrap/js/bootstrapVERSION.js') }}"></script>
</body>
</html>

Use bootstrap form style

Replace VERSION by the supported version you want, v1 or v2

{% form_theme form_view 'RuianTwitterBootstrapBundle:Form:bootstrap_VERSION.html.twig' %}

Example

#Ruian/DemoBundle/Resources/view/new.html.twig
<!DOCTYPE html>
<html>
<head>
    <title>New article</title>
    <link rel="stylesheet" type="text/css" href="{{ asset('bundles/ruiantwitterbootstrap/css/bootstrapv2.css') }}">
    <link rel="stylesheet" type="text/css" href="{{ asset('bundles/ruiantwitterbootstrap/css/bootstrapv2-responsive.css') }}">
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="offset2 span8">

                {% include 'RuianTwitterBootstrapBundle:Alert:bootstrap_v2.html.twig' %}

                {% form_theme form_view 'RuianTwitterBootstrapBundle:Form:bootstrap_v2.html.twig' %}
                <form novalidate class="form-horizontal well" method="post" action="{{ path('RuianDemoBundle_new') }}">
                    {{ form_widget(form_view) }}
                    <div class="well">
                        <input type="submit" value="Save" class="btn" />
                    </div>
                </form>
            </div>
        </div>
    </div>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script type="text/javascript" src="{{ asset('bundles/ruiantwitterbootstrap/js/bootstrapv2.js') }}"></script>
</body>
</html>
#Ruian/DemoBundle/Controller/ArticleController.php
 <?php
/**
 * Controller used for Article
 *
 * @author jgalenski
 */
class ArticleController extends Controller
{
    # some code ...

    public function newAction()
    {
        $entity = new Article();
        $form = $this->createForm(new ArticleType(), $entity);

        $request = $this->get('request');
        if ('POST' === $request->getMethod()) {
            $form->bindRequest($request);
            if (true === $form->isValid()) {
                $em = $this->get('doctrine.orm.default_entity_manager');
                $em->persist($entity);
                $em->flush();

                $this->setFlashSuccess('Congratulation, your article has been saved.');
                return $this->redirect($this->generateUrl('RuianDemoBundle_new'));
            } else {
                $this->setFlashError('Warning, your article can\'t be saved due to some errors.');
            }
        }

        return $this->render('RuianDemoBundle:Article:new.html.twig', array(
            'form_view' => $form->createView(),
        ));
    }

    protected function setFlashSuccess($message)
    {
        $this->get('session')->setFlash('alert-success', $message);
    }

    protected function setFlashError($message)
    {
        $this->get('session')->setFlash('alert-error', $message);
    }

    # some code ...
}

ruian_twitter_bootstrap:  []
  • Merge pull request #10 from andrewtch/gitignore-fix
    By ruian, 8 years ago
  • Dir cehck and ignore files
    By Andrew Tch, 8 years ago
  • Merge pull request #9 from andrewtch/copy_images
    By ruian, 8 years ago
  • copy images
    By andrewtch, 8 years ago
  • Code cleanup
    By andrewtch, 8 years ago
  • Merge pull request #7 from andrewtch/js-order-fix
    By ruian, 8 years ago
  • Fixed js order, misc typos and doc
    By andrewtch, 8 years ago
  • Merge pull request #4 from c33s/patch-1
    By ruian, 8 years ago
  • fixed typo
    By c33s, 8 years ago
  • Update version twitter bootstrap
    By ruian, 8 years ago
  • Update text i should see
    By ruian, 8 years ago
  • Update command to support new skeleton from twitter-bootstrap
    By ruian, 8 years ago
  • Update README to add a support to 2.0.x sf version
    By ruian, 8 years ago
  • sort files by name, with Finder
    By ruian, 8 years ago
  • Refactoring Command test
    By ruian, 8 years ago
  • Refactoring Command test
    By ruian, 8 years ago
  • Change error alert by help-block
    By ruian, 8 years ago
  • Correct some mistakes
    By ruian, 8 years ago
  • Add type of code
    By ruian, 8 years ago
  • Add type of code
    By ruian, 8 years ago
  • Add type of code
    By ruian, 8 years ago
  • Add type of code
    By ruian, 8 years ago
  • Add type of code
    By ruian, 8 years ago
  • Add restriction file on clear command
    By ruian, 8 years ago
  • add composer
    By ruian, 8 years ago
  • Correct Type in README deps part
    By ruian, 8 years ago
  • Add Form Example into README
    By ruian, 8 years ago
  • Add Form Example into README
    By ruian, 8 years ago
  • Add Form Example into README
    By ruian, 8 years ago
  • Add Form Example into README
    By ruian, 8 years ago