Rectangle 27 3

Strange... with default config, path/asset should handle subdirectories. Have you tried it with symfony distribution out-of-the-box? On localhost im mostly using it this way. Would you mind posting your config file?

#config.yml
templating:
  assets_base_urls: { http: "http://yoursite.com/dir1", ssl: "https://yoursite.com/dir1" }
# app/config/parameters.yml
parameters:
  router.request_context.host: example.org
  router.request_context.scheme: http
  router.request_context.base_url: my/path
$context = $this->getContainer()->get('router')->getContext();
// you should be mainly interested in:
$context->getBaseUrl();

It is possible to easily create listener class which will manually set your base url if anyhow it is wrong:

class RouterContextListener {

    protected $router;

    public function __construct(RouterInterface $router)
    {
        $this->router = $router;
    }

    public function onKernelRequest(Event $event)
    {
        $this->router->setBaseUrl('somedir');
    }
}

php - Symfony 2 project in nested directory - Stack Overflow

php symfony
Rectangle 27 1

If you want to use the theme as is (without customization) you only should include the bootstrap.min.css OR bootstrap.css into your HTML:

<link href="/bootstrap.min.css" type="text/css" rel="stylesheet">

Alternatively you can compile your own version of the theme:

  • In the source files replace the less/variables.less file with that download from bootswatch
  • copy the bootswatch.less into the less directory of the bootstrap sources files
  • Than, open the less/bootstrap.less and add the following line of code at the end of this file: @import "bootswatch"

Also notice that Bootstrap adds the autoprefixer for vendor prefixes into their build process. The vendor prefix mixins in less/mixins/vendor-prefixes.less are deprecated as of v3.2.0. So you should add https://packagist.org/packages/bit3/assetic-autoprefixer to your assetic configuration too.

php - Installing Bootstrap theme in Symfony 2 project - Stack Overflow

php html css twitter-bootstrap symfony
Rectangle 27 2

You are looking for RewriteBase rule, add it to your in your .htaccess:

Also take a look onto symfony-standard 2.3 .htaccess file, mb it can help

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]

    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]

    # If the requested filename exists, simply serve it.
    # We only want to let Apache serve files and not directories.
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]

    # Rewrite all other queries to the front controller.
    RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>

php - Symfony 2 project in nested directory - Stack Overflow

php symfony
Rectangle 27 4

If you want to dynamicallly display your Symfony 2 version in pages, example in footer, you do can it this way.

create a service

<?php

namespace Project\Bundle\DuBundle\Twig;

class SymfonyVersionExtension extends \Twig_Extension
{


 public function getFunctions()
 {
 return array(
 //this is the name of the function you will use in twig
 new \Twig_SimpleFunction('symfony_version', array($this, 'b'))
   );
 }

public function getName()
{
//return 'number_employees';
 return 'symfony_version_extension';
}   

public function b()
{
 $symfony_version = \Symfony\Component\HttpKernel\Kernel::VERSION;
 return $symfony_version;
}
}

Register in service.yml

dut.twig.symfony_version_extension:
    class: Project\Bundle\DutBundle\Twig\SymfonyVersionExtension
    tags:
        - { name: twig.extension }
    #arguments: []

And you can call it anywhere.In Controller,wrap it in JSON, or in pages example footer

<p> Built With Symfony {{ symfony_version() }} Version MIT License</p>

Now every time you run composer update to update your vendor, symfony version will also automatically updated in your template.I know this is overkill but this how I do it in my projects and it is working

php - How to know which version of Symfony I have? - Stack Overflow

php symfony
Rectangle 27 4

If you want to dynamicallly display your Symfony 2 version in pages, example in footer, you do can it this way.

create a service

<?php

namespace Project\Bundle\DuBundle\Twig;

class SymfonyVersionExtension extends \Twig_Extension
{


