[fw-general] Strange Zend_View->render() ?
Hi all, maybe it's a newbie question, but I still can't find out why this happens.. I managed to create simple IndexController and ErrorController, but I can't make ZF to render another script than index.phtml from indexAction of IndexController. What I need is to show a login form in case that user is not logged in. Here's the code: */ class IndexController extends Zend_Controller_Action { /** * Initialization - invoked in constructor. */ public function init () { //$this->view->addHelperPath('../application/views/helpers', 'Venturia_View_Helper'); $this->view->wwwroot = $this->_request->getBaseUrl(); } /** * The default action - show the home page. */ public function indexAction () { echo 'Index action called.'; $oUserSession = new Zend_Session_Namespace('user'); $oUserSession->id = 1; unset($oUserSession->id); //print_r($_SESSION); //echo $this->_request->getHeader('accept-language'); $this->view->iUserId = $oUserSession->id; $this->view->sBaseUrl = $this->_request->getBaseUrl(); //. $this->_request->getPathInfo(); //user is not logged in => show login page //if (!isset($oUserSession->id)) //{ //echo 'Script Path:' . $this->view->getScriptPath('login.phtml'); $this->view->render('login.phtml', null, false); //echo 'Login'; //} } } ?> The render() method does not seem to be working as claimed in manual. a) script filename must be set with extension too b) AFAIK, login.phtml should be looked for in somepath/views/scripts/index/login.phtml, but it is looked for directly in somepath/views/scripts/ directory (controller's name not used, no matter how the 3rd parameter of render() method is set) c) and the worst, even when set unconditianally as seen in code above, it still renders somepath/views/scripts/index/index.phtml script instead of login.phtml Can anyone explain me please why this happen and even better how to make it work? Thank a lot -- View this message in context: http://www.nabble.com/Strange-Zend_View-%3Erender%28%29---tf4872248s16154.html#a13941930 Sent from the Zend Framework mailing list archive at Nabble.com.
[fw-general] DB: onDelete, good example?
Hi, Anyone who have an address to an good example of onDelete. I saw this in the manual, but it doesn't show the whole process. array( 'columns' => array('product_id'), 'refTableClass' => 'Products', 'refColumns'=> array('product_id'), 'onDelete' => self::CASCADE, 'onUpdate' => self::RESTRICT ), ... ); } /Peter
Re: [fw-general] Ajax way
Hi Peter, But the problem is I am getting "edit.phtml" not found if I don't "die" the action. Or will this change if I do the setHeader content-type? I'm not getting into the JSON part of it but that issue just sounds like you've not disabled the view renderer. Just adding: ...rest of your code... echo json_encode($a_return); $this->_helper->viewRenderer->setNoRender(); Should stop ViewRenderer trying to auto render a view script. http://framework.zend.com/manual/en/ zend.controller.actionhelpers.html#zend.controller.actionhelper.stockhel pers Nick
Re: [fw-general] why Zend_Json::encode? (was: Ajax way)
Not built-in, but bundled, differnt :) Still you have to include the extension to make it make it work... On Mon, 2007-11-26 at 09:33 +1100, Simon Mundy wrote: > Yes, but only if you had the extension - it was built-in to 5.2
Re: [fw-general] why Zend_Json::encode? (was: Ajax way)
Yes, but only if you had the extension - it was built-in to 5.2 What do you mean? It was the same way to call in 5.1.x, wasn't it? On Mon, 2007-11-26 at 09:21 +1100, Simon Mundy wrote: Well, really only for PHP 5.1.x compatibility -- Simon Mundy | Director | PEPTOLAB """ " "" "" "" "" """ " "" " " " " "" "" " Please support Movember today! Visit http://www.movember.com/au/donate Registration number for Simon 160725 202/258 Flinders Lane | Melbourne | Victoria | Australia | 3000 Voice +61 (0) 3 9654 4324 | Mobile 0438 046 061 | Fax +61 (0) 3 9654 4124 http://www.peptolab.com
Re: [fw-general] why Zend_Json::encode? (was: Ajax way)
That one seams more "light" as it wouldn't require any rendering of the view. Or am I incorrect? Should I set the contenttype as well? /Peter On Sun, 2007-11-25 at 23:28 +0100, Stephane wrote: > > class AjaxController extends Zend_Controller_Action > { > >function updateorderAction() >{ > > > Zend_Controller_Front::getInstance()->setParam('noViewRenderer',true); > $this->getResponse()->setBody(json_encode($this->result)); >}
Re: [fw-general] why Zend_Json::encode? (was: Ajax way)
or class AjaxController extends Zend_Controller_Action { function updateorderAction() { Zend_Controller_Front::getInstance()->setParam('noViewRenderer',true); $this->getResponse()->setBody(json_encode($this->result)); } Le Mon, 26 Nov 2007 00:13:11 +0200, Peter Lauri <[EMAIL PROTECTED]> a écrit : > Ok, cool... But why is there a wrapper for a simple function call for > the json, wouldn't json_encode($this->result) be simpler? Or is there > something I don't get? :) > > > On Mon, 2007-11-26 at 09:10 +1100, Simon Mundy wrote: > > result) ?> >
Re: [fw-general] why Zend_Json::encode? (was: Ajax way)
What do you mean? It was the same way to call in 5.1.x, wasn't it? On Mon, 2007-11-26 at 09:21 +1100, Simon Mundy wrote: > Well, really only for PHP 5.1.x compatibility
Re: [fw-general] why Zend_Json::encode? (was: Ajax way)
Well, really only for PHP 5.1.x compatibility - primarily for lazy sods like me who rely on OS RPMs to update to PHP 5.2.x :) Ok, cool... But why is there a wrapper for a simple function call for the json, wouldn't json_encode($this->result) be simpler? Or is there something I don't get? :) On Mon, 2007-11-26 at 09:10 +1100, Simon Mundy wrote: result) ?> -- Simon Mundy | Director | PEPTOLAB """ " "" "" "" "" """ " "" " " " " "" "" " Please support Movember today! Visit http://www.movember.com/au/donate Registration number for Simon 160725 202/258 Flinders Lane | Melbourne | Victoria | Australia | 3000 Voice +61 (0) 3 9654 4324 | Mobile 0438 046 061 | Fax +61 (0) 3 9654 4124 http://www.peptolab.com
Re: [fw-general] why Zend_Json::encode? (was: Ajax way)
Ok, cool... But why is there a wrapper for a simple function call for the json, wouldn't json_encode($this->result) be simpler? Or is there something I don't get? :) On Mon, 2007-11-26 at 09:10 +1100, Simon Mundy wrote: > result) ?>
Re: [fw-general] Ajax way
Why don't you instead have the json encoding happen from a view action? e.g. Assuming your controller is AjaxController.php:- foreach ($this->getRequest()->getPost('divisioncontainer') AS $i_divisionid) { $o_division = $o_divisiontable->fetchRow("division_id = $i_divisionid"); $o_division->priority = $i; $o_division->save(); $i++; } $this->view->result = array("result", 1); } } ...and then your corresponding view action would be in your view folders ajax/updateorder.phtml result) ?> (Note, I also added the 'getRequest()->getPost()' accessor to be more MVC-friendly :) Cheers But the problem is I am getting "edit.phtml" not found if I don't "die" the action. Or will this change if I do the setHeader content-type? /Peter On Mon, 2007-11-26 at 07:45 +1000, Steven Brown wrote: Peter, This may not be the most correct way, but this is the solution I use: Zend_Loader::loadClass('Zend_Json'); $this->_response->setHeader('content-type', 'application/json', true); $this->_response->setBody("/*-secure-\n" . Zend_Json::encode($response) . "\n*/"); $response really can be anything, a string, an array, an object. Cheers, Steven -Original Message- From: Peter Lauri [mailto:[EMAIL PROTECTED] Sent: Monday, 26 November 2007 7:17 AM To: Zend Framework General Subject: [fw-general] Ajax way Hi, I want to return json from an action, but I have hard times finding out how to do it the best way with ZF. For the moment I do: function updateorderAction() { $i = 1; $o_divisiontable = new Division(); foreach($_POST['divisioncontainer'] AS $i_divisionid) { $o_division = $o_divisiontable->fetchRow("division_id = $i_divisionid"); $o_division->priority = $i; $o_division->save(); $i++; } $a_return = array("result", 1); echo json_encode($a_return); die; } But that isn't the way, is it? /Peter -- Simon Mundy | Director | PEPTOLAB """ " "" "" "" "" """ " "" " " " " "" "" " Please support Movember today! Visit http://www.movember.com/au/donate Registration number for Simon 160725 202/258 Flinders Lane | Melbourne | Victoria | Australia | 3000 Voice +61 (0) 3 9654 4324 | Mobile 0438 046 061 | Fax +61 (0) 3 9654 4124 http://www.peptolab.com
RE: [fw-general] Ajax way
But the problem is I am getting "edit.phtml" not found if I don't "die" the action. Or will this change if I do the setHeader content-type? /Peter On Mon, 2007-11-26 at 07:45 +1000, Steven Brown wrote: > Peter, > > This may not be the most correct way, but this is the solution I use: > > Zend_Loader::loadClass('Zend_Json'); > $this->_response->setHeader('content-type', 'application/json', true); > $this->_response->setBody("/*-secure-\n" . Zend_Json::encode($response) . > "\n*/"); > > $response really can be anything, a string, an array, an object. > > Cheers, > Steven > > -Original Message- > From: Peter Lauri [mailto:[EMAIL PROTECTED] > Sent: Monday, 26 November 2007 7:17 AM > To: Zend Framework General > Subject: [fw-general] Ajax way > > Hi, > > I want to return json from an action, but I have hard times finding out > how to do it the best way with ZF. For the moment I do: > > function updateorderAction() { > $i = 1; > $o_divisiontable = new Division(); > foreach($_POST['divisioncontainer'] AS $i_divisionid) { > $o_division = > $o_divisiontable->fetchRow("division_id = > $i_divisionid"); > $o_division->priority = $i; > $o_division->save(); > $i++; > } > $a_return = array("result", 1); > echo json_encode($a_return); > die; > } > > But that isn't the way, is it? > > /Peter > > >
RE: [fw-general] Ajax way
Peter, This may not be the most correct way, but this is the solution I use: Zend_Loader::loadClass('Zend_Json'); $this->_response->setHeader('content-type', 'application/json', true); $this->_response->setBody("/*-secure-\n" . Zend_Json::encode($response) . "\n*/"); $response really can be anything, a string, an array, an object. Cheers, Steven -Original Message- From: Peter Lauri [mailto:[EMAIL PROTECTED] Sent: Monday, 26 November 2007 7:17 AM To: Zend Framework General Subject: [fw-general] Ajax way Hi, I want to return json from an action, but I have hard times finding out how to do it the best way with ZF. For the moment I do: function updateorderAction() { $i = 1; $o_divisiontable = new Division(); foreach($_POST['divisioncontainer'] AS $i_divisionid) { $o_division = $o_divisiontable->fetchRow("division_id = $i_divisionid"); $o_division->priority = $i; $o_division->save(); $i++; } $a_return = array("result", 1); echo json_encode($a_return); die; } But that isn't the way, is it? /Peter
[fw-general] Ajax way
Hi, I want to return json from an action, but I have hard times finding out how to do it the best way with ZF. For the moment I do: function updateorderAction() { $i = 1; $o_divisiontable = new Division(); foreach($_POST['divisioncontainer'] AS $i_divisionid) { $o_division = $o_divisiontable->fetchRow("division_id = $i_divisionid"); $o_division->priority = $i; $o_division->save(); $i++; } $a_return = array("result", 1); echo json_encode($a_return); die; } But that isn't the way, is it? /Peter
[fw-general] Logging exceptions: set_exception_handler doesn't seem to work with Zend_Controller_Response
Hi everyone, I'm trying to output any exceptions thrown by the zend framework to a log in a custom application built on top of the Zend_Framework_Controller. Actually I have a log system based on Zend_Log and Zend_Debug perfectly working, and what I would like to achieve is having the stacktrace to be logged (and eventually rendered to screen if Zend_Controller_Response->renderExceptions is set to true) everytime my app or a zend framework component throws an exception. I've considered a pair of ways to do that, but without succes: 1) with a logging callback in Zend_Exception - but it figured to be the wrong way, since Zend_Exception doesn't call parent::_construct() and I don't want to modify the zend's source... 2) using a custom handler defined with set_exception_handler(). This looked better, since it won'only capture my applicaiton and zend framework's exceptions, but any exception thrown by any external library... I managed to setup it with ease, but it looks like Zend_Controller_Response brokes the default behaviur: if I throw an exception before Zend_Controller_Response->sendResponse() my handler work and the exception get logged, if instead i generate an internal MVC exception (like a 404 not found for a bad controller/action combination) I only get the in page exception and nothing is logged. I cant'f find a way to let a custom exception handler and Zend_Controller_Response live together. Any suggestion (maybe there's a callback I don't know of?) I've also checked out the sources of the Zend_Controller but I haven't found any presence of set_exception_handler, so this isn't just overwritten. Jules