[Symfony] How to add a new controller
查看有哪些指令可以用
[eric_tu@localhost eric_tu]$ php bin/console list --no-debug
找到個命令可以列出所有route
[eric_tu@localhost eric_tu]$ php bin/console debug:router
-------------------------- ---------- -------- ------ -----------------------------------
Name Method Scheme Host Path
-------------------------- ---------- -------- ------ -----------------------------------
_wdt ANY ANY ANY /_wdt/{token}
_profiler_home ANY ANY ANY /_profiler/
_profiler_search ANY ANY ANY /_profiler/search
_profiler_search_bar ANY ANY ANY /_profiler/search_bar
_profiler_info ANY ANY ANY /_profiler/info/{about}
_profiler_phpinfo ANY ANY ANY /_profiler/phpinfo
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results
_profiler_open_file ANY ANY ANY /_profiler/open
_profiler ANY ANY ANY /_profiler/{token}
_profiler_router ANY ANY ANY /_profiler/{token}/router
_profiler_exception ANY ANY ANY /_profiler/{token}/exception
_profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css
_twig_error_test ANY ANY ANY /_error/{code}.{_format}
testAPI GET ANY ANY /api/test
page GET ANY ANY /page/{page}
list ANY ANY ANY /{page}
add ANY ANY ANY /add
show GET ANY ANY /show/{id}
showall ANY ANY ANY /showall
edit GET|POST ANY ANY /edit/{id}
delete ANY ANY ANY /delete/{id}
apiList ANY ANY ANY /api/list/{page}
apiAdd POST ANY ANY /api/add
api/edit PUT ANY ANY /api/edit/{id}
deleteAPI DELETE ANY ANY /api/delete/{id}
app_laki_number ANY ANY ANY /laki/number/{max}
Msg_list ANY ANY ANY /msgboard/{id}
Msg_show ANY ANY ANY /msgboard/{slug}
-------------------------- ---------- -------- ------ -----------------------------------
system_homepage:
path: /
defaults: { _controller: SystemBundle:System:index }
system_about:
path: /about
defaults: { _controller: SystemBundle:System:about}
system_contact:
path: /contact
defaults: { _controller: SystemBundle:System:contact}
system_pkg:
path: /pkgs
defaults: { _controller: SystemBundle:System:pkgs}
可以到 routing.yml 中設定對應的route
<?php
namespace SystemBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class SystemController extends Controller
{
public function indexAction()
{
return $this->render('SystemBundle:Pages:index.html.twig');
}
public function pkgsAction(){
return $this->render('SystemBundle:Pages:pkg.html.twig');
}
public function aboutAction(){
return $this->render('SystemBundle:Pages:about.html.twig');
}
public function contactAction(){
return $this->render('SystemBundle:Pages:contact.html.twig');
}
}
新增完之後,如果不能訪問,可以去清一下cache
php bin/console cache:clear --no-warmup -e prod
清完之後注意 var/* 底下的權限
留言
張貼留言