我在我的Phalcon項目中使用了很多Ajax,並且每個請求都由特定的控制器/動作處理,其中我禁用了模板呈現(僅呈現視圖)。如何停止渲染爾康模板使用Ajax時?
我怎麼能全局禁用模板時,如果呼叫使用Ajax做?
我在我的Phalcon項目中使用了很多Ajax,並且每個請求都由特定的控制器/動作處理,其中我禁用了模板呈現(僅呈現視圖)。如何停止渲染爾康模板使用Ajax時?
我怎麼能全局禁用模板時,如果呼叫使用Ajax做?
對於一個具體的行動,你可以使用這些實現的:
public function saveAction()
{
$this->view->disable();
// Operations go here.....
$this->view->pick('some/view/to/display');
}
public function resetAction()
{
$this->view->disable();
// Operations go here.....
echo 'reset action'
}
public function cancelAction()
{
$this->view->disable();
// Operations go here.....
$response = new \Phalcon\Http\Response();
$response->setStatusCode(200, 'OK');
$response->setContentType('application/json', 'UTF-8');
$response->setJsonContent('some content goes here', JSON_UNESCAPED_SLASHES);
return $response->send();
}
我找到了答案:)
abstract class ControllerBase extends Controller
{
/**
* Called in each Controller/Action request
*/
public function initialize(){
if($this->request->isAjax()){
$this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
}
...
或'$這個 - >查看 - >禁用();' – yergo
可用的渲染級別是:
Class Constant Description Order LEVEL_NO_RENDER Indicates to avoid generating any kind of presentation. LEVEL_ACTION_VIEW Generates the presentation to the view associated to the action. 1 LEVEL_BEFORE_TEMPLATE Generates presentation templates prior to the controller layout. 2 LEVEL_LAYOUT Generates the presentation to the controller layout. 3 LEVEL_AFTER_TEMPLATE Generates the presentation to the templates after the controller layout. 4 LEVEL_MAIN_LAYOUT Generates the presentation to the main layout. File views/index.phtml 5
對於更多信息請參見:control-rendering-levels
你應該接受的答案之一。 – Timothy