 public function getFunctions()
 {
 return array(
 //this is the name of the function you will use in twig
 new \Twig_SimpleFunction('symfony_version', array($this, 'b'))
   );
 }

public function getName()
{
//return 'number_employees';
 return 'symfony_version_extension';
}   

public function b()
{
 $symfony_version = \Symfony\Component\HttpKernel\Kernel::VERSION;
 return $symfony_version;
}
}

Register in service.yml

dut.twig.symfony_version_extension:
    class: Project\Bundle\DutBundle\Twig\SymfonyVersionExtension
    tags:
        - { name: twig.extension }
    #arguments: []

And you can call it anywhere.In Controller,wrap it in JSON, or in pages example footer

<p> Built With Symfony {{ symfony_version() }} Version MIT License</p>

Now every time you run composer update to update your vendor, symfony version will also automatically updated in your template.I know this is overkill but this how I do it in my projects and it is working

php - How to know which version of Symfony I have? - Stack Overflow

php symfony
Rectangle 27 4

You probably didn't clear the cache.

php bin/console cache:clear --env=prod

Or if you use dev-environment (it is not right for production server) you shoud use:

php bin/console cache:clear

If you have no access to shell you can clear the cache manually by removing whole folder with the name of your environment from var/cache. For prod environment you should remove var/cache/prod folder.

i clear cache exactly with your help but get error again. i delete all content of '/var/cache' manually and solved problem and not get any error(s). thanks

php - I have some error on symfony project in shared host - Stack Over...

php symfony
Rectangle 27 3

we can find the symfony version using Kernel.php file but problem is the Location of Kernal Will changes from version to version (Better Do File Search in you Project Directory)

in symfony 3.0 : my_project\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php

Check from Controller/ PHP File

$symfony_version = \Symfony\Component\HttpKernel\Kernel::VERSION;
echo $symfony_version; // this will return version; **o/p:3.0.4-DEV**

php - How to know which version of Symfony I have? - Stack Overflow

php symfony
Rectangle 27 3

we can find the symfony version using Kernel.php file but problem is the Location of Kernal Will changes from version to version (Better Do File Search in you Project Directory)

in symfony 3.0 : my_project\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php

Check from Controller/ PHP File

$symfony_version = \Symfony\Component\HttpKernel\Kernel::VERSION;
echo $symfony_version; // this will return version; **o/p:3.0.4-DEV**

php - How to know which version of Symfony I have? - Stack Overflow

php symfony
Rectangle 27 1

Usually, the PHP CLI uses a different php.ini configuration than the Apache PHP. Could you check where is the right configuration file for command line? This topic can help you.

Then when you'll find it, just do the same as you did with the MAMP php.ini. It should work.

Hello, i check by using php.ini and it seems php cli

Hello, I check by using php -ini and i have "Configuration File (php.ini) Path => C:\WINDOWS and Loaded Configuration File => (none)" for my php cli. I don't know how to change these values because i can find where they set. I read the page of configuration files in php.net, but as far as i know, i didn't use sapi, i check if i have any environment variable with php but no. And no registry keys also. And i don't want move my php.ini in C:\WINDOWS but i can find another way.

php - Unable to install my symfony project - Stack Overflow

php symfony datetime mamp
Rectangle 27 1

It seemed that app/console cache:clear does not work in this case because not all cache files where deleted. Removing the cache by hand did:

sudo rm -rf -- app/cache/prod app/cache/dev

After removing the cache file by hand app/console assetic:dump --force --watch compiles the files to the right directory.

You are right ;-)

php - Assetic dump and moving the symfony project to a new directory -...

php twitter-bootstrap symfony assetic
Rectangle 27 6

It's a very bad idea to put the php file into the bundles folder, it's a huge security issue. If you want an AJAX response then put it into the Controller.

Create a new action in the Controller as you normally do. Write the AJAX action and give back a JSONResponse as a response.

/**
* Return an ajax response
*/
public function ajaxAction(){
   // do the controller logic
   // $response is an array()
   return new JSONResponse($response);
}

Then in jQuery ajax set the url like this:

