我在CakePHP 2.7中创建了一个网站。我有一个名为AdsController.php的控制器并创建了一个名为buscar()的操作;
在AdsController.php的buscar()中:
// método para buscar
public function buscar(/* $uf = null,
$city = null,
$newspaper = null, */
$year1 = null, $month1 = null, $day1 = null, $year2 = null, $month2 = null, $day2 = null) { // tenho que validar os nulos
$options = array(
'conditions' => array(
"Ad.created >=" => $year1 . '-' . $month1 . '-' . $day1 . ' 00:00:00',
"Ad.created <=" => $year2 . '-' . $month2 . '-' . $day2 . ' 23:59:59'
)
);
$this->set(
array(
'ad' => $this->Ad->find('first', $options),
'_serialize' => array('ad')
)
);
}
app / Config / routes.php
<?php
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
//Criando RESTful
//Router::mapResources('ads');
// Ativando rotas RESTful
Router::connect('/ads/:year1/:month1/:day1/:year2/:month2/:day2', array('controller' => 'ads', 'action' => 'buscar'), array(
'year1' => '[12][0-9]{3}',
'month1' => '0[1-9]|1[012]',
'day1' => '0[1-9]|[12][0-9]|3[01]',
'year2' => '[12][0-9]{3}',
'month2' => '0[1-9]|1[012]',
'day2' => '0[1-9]|[12][0-9]|3[01]',
)
);
/**
* Load all plugin routes. See the CakePlugin documentation on
* how to customize the loading of plugin routes.
*/
CakePlugin::routes();
/**
* Load the CakePHP default routes. Only remove this if you do not want to use
* the built-in default routes.
*/
require CAKE . 'Config' . DS . 'routes.php';
// Ativando extensão .json
Router::parseExtensions('json');
索引为http://localhost/classificado
。
当我调用操作时,例如localhost/classificado/ads/buscar/2015/09/01/2015/10/10
,或者当我调用localhost/classificado/ads/2015/09/01/2015/10/10
时,请指向routes.php,它转到localhost/classificado/classificado/ads/add
并抛出错误:
无法找到ClassificadoController。
但我没有重定向到此。请帮帮我。