After the symfony installation is completed, you enter the homepage, but the css style is not rendered.
PHP中文网
PHP中文网 2017-05-16 16:44:32
0
4
615

Effect display

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(4)
習慣沉默

It should be caused by the css file not existing. Check if there are css resources now

漂亮男人

I have to say you programmers. . .

Various systems including symfony, wiki system,
In addition, wordpress, inews, etc. can write the address as /index.php/M/V/C, or /M/V/C.html,
It is normal for CSS not to be displayed in some cases, and the reason for this, from the front-end perspective, is that 99% of the time the CSS cannot be found.
WordPress uses Google fonts and the page does not display for a long time. This is another topic.

From the background, some systems will provide solutions, such as CI, which is written as /index.php/M/V/C. This type will find CSS. This is because CI itself is more conscientious. (There may be. I looked at the CI manual a few days ago and vaguely remembered this implementation.) There are also many other things that will be implemented, not just CI.
The implementation principle is /index.php/css/template.css. It will pass /css/template.css as a parameter to index.php, and then use PHP to read it out.

Some things are a little trickier,
He wants to use rewrite but index.php does not provide this method, which directly leads to /index.php/css/template.css. The parameters passed in do not work, which directly leads to the CSS not being displayed.
For example: mediawiki, someone installed mediawiki in the first few days, but did not do rewrite, so it would not be displayed.

Some server software, such as nginx, in some cases pass parameters in by default,
For example, when visiting www.test.com/M/V/C, nginx will parse it into www.test.com/index.php/M/V/C, and it will display those with conscience.
Of course, some foolishly look for the M/V/C directory of the server directory, and of course 403/404.

I have said so much above,
If you don’t understand, just think that I am talking to myself. Here are the key points, analyzing this issue from a deep level.

The key point is:

Rewriting mechanism, or rewrite.
Generally, those who write PHP will have experience, and the website will definitely have a large number of parameters, such as www.bbs.com/forum.php?mod=forumdisplay&fid=25

But some php sites do not have it. For example, if you visit discuz, http://www.discuz.net/forum-10-1.html, this example page, the root directory of the website will definitely not have forum-10-1.html. file, because firstly, it may be unsafe if the root directory has write permissions, and secondly, this file needs to be updated in real time, which means that it is equivalent to returning to the era when text files were used as databases. The hard disk is under great pressure and breaks down quickly.

Of course, what should I do if this file does not exist?

Of course the server software nginx/lighttpd/apache comes into play at this time.
Apache is the simplest. Most systems will have a .htaccess file for you. You just need to drop this file into the root directory of the website.
It is said that nginx can also use .htaccess files, but I have never used it. They are all configured manually.
lighttpd must be configured manually.

Now you access this file,
For example, when nginx, the boss lady, receives this request, she will definitely say to the outside world, "Oh no, everyone is here. Stop working and sit down for a while." She will serve you tea immediately, and then immediately ask the waiter to prepare it.
When the waiter saw that the landlady wanted to serve tea, he went to prepare tea leaves and boiling water.
The guy here is naturally the rewrite module of nginx.
How to write the nginx module: (Here is a rewrite of the page http://www.discuz.net/thread-998595-1-1.html)

rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /viewthread.php?tid=&extra=page%3D&page= last;

The function of the above line of code is,
Any URL of the type http://www.discuz.net/thread-998595-1-1.html will be directly converted into www.discuz.net/viewthread.php?tid=998595&extra=page%3D1&page=1 form.
Of course, this line of code is a bit old, and the new discuz no longer uses this rewrite rule. If you visit this page and it gets a 404, it doesn't mean what I said was wrong.

The writing method of htaccess for similar rules is as follows: (Here is a rewrite of the page http://www.discuz.net/forum-10-1.html)

RewriteRule ^(.*)/forum-(\w+)-([0-9]+)\.html$ /forum.php?mod=forumdisplay&fid=&page=&%1

Speaking of which,
The reason why your problem occurs is,
The CSS file is passed into app_dev.php as a parameter, so naturally the css cannot be found.

The specific solutions are also given to you:
First: Baidu symfony rewrite app_dev.php
Second: the rewriting mechanism relies on regular expressions. No matter which server software can escape.
Third, learn regular expressions in minutes. Address: http://www.jb51.net/tools/zhengze.html

http://symfony.cn/articles/symfony2-nginx-configuration.html
Please understand this line carefully: rewrite ^/app.php/?(.*)$ /$1 permanent;

By the way: Graduates looking for internship positions.

滿天的星座

Same as above, use a virtual host and do not access the entry file directly

曾经蜡笔没有小新

Use the command line to enter the project root directory and run:

app/console assets:install web

Go back to the browser and refresh it, you should see it. The reason is that after the installation is completed, the installation of resource files such as css is missing (this may be the case under Windows, I have not played sf2 on Windows). The above command will install the resource files in the sf2 default demo Bundle to the web/bundles directory. .

Hope this helps.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!