1、新建并激活Bundle【AppBundle】
~~~
php app/console generate:bundle
~~~
`编辑:app/AppKernel.php`
~~~
<?php
public function registerBundles()
{
return array(
#……
new AppBundle\AppBundle(),
);
}
~~~
2、新建controller【AppBundle:Ajax】
~~~
php app/console generate:controller
~~~
3、新建Action
`编辑:src/Appbundle/Controller/DefaultController`
~~~
<?php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
class DefaultController extends Controller{
/**
* @Route("/test", name="test")
* @Template()
*/
public function testAction(){
return array();
}
}
~~~
`编辑:src/Appbundle/Controller/AjaxController`
~~~
<?php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;
class AjaxController extends Controller{
/**
* @Route("/ajax_test", name="ajax_test")
*/
public function ajax_testAction(){
return new Response('今天是'.$_REQUEST['d']);
}
}
~~~
4、新建Twig模板
`新建:src/Appbundle/Resources/views/Default/test.html.twig`
~~~
<script type="text/javaxcript" src="jquery"></script>
<script type="text/javaxcript">
$(function(){
$("p").click(function(){
var d = $(this).text();
$.ajax({
type: "get",
url: "{{ path('ajax_text') }}",
data: { d : d },
success: function(r){
alert(r);
}
});
})
})
</script>
<h1>test ajax</h1>
<p>星期一</p>
<p>星期二</p>
<p>星期三</p>
<p>星期四</p>
<p>星期五</p>
<p>星期六</p>
<p>星期日</p>
~~~
- 安装
- 配置
- web服务器
- DependencyInjection
- Serializer
- Ajax
- Annotation
- Controller
- Entity
- Components【组件】
- HttpFoundation【HTTP处理】
- Routing【路由处理】
- Form【表单处理】
- Validator【验证处理】
- ClassLoader【类加载】
- Templating【模板】
- Security【处理安全问题】
- Translation【语言翻译】
- Bundles【功能包】
- Doctrine
- entityManager
- entityRespository
- createQueryBuilder
- createNativeQuery
- find
- DoctrineBundle
- doctrine_config
- DoctrineFixturesBundle
- KnpMenuBundle
- KnpPaginatorBundle
- FOSUserBundle
- FOSRestBundle
- FOSCommentBundle
- FOSElasticaBundle
- SonataCoreBundle
- SonataBlockBundle
- SonataMediaBundle
- SonataAdminBundle
- DoctrineORMAdminBundle
- Sonata
- Install_Sonata
- Config_Sonata
- BlockService
- Custom_BlockService
- Custom_Admin
- Problems