我需要POST到ZendFramework2中的自定义视图。
在我的Module文件夹中,我添加了一个名为zfc-user
我通过创建新路径来覆盖模板文件
'template_path_stack' => array(
__DIR__ . '/../view',
'zfc-user' => __DIR__ . '/../view',
),
),
有效。
然后我在application / pdf /上添加了一个自定义视图,名为index.phtml
但是当我做<?php echo $this->url('pdf'); ?>
Message:
Route with name "pdf" not found
'pdf' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/pdf',
'defaults' => array(
'controller' => 'Application\Controller\Pdf',
'action' => 'index',
),
),
),
控制器
<?php
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use DOMPDFModule\View\Model\PdfModel;
class PdfController extends AbstractActionController {
public function indexAction() {
// Instantiate new PDF Model
$pdf = new PdfModel();
// set filename
$pdf->setOption('filename', 'invoice.pdf');
// Defaults to "8x11"
$pdf->setOption('paperSize', 'a4');
// paper orientation
$pdf->setOption('paperOrientation', 'portrait');
return $pdf;
}
}
溃败
'pdf' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/pdf',
'defaults' => array(
'controller' => 'Application\Controller\Pdf',
'action' => 'index',
),
),
),
'controllers' => array(
'invokables' => array(
'Application\Controller\Index' => 'Application\Controller\IndexController',
'Application\Controller\Pdf' => 'Application\Controller\PdfController'
),
),
My form is at Application/view/zfc-user/user/index.phtml
Action script is Application/view/application/pdf/index.phtml
表格
<form action="pdf/index.phtml" method="POST" id="printInvoice" name="printInvoice" class="form-horizontal" role="form">
<div class="form-group">
<label class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input class="form-control" name="yourName" id="yourName" type="text" placeholder="Your Name">
</div>
</div>