시도 다양한 솔루션을 가진 후, 내가 가장 쉽고 안정적인 방법은 Kohana_Request_Client_Internal::execute_request
을 무시하는 것으로 나타났습니다. 예를 들어, 하이픈 조치를 추가하는 그런
<?php defined('SYSPATH') or die('No direct script access.');
class Kohana_Request_Client_Internal extends Request_Client {
/**
* @var array
*/
protected $_previous_environment;
/**
* Processes the request, executing the controller action that handles this
* request, determined by the [Route].
*
* 1. Before the controller action is called, the [Controller::before] method
* will be called.
* 2. Next the controller action will be called.
* 3. After the controller action is called, the [Controller::after] method
* will be called.
*
* By default, the output from the controller is captured and returned, and
* no headers are sent.
*
* $request->execute();
*
* @param Request $request
* @return Response
* @throws Kohana_Exception
* @uses [Kohana::$profiling]
* @uses [Profiler]
* @deprecated passing $params to controller methods deprecated since version 3.1
* will be removed in 3.2
*/
public function execute_request(Request $request)
{
// Create the class prefix
$prefix = 'controller_';
// Directory
$directory = $request->directory();
// Controller
$controller = $request->controller();
if ($directory)
{
// Add the directory name to the class prefix
$prefix .= str_replace(array('\\', '/'), '_', trim($directory, '/')).'_';
}
if (Kohana::$profiling)
{
// Set the benchmark name
$benchmark = '"'.$request->uri().'"';
if ($request !== Request::$initial AND Request::$current)
{
// Add the parent request uri
$benchmark .= ' « "'.Request::$current->uri().'"';
}
// Start benchmarking
$benchmark = Profiler::start('Requests', $benchmark);
}
// Store the currently active request
$previous = Request::$current;
// Change the current request to this request
Request::$current = $request;
// Is this the initial request
$initial_request = ($request === Request::$initial);
try
{
if (! class_exists($prefix.$controller))
{
throw new HTTP_Exception_404('The requested URL :uri was not found on this server.',
array(':uri' => $request->uri()));
}
// Load the controller using reflection
$class = new ReflectionClass($prefix.$controller);
if ($class->isAbstract())
{
throw new Kohana_Exception('Cannot create instances of abstract :controller',
array(':controller' => $prefix.$controller));
}
// Create a new instance of the controller
$controller = $class->newInstance($request, $request->response() ? $request->response() : $request->create_response());
$class->getMethod('before')->invoke($controller);
// Determine the action to use
/* ADDED */ if (strpos($request->action(), '_') !== false) throw new HTTP_Exception_404('The requested URL :uri was not found on this server.', array(':uri' => $request->uri()));
/* MODIFIED */ $action = str_replace('-', '_', $request->action()); /* ORIGINAL: $action = $request->action(); */
$params = $request->param();
// If the action doesn't exist, it's a 404
if (! $class->hasMethod('action_'.$action))
{
throw new HTTP_Exception_404('The requested URL :uri was not found on this server.',
array(':uri' => $request->uri()));
}
$method = $class->getMethod('action_'.$action);
$method->invoke($controller);
// Execute the "after action" method
$class->getMethod('after')->invoke($controller);
}
catch (Exception $e)
{
// Restore the previous request
if ($previous instanceof Request)
{
Request::$current = $previous;
}
if (isset($benchmark))
{
// Delete the benchmark, it is invalid
Profiler::delete($benchmark);
}
// Re-throw the exception
throw $e;
}
// Restore the previous request
Request::$current = $previous;
if (isset($benchmark))
{
// Stop the benchmark
Profiler::stop($benchmark);
}
// Return the response
return $request->response();
}
} // End Kohana_Request_Client_Internal
이렇게하려면 "요청 \ 클라이언트 \의 internal.php 응용 프로그램의 \ 클래스 \ kohana \"에 application
폴더에 파일을 추가 한 다음에 그 내용을 설정 , "controller/my-action"은 "my_action()"이라는 액션을 생성합니다.
사용자가 "controller/my_action"에 액세스하려고 시도하면 오류가 발생합니다 (중복 콘텐츠를 방지하기 위해).
일부 개발자는이 방법이 마음에 들지 않지만 장점은 작업의 이름을 바꾸지 않기 때문에 현재 작업을 확인하면 모든 곳에서 일관되게 "내 조치"라고합니다. Route 또는 lambda 함수 메소드를 사용하면 action은 "my_action", 언젠가는 "my-action"이라고 할 수 있습니다 (두 메소드가 모두 액션의 이름을 변경하기 때문에).
이것은 (액션이 아니라 컨트롤러. 'Unofficial Kohana 3.0 Wiki'에는 액션과 컨트롤러 모두에서 작동하지만 중복 된 내용을 처리하지 않는 Konaha_Request (http://kerkness.ca/kowiki/doku.php?id=routing:using_hyphen_in_urls)를 확장하는 비슷한 솔루션이 있습니다. . – ChrisV