$.ajax({
  url: 'url/to/your/controller', // If you use the FOSJsRoutingBundle then it will be Routing.generate('route_name')
  type: 'POST',
  dataType: 'JSON',
  success: function(data1) {
    var id=data1.id;
    document.write(id);
  }
});

In the new action you can use the EntityManager to access your database.

You should also consider to use the FOSJsRoutingBundle for javascript routing. It's a very great bundle that allows you to generate routes in javascript files as you can do it in twig with the path('path_name') command.

Try to understand the Symfony Request -> Response process, because if you don't follow it, it will cause serious problems for you.

Thanks a lot for your answer, by the way I changed the code of test.html.twig as below:

<html> <</head> <body> <script src="{{asset('bundles/moslemtest/src/jquery.min.js')}}" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { $.ajax({ url: '{{asset('bundles/moslemtest/phptest/moslem1.php')}}', type: 'POST', dataType: 'JSON', success: function(data1) { document.write(data1); } }); }); </script></body></html>

And it works...it displays for me this output: {"id":"2","subject":"ss","location":null,"description":null,"starttime":"2014-05-26 01:00:00","endtime":"2014-05-26 02:00:00"} So as you can you see here, the problem is in the two lines: var id=data1.id; document.write(id);

how to get an array field value from a PHP file using jquery/Ajax in S...

php jquery html symfony twig
Rectangle 27 0

If you're using a lot of YAML in your project you may find that the pure PHP libraries like spyc or Symfony YAML are not fast enough. There are at least two PHP bindings for C YAML parsers:

  • yaml - a wrapper for the LibYAML YAML 1.1 parser library
  • syck - a wrapper for the Syck YAML 1.0 parser library

parsing - PHP YAML Parsers - Stack Overflow

php parsing yaml
Rectangle 27 0

If you want to use the theme as is (without customization) you only should include the bootstrap.min.css OR bootstrap.css into your HTML:

Alternatively you can compile your own version of the theme:

  • In the source files replace the less/variables.less file with that download from bootswatch
  • copy the bootswatch.less into the less directory of the bootstrap sources files
  • Than, open the less/bootstrap.less and add the following line of code at the end of this file: @import "bootswatch"

Also notice that Bootstrap adds the autoprefixer for vendor prefixes into their build process. The vendor prefix mixins in less/mixins/vendor-prefixes.less are deprecated as of v3.2.0. So you should add https://packagist.org/packages/bit3/assetic-autoprefixer to your assetic configuration too.

php - Installing Bootstrap theme in Symfony 2 project - Stack Overflow

php html css twitter-bootstrap symfony2
Rectangle 27 0

Manage your dependencies with composer.

First create a composer.json file in your project folder :

{
    "require": {
        "symfony/translation": "2.4.*"
    }
}

Then download composer and run it :

wget http://getcomposer.org/composer.phar
php composer.phar install

You can now use your component by importing the composer autoloader :

<?php

    require_once('vendor/autoload.php');

    use Symfony\Component\Translation\Translator;
    use Symfony\Component\Translation\MessageSelector;
    use Symfony\Component\Translation\Loader\ArrayLoader;

    $translator = new Translator('fr_FR', new MessageSelector());
    $translator->setFallbackLocales(array('fr'));
    $translator->addLoader('array', new ArrayLoader());
    $translator->addResource('array', array(
        'Hello World!' => 'Bonjour',
    ), 'fr');

    echo $translator->trans('Hello World!')."\n";

php - Use Symfony 2 component in non-Symfony project? - Stack Overflow

php symfony2 internationalization xliff
Rectangle 27 0

You may want to look into a PHP Templating Engine. I use PHPTAL on a lot of projects. Twig (not listed there) is also popular I think, possibly because Symfony is popular.

The goal is to keep PHP code with PHP code and prevent constant breaking in and out of php tags.

Ha this may be excatly what i'm looking for. Is PHPTAL ok to use with an MVC structure?

@SaffronHarris I would say it's even easier to use PHPTAL with an MVC structure than not, although it is a stand-alone templating engine (i.e. it's not completely automatic for MVC). I've heard some criticism of PHPTAL too, so be careful with your choice.

