Symfony(4)Pages in Symfony2
There is a simple two-step process.
Create a Route
Create a Controller
1. Environment and Front Controllers
There are 3 environment defined — dev, test and prod.
Symfony2 comes with 2 web-accessible front controller: app_dev.php and app.php.
When running in debug mode, Symfony2 runs slower, but all changes are reflected without having to manually clear the cache.
2. Build Simple Hello Page
A bundle is nothing more than a directory that houses everything related to a specific feature, including PHP classes, configuration, and even stylesheets and JavaScript files.
Create the Bundle
>php app/console generate:bundle --namespace=Acme/HelloBundle --format=yml
After that a directory(bundle) is created /src/Acme/HelloBundle, and one line is added to the file app/AppKernel.php.
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new Acme\HelloBundle\AcmeHelloBundle(),
);
Create Router
The root router is already there in #app/config/routing.xml
helloBundle is already there
acme_hello:
resource: "@AcmeHelloBundle/Resources/config/routing.yml"
prefix: /
in the sub routing.xml file src/Acme/HelloBundle/Resources/config/routing.yml
acme_hello_homepage:
pattern: /hello/{name}
defaults: { _controller: AcmeHelloBundle:Default:index }
Create the Controller
Based on the configuration, the src/Acme/HelloBundle/Controller/DefaultController.php will be called and the method should be indexAction
<?php
namespace Acme\HelloBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class DefaultController extends Controller
{
public function indexAction($name)
{
return $this->render('AcmeHelloBundle:Default:index.html.twig', array('name' => $name));
}
}
Then I visit the page http://sdk-consumer.local.sillycat.com/hello/good, it will give me the pages.
I am running that under apache. Here is another way to run it.
>php app/console cache:clear --env=prod --no-debug
>php app/console server:run --env=prod
Create The Template
Instead of writing the HTML inside the controller, render a template file instead.
return $this->render('AcmeHelloBundle:Default:index.html.twig', array('name' => $name));
BundleName:ControllerName:TemplateName
The physical location should be /path/to/BundleName/Resources/views/ControllerName/TemplateName
The twig file template will be as follow:
{# src/Acme/HelloBundle/Resources/views/Hello/index.html.twig #}
{% extends '::base.html.twig' %}
{% block body %}
Hello {{ name }}!
{% endblock %}
Pay attention to the ::base.html.twig, it is missing the BundleName:ControllerName, that means it is under the app/Resources
3. The Directory Structure
The Web Directory
Our front controller is there, app.php, app_dev.php. Actually our visit can be as follow:
http://sdk-consumer.local.sillycat.com/app_dev.php/hello/sillycat
Bundle Directory Structure
Controller/ — contains the controllers of the bundle
DependencyInjection/ — holds certain dependecy injection extension classes, for example, service configuration, compiler passes (optional)
Resources/config/
Resources/views/
Resources/public/ contains web assets(images, stylesheets, etc) and is copied or symbolically linked into the project web/ directory via the assets:install console command
Tests/
>php app/console assets:install
Tips
1. Permission Error when Execute composer update
Error Message:
[ErrorException] touch(): Utime failed: Permission denied
Solution:
Find touch and change the rights
>which touch
/usr/bin/touch
>sudo chmod 755 /usr/bin/touch
Error Message:
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-update-cmd event terminated with an exception [RuntimeException] An error occurred when executing the "'cache:clear --no-warmup'" command.
Solution:
Run this command first, before we do composer update
>sudo rm -fr app/cache/*
>sudo rm -fr app/logs/*
>sudo rm -fr web/bundles/*
The root reason is that the apache is running with user daemon, my current user is carl. So I need to fix as follow:
>sudo chmod +a "daemon allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs web/bundles
>sudo chmod +a "carl allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs web/bundles
References:
http://composer.golaravel.com/04-schema.html#extra Configuration Doc for Composer
http://www.copernica.com/en/support/rest/example-get-post-put-and-delete-requests curl with PHP
http://kiwwito.com/unable-to-write-cache-file-problem-in-symfony-2/ Permission with composer and apache
- 浏览: 2566963 次
- 性别:
- 来自: 成都
-
文章分类
最新评论
-
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 408PHP Command Line Tool Recently ... -
Code SonarQube 2019(2)PostgreSQL as Database
2019-07-24 05:32 436Code SonarQube 2019(2)PostgreSQ ... -
Code SonarQube 2019(1)Installation with default H2
2019-07-23 10:42 780Code SonarQube 2019(1)Installat ... -
Auth Solution(3)JWT in Java and PHP Sample
2019-05-03 07:33 326Auth Solution(3)JWT in Java and ... -
Flarum BBS System(2)Docker the BBS
2018-11-20 03:31 692Flarum BBS System(2)Docker the ... -
Flarum BBS System(1)Installation and Introduction
2018-11-18 14:29 517Flarum BBS System(1)Installatio ... -
Grav CMS System(5)Multiple Domains and Certs
2018-11-15 01:48 548Grav CMS System(5)Multiple Doma ... -
Grav CMS System(4)Multiple Domain Sites in HAProxy and HTTPS
2018-11-14 21:33 592Grav CMS System(4)Multiple Doma ... -
Grav CMS System(3)Docker Nginx and PHP
2018-11-14 00:21 473Grav CMS System(3)Docker Nginx ... -
Grav CMS System(1)Install PHP7 on MAC
2018-10-23 21:53 655Grav CMS System(1)Install PHP7 ... -
Laravel PHP Framework(1)Introduction and Installation
2018-08-22 02:47 994Laravel PHP Framework(1)Introdu ... -
JSON Log in PHP and Cloud Watch(1)JSON Format in PHP
2017-12-30 05:31 612JSON Log in PHP and Cloud Watch ... -
PHPRedis Library
2017-03-30 00:32 690PHPRedis Library We can instal ... -
PHP Call Wget Command
2017-03-24 23:35 679PHP Call Wget Command In my PH ... -
PHP XML Writer
2017-03-10 03:59 1469PHP XML Writer PHP XML writer ... -
PHP Redis Client and Cluster
2017-02-16 03:34 661PHP Redis Client and Cluster S ... -
PHP Redis Client and Replica
2017-02-16 01:11 604PHP Redis Client and Replica W ... -
PHP HTTP Library and Error Handling
2017-02-11 06:19 680PHP HTTP Library and Error Hand ... -
PHP ENV and HTTP Extension
2017-01-12 01:04 806PHP ENV and HTTP Extension We ... -
PHP Connect Redis Driver
2016-11-23 00:29 593PHP Connect Redis Driver I was ...
相关推荐
请参阅上的GitHub Pages。 :chart_increasing: 变化 此项目的所有显着更改将记录在文件中。 这个CHANGELOG是用 :red_heart_selector: 通过 。 该项目遵循。 :bookmark: 路线图 见 :spouting_whale: 支持的...
对于部署到Github Pages和其他非PHP静态网站托管很有用。安装composer require symplify/symfony-static-dumper 如果您不使用Flex,请添加到config/bundles.php : return [ Symplify \ SymfonyStaticDumper \ ...
Use the RxPHP library in combination with Symfony Console The different approaches to using Symfony3's Event Dispatcher component Test your reactive PHP code using PHPUnit Analyze ...
4. `config/`: 存放 Symfony 配置文件,如`services.yaml`,定义了服务及其依赖。 5. `tests/`: 测试代码目录,包括单元测试和集成测试,确保代码的正确性。 6. `composer.json`: 描述项目信息、依赖关系及自动加载...
这个版本是DLOG4J的第三大主要版本,并且处于Beta2测试阶段,意味着它可能包含一些未解决的问题,但已经具备了基本功能,适合开发人员试用和反馈。 【描述】"基于PHP的DLOG4J JSP v3.0 Beta2 开源个人版.zip" 暗示...
2017 | ASIN: B01IF7NLDW | 340 Pages | AZW3 | 2.55 MB Key Features Gain a complete understanding of data structures using a simple approach Analyze algorithms and learn when you should apply each ...
2. **变量和数据类型**:PHP支持多种数据类型,包括字符串、整型、浮点型、数组、对象、布尔值和NULL。变量以$符号开头,无需提前声明类型。 3. **流程控制**:PHP提供条件语句(如if...else、switch)、循环(for...
4. 扩展性:PHP有大量的开源库和框架,如Laravel、Symfony等,而ASP虽然也有组件,但数量和多样性不及PHP。 在使用Asp2Php进行转换时,开发者应考虑以下几点: 1. 测试:转换后,必须对所有PHP文件进行全面测试,...
4. PHP框架:如Laravel或Symfony,可以简化开发流程并提供更好的代码组织结构。 最后,我们讨论ASP(Active Server Pages)的实现。ASP是微软早期的服务器端脚本技术,虽然现在被ASP.NET取代,但在一些旧系统中仍然...
4. **Pages**: "pages"目录可能包含了系统的各个视图或路由,每个文件可能代表一个独立的管理页面,如登录页、用户管理页、数据统计页等。页面结构通常由HTML、CSS和JavaScript共同构建,其中HTML负责内容结构,...
OC-Projet-5_博客Projet博客Openclassrooms du parcoursdéveloppeurd'applications PHP / SYMFONY。... 可以在以下页面上进行以下网站的网站制作: les pages utilesàtous les访问者; les page permettant
2. **ASP, PHP, JSP的优缺点比较**: - ASP(Active Server Pages)使用VBScript或JavaScript作为脚本语言,易于学习,但性能相对较低。 - PHP(Hypertext Preprocessor)跨平台,语法简洁,支持多种数据库,并且...
iOS OS X .NET Framework Man Pages ActionScript Akka Android AngularJS Ansible Appcelerator Titanium Arduino Backbone Bash Boost Bootstrap Bourbon Bourbon Neat C C++ CakePHP Cappuccino Chai Chef ...
Apache2.0在JAVA开发中的应用主要体现在其对Servlets和JSP(JavaServer Pages)的支持。通过集成Tomcat或Jetty等Servlet容器,Apache能够运行JAVA Web应用程序,提供动态内容服务。开发者可以利用这些技术构建企业级...
2. JAVA类: - Java是一种跨平台的面向对象编程语言,常用于企业级应用开发。设计题目可能涵盖Java桌面应用、Web应用或移动应用。 - 知识点:Java核心技术(如集合、多线程、IO流、网络编程)、Java Swing或JavaFX...
4. **JSTL(JavaServer Pages Standard Tag Library)**:提供一系列标准标签,简化JSP页面的编写。 5. **Servlet**:虽然不是JSP的一部分,但作为JSP的基础,理解Servlet的工作原理和API非常重要。 6. **MVC(Model...
2. JAVA类:Java是一种广泛使用的面向对象的编程语言,其毕业设计可能涵盖: - Java SE和Java EE的区别与应用场景 - Servlet和JSP的使用,理解MVC模式 - Spring框架的使用,包括Spring Boot和Spring Cloud - ...
2. JAVA:Java是一种广泛使用的面向对象的编程语言,适用于跨平台应用开发。Java题目可能涵盖: - 使用Servlet和JSP开发Web应用。 - Spring框架的应用,包括Spring Boot、Spring MVC、Spring Data等。 - ...
2. JAVA类题目: Java是一种广泛使用的面向对象的编程语言,适用于各种平台。Java毕业设计涉及的知识点包括: - Java基础语法和面向对象编程 - Spring框架的使用,包括Spring Boot和Spring MVC - 数据库连接池和...
【标题】"基于PHP的淘客JSP在线客服管理系统TaokeOCS v站点版.zip" 涉及的核心技术是PHP编程语言与JSP(JavaServer Pages)在构建在线客服系统中的结合应用。淘客,是指通过推广电商平台的商品赚取佣金的网络营销...