我的index.phtml中有很多网址,但是当我尝试使用它们时,我仍然在主页! 我试图使用许多函数basepath(),url()但我有同样的问题。 这是我的控制器:
class VehiculesController extends AbstractActionController
{
/**
* @var Doctrine\ORM\EntityManager
*/
protected $_objectManager;
protected function getObjectManager()
{
if (!$this->_objectManager) {
$this->_objectManager=$this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
}
return $this->_objectManager;
}
public function indexAction()
{
$vehicules = $this->getObjectManager()->getRepository('Vehicules\Entity\Vehicule')
->findAll();
return new ViewModel(array('vehicules' => $vehicules));
}
public function VehLibreAction()
{
$view = new ViewModel();
$view->setTemplate('Vehicules/Vehicules/VehLibre');
return $view;
}
public function VehReserveAction()
{
$view = new ViewModel();
$view->setTemplate('Vehicules/Vehicules/VehReserves');
return $view;
}
public function VehIndisponibleAction()
{
$view = new ViewModel();
$view->setTemplate('Vehicules/Vehicules/VehIndisponible');
return $view;
}
public function VehHorServicAction()
{
$view = new ViewModel();
$view->setTemplate('Vehicules/Vehicules/VehHorServic');
return $view;
}
}
这是我的index.phtm
<div>
<div>
<div>
<div>
<h3>liste des véhicules</h3>
</div>
<div>
<div> <a href="<?php echo $this->url('vehicules', array('action'=>'VehLibre'));? >"> liste des Vehicules libres</a></div>
<div><a href="<?php echo $this->basePath("vehicules/vehicules/VehLibre"); ?>">liste des Vehicules reservés</a></div>
<div><a href="<?php echo $this->url('vehicules', array('action'=>'VehIndisponible'));? >">liste des Vehicules indisponibles</a></div>
<div><a href="<?php echo $this->url(NULL, array('controller'=>'vehicules','action'=>'VehHorServic'));?>">liste des Vehicules hors service</a></div>
<?php if (isset($vehicules)) : ?>
<table class="table">
<thead>
<tr>
<th>Marque</th>
<th>Matricule</th>
<th></th>
</tr>
</thead>
<?php foreach($vehicules as $v): ?>
<tbody>
<tr>
<td><?php echo $v->getIdveh(); ?></td>
<td><?php echo $v->getMatricule(); ?></td>
</tr>
</tbody>
<?php endforeach; ?>
</table>
<?php endif; ?>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
网址 -
<?php echo $this->url('vehicules/default', array('controller'=>'vehicules', 'action'=>'VehLibre')); ?>
和
<?php echo $this->url('vehicules/default', array('controller'=>'vehicules', 'action'=>'VehIndisponible'));? >
通过将module.config.php
中的路线设置为:
'router' => array(
'routes' => array(
'vehicules' => array(
'type' => 'Literal',
'options' => array(
'route' => '/vehicules',
'defaults' => array(
'__NAMESPACE__' => 'Vehicules\Controller',
'controller' => 'Vehicules',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
),
...
),
现在应该可以了。
答案 1 :(得分:0)
这是我的module.php
<?php
return array(
'controllers' => array(
'invokables' => array(
'Vehicules\Controller\Vehicules' => 'Vehicules\Controller\VehiculesController',
'Vehicules\Controller\option' => 'Vehicules\Controller\optionController',
),
),
'router' => array(
'routes' => array(
'vehicules' => array(
'type' => 'Literal',
'options' => array(
// Change this to something specific to your module
'route' => '/vehicules',
'defaults' => array(
// Change this value to reflect the namespace in which
// the controllers for your module are found
'__NAMESPACE__' => 'Vehicules\Controller',
'controller' => 'Vehicules',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
// This route is a sane default when developing a module;
// as you solidify the routes for your module, however,
// you may want to remove it and replace it with more
// specific routes.
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'Vehicules' => __DIR__ . '/../view',
),
),
'doctrine' => array(
'driver' => array(
'Vehicules_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/Vehicules/Entity')
),
'orm_default' => array(
'drivers' => array(
'Vehicules\Entity' => 'Vehicules_driver'
)
)
)
)
);