Oh wow, thanks!! The example i'm seeing on there are excatly what i'm looking for, and it's easy to understand as well. But you've haven't had probs with PHPTAL right?

@SaffronHarris not any kind of problems I wouldn't expect from other templating engines.

haha i see what you did there hahaha, thanks Explosion Pills :)

Restructuring PHP code in HTML - Stack Overflow

php html
Rectangle 27 0

IIS doesn't support URL rewriting very well, which is a requirement of Symfony's routing to work. Essentially, the webserver is supposed to redirect all requests to non-existing files/paths to Symfony's index.php, passing along with it the original URL requested. Symfony decodes this URL and applies its routing rules.

php - Problem with Symfony routing with online project - Stack Overflo...

php iis-7 routing symfony1 isapi-rewrite
Rectangle 27 0

I've found the solution. I added this code to the top of my index.php

$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];

I tried everything within the Symfony on IIS tutorial (http://trac.symfony-project.org/wiki/symfonyOnIIS) and nothing made a difference. If anyone else runs into this problem, please try adding the above code first before mucking with any settings or .htaccess rules.

php - Problem with Symfony routing with online project - Stack Overflo...

php iis-7 routing symfony1 isapi-rewrite
Rectangle 27 0

To enable it the rewrite module, run "apache2 enable module rewrite":

sudo a2enmod rewrite

You need to restart the webserver to apply the changes:

sudo service apache2 restart
DocumentRoot /var/www/project_path
<Directory /var/www/project_path>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ /app.php [QSA,L]
    </IfModule>
</Directory>

this option is redirect your index.php, index.html or whatever:

Options Indexes FollowSymLinks MultiViews
<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ /app.php [QSA,L]
    </IfModule>

php - Symfony 2 project in nested directory - Stack Overflow

php symfony2
Rectangle 27 0

For Symfony 2.0.x and Doctrine 2.1.x. projects you'll need to specify the compatible versions of the extensions in deps, this is what worked for me:

[DoctrineExtensions]
    git=https://github.com/l3pp4rd/DoctrineExtensions.git
    target=/gedmo-doctrine-extensions
    version=origin/doctrine2.1.x

[StofDoctrineExtensionsBundle]
    git=https://github.com/stof/StofDoctrineExtensionsBundle.git
    target=/bundles/Stof/DoctrineExtensionsBundle
    version=1.0.2

php - Installing Doctrine extensions in a Symfony 2 project causes Fat...

php symfony2 doctrine2 doctrine-extensions stofdoctrineextensions
Rectangle 27 0

Try logging into the server and changing into the Symfony project's root directory. There's probably a "symfony" script/link there (the details depend on your OS and how Symfony's set up; you might be able just to run ./symfony rather than needing php symfony). Run this to see whether this basics are working:

php symfony

If that works, you should get a list of possible tasks you can do. If you're using the sfGuardPlugin, you should see some tasks like guard:create-user.

To get more information on a task, try something like:

php symfony help guard:create-user

But basically, assuming a fairly modern Symfony installation and plugin, try something like:

php symfony guard:create-user --env=prod newusername newpassword

(the --env=prod option creates the user in the production environment, which is probably what you want.)

If there are super-user-only tasks you want to do, try also doing this:

php symfony guard:promote newusername

You'll probably also find a guard:change-password task which will simply reset the password for a given user.

Thanks! Exactly what I was looking for. I keep this for future reference. (is this documented somewhere?)

@cstamas Symfony command-line tasks are discussed in a few different places throughout the documentation; a thorough treatment is probably best found here in the Reference. For the tasks added by sfGuardPlugin, check the "Readme" tab of the sfGuardPlugin plugin page, though the best way to know exactly what your version of the plugin does is probably symfony help <task_name> for the guard tasks you see when you run symfony.

database - Symfony sfGuardPlugin password recovery - Stack Overflow

database symfony1 passwords recovery