Symfony(1)Installation and Tour
1. Install symfoy
Check the PHP version on my machine
>php --version
PHP 5.4.24 (cli) (built: Jan 19 2014 21:32:15) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
That is not the latest stable version. I plan to update that. Check the latest version here
http://us2.php.net/downloads.php
>sudo rm -fr /usr/bin/php
>wget http://us1.php.net/distributions/php-5.5.13.tar.gz
Unzip that file
>./configure --prefix=/Users/carl/tool/php-5.5.13
>make
>make install
Then add the bin directory to the working environment
>php --version
PHP 5.5.13 (cli) (built: May 30 2014 18:07:00) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
Before we install Symfony, we first need composer.
https://getcomposer.org/
>curl -sS https://getcomposer.org/installer | php
When I do this, I got Error Information
#!/usr/bin/env php Some settings on your machine make Composer unable to work properly.Make sure that you fix the issues listed below and run this script again:The openssl extension is missing, which means that secure HTTPS transfers are impossible.If possible you should enable it or recompile php with --with-openssl
Solution:
Reinstall the php with openssl.
>./configure --prefix=/Users/carl/tool/php-5.5.13 --with-openssl
Error Message when I execute the command make
Undefined symbols for architecture x86_64:
Solution:
http://www.devsumo.com/technotes/2013/02/building-php-on-os-x/
>export LDFLAGS=-lresolv
>make clean
>make
Still not working, Error Message
Undefined symbols for architecture x86_64: "_iconv_close", referenced from: _zif_iconv_substr in iconv.o _zif_iconv_mime_encode in iconv.o _php_iconv_string in iconv.o __php_iconv_strlen in iconv.o __php_iconv_strpos in iconv.o __php_iconv_mime_decode in iconv.o _php_iconv_stream_filter_cleanup in iconv.o ... "_iconv_open", referenced from: _zif_iconv_substr in iconv.o _zif_iconv_mime_encode in iconv.o _php_iconv_string in iconv.o __php_iconv_strlen in iconv.o __php_iconv_strpos in iconv.o __php_iconv_mime_decode in iconv.o _php_iconv_stream_filter_factory_create in iconv.o ... ld: symbol(s) not found for architecture x86_64
Solution:
http://superuser.com/questions/394219/compiling-php-on-os-x-iconv-works-only-if-forced-to-64-bit
http://miphol.com/muse/2013/08/libiconv-on-mac-os-x-1084.html
http://stackoverflow.com/questions/5835847/libiconv-2-dylib-mac-os-x-problem
Backup and delete the related files under /opt/local/lib
>cd /opt/local/lib
>sudo mv libiconv.* /Users/carl/data/baklib/
>cd /Users/carl/data/baklib
>ls
-rw-r--r-- 1 root admin 1048064 Nov 18 2013 libiconv.2.dylib -rw-r--r-- 1 root admin 1096256 Nov 18 2013 libiconv.a lrwxr-xr-x 1 root admin 16 Nov 18 2013 libiconv.dylib -> libiconv.2.dylib
>./configure --prefix=/Users/carl/tool/php-5.5.13 --with-openssl --with-iconv-dir=/usr/lib
>make
>make install
After the installation, I will copy my backup libs back to /opt/local/lib, then go on with composer
>curl -sS https://getcomposer.org/installer | php
>mkdir /Users/carl/tool/composer/bin
>mv composer.phar /Users/carl/tool/composer/bin/composer
Check my installation is fine.
>composer --version
Composer version f16e3a88e28228af67cc98950a2b621713f4aac3 2014-06-03 08:46:14
2. Create my First Project
>composer create-project symfony/framework-standard-edition myfirstproject/ ~2.4
Then it will generate the project for me.
>cd myfirstproject/
This is the first time for me to run PHP/Symfony project here on my machine. So I will check the requirements.
>php app/check.php
Information
* WARNING: No configuration file (php.ini) used by PHP!
ERROR date.timezone setting must be set Set the "date.timezone" setting in php.ini* (like Europe/Paris).
WARNING mb_strlen() should be available Install and enable the mbstring extension.
WARNING intl extension should be available Install and enable the intl extension (used for validators).
WARNING a PHP accelerator should be installed Install and enable a PHP accelerator like APC (highly recommended).
WARNING short_open_tag should be disabled in php.ini Set short_open_tag to off in php.ini*.
Solution:
http://www.inmotionhosting.com/support/website/php/setting-the-timezone-for-php-in-the-phpini-file
http://php.net/manual/en/timezones.others.php
http://www.php.net/manual/en/timezones.php
>sudo vi /etc/php.ini
Search for date.timezone
Change the content as follow
date.timezone = "US/Central"
Ok, it does not working, that is only because I am changing the wrong php.ini
>php --ini
Configuration File (php.ini) Path: /Users/carl/tool/php-5.5.13/lib
So go and change the file in that place.
>sudo rm -fr /etc/php.ini
>cp /etc/php.ini.default /opt/php/lib/php.ini
>sudo ln -s /opt/php/lib/php.ini /etc/php.ini
And change the timezone as follow>
date.timezone = America/North_Dakota/Center
Run the first project
>php app/console server:run
Visit the page
http://127.0.0.1:8000/
Error Message:
No route found for "GET /"
Solution:
When I create the project I should use this command.
>composer create-project symfony/framework-standard-edition myfirstproject ~2.4.6
3. Understand the Tour
Hello World Demo is here http://localhost:8000/demo/hello/World
Routing
ProjectName/app/config/routing_dev.yml
ProjectName/src/Acme/DemoBundle/Resources/Config/routing.xml
Controllers
Instead of using PHP global variables and functions($_GET, headers()), Symfony uses objects: Request and Response.
Magic things, PHP annotation, actually, it is JAVA like codes. And PHP also has the idea of Controller.
ProjectName/src/Acme/DemoBundle/Controller/WelcomeController.php
<?php
namespace Acme\DemoBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class WelcomeController extends Controller
…snip...
Bundle under vendor and src
public function indexAction()
{
return $this->render('AcmeDemoBundle:Welcome:index.html.twig');
}
And we can put more stuff in response like this
public function indexAction(){
$response = $this->render(‘AcmeDemoBundle:Welcome:index.txt.twig’);
$response->headers->set(‘Content-Type’, ‘text/plain’);
return $response;
}
AcmeDemoBundle:Welcome:index.html.twig is the logic name, we found the page here
ProjectName/src/Acme/DemoBundle/Resources/views/Welcome/index.html.twig
And in the routing.yml, the routing defined as follow:
_demo_secured:
resource: "@AcmeDemoBundle/Controller/SecuredController.php"
type: annotation
Now we will see, it is said annotation, and the annotation codes are as follow:
/**
* @Route("/hello/{name}", name="_demo_hello")
* @Template()
*/
Templates
Symfony2 uses Twig as its template engine. The template file is just text file, the extension name is not important, .html .htm .twig.
{% … %} is for the control statement.
{{ … }} is for the content statement.
IDE Support for Sublime Text https://github.com/Anomareh/PHP-Twig.tmbundle
References——> Package Control ——> Install Package ——>PHP-Twig
Flow Control
{% for user in users %}
{{ user.username }
{% endfor %}
{% if users|length > 0 %}
…
{% endif %} {# here is the comments #}
Load Other Template
{% include ’sidebar.html’ %}
Even sometimes, the template name can be variables.
{% for box in boxes %}
{% include “render_box.html” %}
{% endfor %}
Bundle - a set of files(PHP files, stylesheets, JavaScripts, images, ...)
Environment - dev and prod
References:
http://symfony.com/
http://symfony.com/get-started
http://symfony.com/doc/current/quick_tour/the_big_picture.html
PHP envirenment
http://sillycat.iteye.com/blog/562652
http://tutorial.symblog.co.uk/
https://github.com/dsyph3r/symblog
https://github.com/Monomachus/FirstSymfony2App
https://github.com/symfony/symfony-standard
Twig template
http://blog.csdn.net/jiaochangyun/article/details/7180758
- 浏览: 2551872 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
发表评论
-
PHP Command Line Tool
2019-08-17 05:06 396PHP Command Line Tool Recently ... -
Code SonarQube 2019(2)PostgreSQL as Database
2019-07-24 05:32 426Code SonarQube 2019(2)PostgreSQ ... -
Code SonarQube 2019(1)Installation with default H2
2019-07-23 10:42 772Code SonarQube 2019(1)Installat ... -
Auth Solution(3)JWT in Java and PHP Sample
2019-05-03 07:33 316Auth Solution(3)JWT in Java and ... -
Flarum BBS System(2)Docker the BBS
2018-11-20 03:31 659Flarum BBS System(2)Docker the ... -
Flarum BBS System(1)Installation and Introduction
2018-11-18 14:29 508Flarum BBS System(1)Installatio ... -
Grav CMS System(5)Multiple Domains and Certs
2018-11-15 01:48 538Grav CMS System(5)Multiple Doma ... -
Grav CMS System(4)Multiple Domain Sites in HAProxy and HTTPS
2018-11-14 21:33 583Grav CMS System(4)Multiple Doma ... -
Grav CMS System(3)Docker Nginx and PHP
2018-11-14 00:21 463Grav CMS System(3)Docker Nginx ... -
Grav CMS System(1)Install PHP7 on MAC
2018-10-23 21:53 637Grav CMS System(1)Install PHP7 ... -
Laravel PHP Framework(1)Introduction and Installation
2018-08-22 02:47 989Laravel PHP Framework(1)Introdu ... -
JSON Log in PHP and Cloud Watch(1)JSON Format in PHP
2017-12-30 05:31 605JSON Log in PHP and Cloud Watch ... -
PHPRedis Library
2017-03-30 00:32 680PHPRedis Library We can instal ... -
PHP Call Wget Command
2017-03-24 23:35 672PHP Call Wget Command In my PH ... -
PHP XML Writer
2017-03-10 03:59 1458PHP XML Writer PHP XML writer ... -
PHP Redis Client and Cluster
2017-02-16 03:34 656PHP Redis Client and Cluster S ... -
PHP Redis Client and Replica
2017-02-16 01:11 599PHP Redis Client and Replica W ... -
PHP HTTP Library and Error Handling
2017-02-11 06:19 656PHP HTTP Library and Error Hand ... -
PHP ENV and HTTP Extension
2017-01-12 01:04 798PHP ENV and HTTP Extension We ... -
PHP Connect Redis Driver
2016-11-23 00:29 584PHP Connect Redis Driver I was ...
相关推荐
例如,“第1章:全景图”通过介绍Symfony2背后的一些最重要的概念和展示一个简单项目的实践,让读者快速入门。如果读者之前使用过其他的网络框架,那么在Symfony2中的感觉应该是很自然的。对于新手,这将是一个全新...
解压密码在:http://www.pin5i.com/showtopic-building-php-applications-with-symfony-cakephp-zend-framework.html
在"symfony-quick_tour"中,我们可以探索Symfony框架的基础知识和核心概念,了解如何高效地使用它来开发Web项目。 首先,Symfony是一个遵循MVC(Model-View-Controller)模式的开源PHP框架,它为开发者提供了丰富的...
**Symfony** Symfony是一款开源的PHP框架,用于构建高质量的、可维护的Web应用程序。它遵循MVC(模型-视图-控制器)架构模式,提供了一套强大的工具来简化Web开发过程,包括路由、依赖注入、事件系统、表单处理、...
在 Symfony 框架中,权限管理是核心功能之一,用于控制不同用户对应用程序的访问权限。本节主要讲解了Symfony内置的权限属性及其在实际应用中的使用。 首先,我们有三个关键的权限属性: 1. **IS_AUTHENTICATED_...
[Symfony][1] is a **PHP framework** for web and console applications and a set of reusable **PHP components**. Symfony is used by thousands of web applications and most of the [popular PHP projects][2...
**Symfony 框架概述** Symfony 是一个高度可重用的 PHP 组件集合,同时也是一款强大的 Web 应用程序开发框架。它遵循 Model-View-Controller (MVC) 设计模式,旨在提高代码的可维护性和扩展性。Symfony 实现了 PHP ...
【标题】: "第03章 运行 Symfony1" 【描述】: "本章将指导您如何运行基于PHP5的Symfony框架。首先,确保您的系统已安装了正确版本的PHP,然后通过沙盒快速试用或通过PEAR或Subversion进行安装。我们将详细解释沙盒...
1. **路由(Routing)**: Symfony的路由系统负责将HTTP请求映射到特定的控制器。在Symfony_metabook_2.0中,对路由的配置、HTTP基础以及路由系统与传统PHP脚本的区别进行了详细说明。例如,文档中提到了强制路由使用...
**Symfony API CHM手册**是针对Symfony框架的重要参考资料,它以离线帮助文档(CHM:Compiled Help Manual)的形式提供,方便开发者在无网络的情况下查阅Symfony框架的各种API和功能。Symfony是一个广泛使用的PHP...
在本书里,你将了解如何使用symfony建立Web应用程序。本书分成五篇:“基础知识”篇,包含所有的基本概念和开始symfony的基本知识;“核心架构”篇,讲述模型视图控制器(MVC)在symfony中的实现,以及如何用这样的...
1. **依赖注入**:Symfony2的核心特性之一是依赖注入(Dependency Injection)。通过DI,开发者可以在不直接创建对象的情况下,将依赖关系传递到类中。这提高了代码的可测试性和可维护性。`依赖注入.rtf`可能详细...
**知识点1:Symfony2概述** Symfony2是一款先进的PHP框架,旨在提供一种结构化、高效且可扩展的方式来构建Web应用程序。它通过一系列可复用的组件和工具简化了开发流程,使开发者能够专注于业务逻辑而非基础架构。 ...
Symfony2.3.1是在2.3系列中的一个稳定版本,发布于2014年,旨在提供可靠的服务和组件,帮助开发者快速构建复杂的Web应用。 首先,Symfony框架遵循MVC(Model-View-Controller)设计模式,它将业务逻辑、数据处理和...
Symfony框架的快速入门教程,也即"The Quick Tour",是Symfony官方提供的一个入门指南,它通过逐步探索Symfony的各个方面,帮助开发者快速了解Symfony的生态系统,并生成一个简单的Symfony项目实例。开发者将学习...