Oddly enough I ran into this problem yesterday as well that I am trying to track down. I have used AjaxContext/ContextSwitching without a problem in the past so I am not sure what is happening.
The view that is rendered is: update-module-preferences.phtml when it should be update-module-preferences.ajax.phtml. This was verified through Firebug. In addition I also tested in the action if the request was an ajax request ($this->_request->isXmlHttpRequest() ? "Yes" : "No";) and the response is yes.
I am using jQuery as my javascript library.
Controller:
[code]
public function init() {
$this->_logger = Zend_Registry::get('logger');
$this->_globalConfig = Zend_Registry::get('globalConfig');
$this->_homepageConfig = Zend_Registry::get('hpConfig');
$this->_helper->layout->setLayout('layout-mystjude');
$this->_ajaxContext = $this->_helper->getHelper('AjaxContext');
$this->_ajaxContext->addActionContext('update-module-preferences', 'html');
$this->_ajaxContext->initContext();
$this->_modulePreferences = new SjcrhModulePreferences();
$this->_joomlaContent = new JoomlaContent();
}
public function updateModulePreferencesAction() {
if ($this->_request->isPost()) {
$auth = Zend_Auth::getInstance()->getIdentity();
$this->_userId = $auth['username'];
$module = $this->view->escape($this->_getParam('mod'));
$status = $this->view->escape($this->_getParam('status'));
$where = $this->_modulePreferences->getAdapter()
->quoteInto('username = ? ', $this->_userId);
$select = $this->_modulePreferences->select()->where($where);
$row = $this->_getModulePositions($this->_userId);
$positions = split(",", $row);
foreach ($positions as $k => $position) {
$regex = "/(".$module.")=(show|hide)/i";
$replacement = '${1}='.$status;
$positions[$k] = preg_replace($regex, $replacement, $positions[$k]);
}
$data = array('positions' => implode($positions, ","));
$this->_modulePreferences->update($data, $where);
$userLog = SJCRH_Util::logUserAction($this->_userId, "{$module} Updated");
$this->view->ajax = $this->_request->isXmlHttpRequest() ? "Yes" : "No";
}
}
[/code]
Ajax Call
[code]
$.ajax({
url: '/home/mystjude/index/update-module-preferences/mod/' + divid + '/status/' + divStatus,
type: 'POST',
dataType: 'text',
error: function(){
$("#message").html('Error saving preferences');
},
success: function(data){
$("#message").css("background-color", "yellow").html("Preference Saved").show().fadeOut();
}
});
[/code]
View Script [update-module-preferences.ajax.phtml is an empty file since all that is done is posting]
--
Cory Wiles
kwylez@gmail.com
http://www.corywiles.com
http://www.400mtogo.com
The view that is rendered is: update-module-preferences.phtml when it should be update-module-preferences.ajax.phtml. This was verified through Firebug. In addition I also tested in the action if the request was an ajax request ($this->_request->isXmlHttpRequest() ? "Yes" : "No";) and the response is yes.
I am using jQuery as my javascript library.
Controller:
[code]
public function init() {
$this->_logger = Zend_Registry::get('logger');
$this->_globalConfig = Zend_Registry::get('globalConfig');
$this->_homepageConfig = Zend_Registry::get('hpConfig');
$this->_helper->layout->setLayout('layout-mystjude');
$this->_ajaxContext = $this->_helper->getHelper('AjaxContext');
$this->_ajaxContext->addActionContext('update-module-preferences', 'html');
$this->_ajaxContext->initContext();
$this->_modulePreferences = new SjcrhModulePreferences();
$this->_joomlaContent = new JoomlaContent();
}
public function updateModulePreferencesAction() {
if ($this->_request->isPost()) {
$auth = Zend_Auth::getInstance()->getIdentity();
$this->_userId = $auth['username'];
$module = $this->view->escape($this->_getParam('mod'));
$status = $this->view->escape($this->_getParam('status'));
$where = $this->_modulePreferences->getAdapter()
->quoteInto('username = ? ', $this->_userId);
$select = $this->_modulePreferences->select()->where($where);
$row = $this->_getModulePositions($this->_userId);
$positions = split(",", $row);
foreach ($positions as $k => $position) {
$regex = "/(".$module.")=(show|hide)/i";
$replacement = '${1}='.$status;
$positions[$k] = preg_replace($regex, $replacement, $positions[$k]);
}
$data = array('positions' => implode($positions, ","));
$this->_modulePreferences->update($data, $where);
$userLog = SJCRH_Util::logUserAction($this->_userId, "{$module} Updated");
$this->view->ajax = $this->_request->isXmlHttpRequest() ? "Yes" : "No";
}
}
[/code]
Ajax Call
[code]
$.ajax({
url: '/home/mystjude/index/update-module-preferences/mod/' + divid + '/status/' + divStatus,
type: 'POST',
dataType: 'text',
error: function(){
$("#message").html('Error saving preferences');
},
success: function(data){
$("#message").css("background-color", "yellow").html("Preference Saved").show().fadeOut();
}
});
[/code]
View Script [update-module-preferences.ajax.phtml is an empty file since all that is done is posting]
On Thu, Jul 31, 2008 at 7:57 AM, Matthew Weier O'Phinney <matthew@zend.com> wrote:
-- Ramon de la Fuente <ramon@delafuente.nl> wrote
(on Thursday, 31 July 2008, 10:27 AM +0200):
I've been using AjaxContext and ContextSwitch without issue. Is it> I have started using the AjaxContext helper, but I'm running into the
> problem that although the right viewscript is being called
> (action.ajax.phtml), the Layout is not being disabled by default. I read
> this should happen when using ContextSwitch, and in the maual it states
> that AjaxContext is a special case of ContextSwitch; Am I reading it
> wrong?
possible that you're forwarding to another action? That could
potentially re-enable the layout.
Otherwise, can you provide a reproduce case for me to examine?
--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/
--
Cory Wiles
kwylez@gmail.com
http://www.corywiles.com
http://www.400mtogo.com
没有评论:
发表评论