3
我已經使用Sonata Admin Bundle創建了表單。然後,我已經建立了我自己的控制器(的TestController)和覆蓋CRUD控制器,從ajax調用控制器的自定義函數symfony2
我已經添加的一個的TestController新功能,
namespace IFI2\MainProjectBundle\Controller;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Bridge\Monolog\Logger;
use Sonata\AdminBundle\Controller\CRUDController as Controller;
//use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
class TestController extends Controller
{
public function getProductPricesAction() {
file_put_contents("/Applications/XAMPP/htdocs/IFI2 CMS/Logs.txt","HELO",FILE_APPEND);
return new Response(json_encode($response));
}
}
然後我想通過訪問這個功能我JavaScript代碼,
<script type="text/javascript">
function test1() {
$.ajax({
type:"POST",
//dataType: "json",
url: '{{ path('main_project.admin.test')}}',
success: function(successMsg) {
alert("successMsg");
},
error: function(errorMsg) {
alert("errorMsg");
}
});
}
</script>
這裏是我的routing.yml,
main_project.admin.test:
pattern: /getProductPrices/
defaults: { _controller: IFI2MainProjectBundle:Test:getProductPrices}
我已經公頃d services.yml進入這個實體,
main_project.admin.cobrand:
class: MainProjectBundle\Admin\TestAdmin
arguments: [~, MainProjectBundle\Entity\Test, "MainProjectBundle:Test"]
tags:
- {name: sonata.admin, manager_type: orm, group: admin, label: Test}
calls:
- [setTemplate, [edit, MainProjectBundle:Test:edit.html.twig]]
我在我的迴應得到以下錯誤,
沒有爲控制器MainProjectBundle\Controller\TestController
和當前路由main_project.admin.test
請定義_sonata_admin
,幫我怎麼嵌入它?
感謝, 費薩爾納西爾
如何在集合中添加路由參數?我想添加id作爲參數 –
它在兩個變體中都是相同的: path('base_route_name_get_product_prices',{'id':1}) admin.generateUrl('get_product_prices',{'id':1}) –