Re: [fw-general] how to use json action context?

2011-03-07 Thread Tim
Well, I wasn't expecting that code response Kizano. It's almost
verbatim to what I did as a quick work around. How dare you peek at my
code :-P

Thanks for both yours and Hector's responses. They were both helpful
and provided enough info that I can work the rest of it out.

Thanks!
-Tim

On Mon, Mar 7, 2011 at 12:25 AM, Markizano Draconus
asthral...@gmail.com wrote:
 Hey Tim,

 You could add something to disable the layout and set the proper headers:
 In the controller, under init() or the action you want to execute:


 $this-_helper-layout-disableLayout();
 $this-_response-setHeader('Content-Type', 'application/json');
 $this-view-json = array(
  'status' = 'ok',
  'message' = 'This is a status message.',
 );


 In application/scripts/view/index/index.phtml (or wherever your view scripts
 are):

 ?php print $this-json; ?

 It's probably looking for error.phtml because it's missing the view scripts
 for the error controller to render the HTML for the error and exceptions.
 Try adding that and your debugging might be  made a bit easier ;)


 Hope this helps,
 -Kizano
 //-
 Information Security
 eMail: asthral...@gmail.com
 http://www.markizano.net/

 On 03/06/2011 10:49 PM, Tim wrote:

 I can't seem to get my controllers to recognize that I only want them
 to display json. Here's my controller

 ?php

 class IndexController extends Zend_Controller_Action {
         public function init() {
                 $this-_helper-contextSwitch()
                         -clearContexts()
                         -clearActionContexts()
                         -setDefaultContext('json')
                         -initContext('json');
         }

         public function indexAction() {
                 $this-view-assign(array(
                         'status' =  'ok',
                         'message' =  'This is the index action'
                 ));
         }
 }

 ?


 All I want to do is, by default, output everything as json. I don't
 want to have to send a format=json parameter in the URL.

 According to
 http://framework.zend.com/manual/en/zend.controller.actionhelpers.html
 I should be able to do this, but the above controller results in the
 error

 Fatal error: Uncaught exception 'Zend_View_Exception' with message
 'script 'error/error.phtml' not found in path

 What am I missing?

 Thanks,
 Tim



RE: [fw-general] how to use json action context?

2011-03-07 Thread Sergio Rinaudo

Hi, 
there is another possible solution, in your controller init() methos

$this-getRequest()-setParam('format','json');

Hope it helps
Cheers

Sergio Rinaudo



 Date: Mon, 7 Mar 2011 08:33:49 -0600
 From: caphrim...@gmail.com
 To: asthral...@gmail.com
 CC: fw-general@lists.zend.com
 Subject: Re: [fw-general] how to use json action context?
 
 Well, I wasn't expecting that code response Kizano. It's almost
 verbatim to what I did as a quick work around. How dare you peek at my
 code :-P
 
 Thanks for both yours and Hector's responses. They were both helpful
 and provided enough info that I can work the rest of it out.
 
 Thanks!
 -Tim
 
 On Mon, Mar 7, 2011 at 12:25 AM, Markizano Draconus
 asthral...@gmail.com wrote:
  Hey Tim,
 
  You could add something to disable the layout and set the proper headers:
  In the controller, under init() or the action you want to execute:
 
 
  $this-_helper-layout-disableLayout();
  $this-_response-setHeader('Content-Type', 'application/json');
  $this-view-json = array(
   'status' = 'ok',
   'message' = 'This is a status message.',
  );
 
 
  In application/scripts/view/index/index.phtml (or wherever your view scripts
  are):
 
  ?php print $this-json; ?
 
  It's probably looking for error.phtml because it's missing the view scripts
  for the error controller to render the HTML for the error and exceptions.
  Try adding that and your debugging might be  made a bit easier ;)
 
 
  Hope this helps,
  -Kizano
  //-
  Information Security
  eMail: asthral...@gmail.com
  http://www.markizano.net/
 
  On 03/06/2011 10:49 PM, Tim wrote:
 
  I can't seem to get my controllers to recognize that I only want them
  to display json. Here's my controller
 
  ?php
 
  class IndexController extends Zend_Controller_Action {
  public function init() {
  $this-_helper-contextSwitch()
  -clearContexts()
  -clearActionContexts()
  -setDefaultContext('json')
  -initContext('json');
  }
 
  public function indexAction() {
  $this-view-assign(array(
  'status' =  'ok',
  'message' =  'This is the index action'
  ));
  }
  }
 
  ?
 
 
  All I want to do is, by default, output everything as json. I don't
  want to have to send a format=json parameter in the URL.
 
  According to
  http://framework.zend.com/manual/en/zend.controller.actionhelpers.html
  I should be able to do this, but the above controller results in the
  error
 
  Fatal error: Uncaught exception 'Zend_View_Exception' with message
  'script 'error/error.phtml' not found in path
 
  What am I missing?
 
  Thanks,
  Tim
 
  

[fw-general] how to use json action context?

2011-03-06 Thread Tim
I can't seem to get my controllers to recognize that I only want them
to display json. Here's my controller

?php

class IndexController extends Zend_Controller_Action {
public function init() {
$this-_helper-contextSwitch()
-clearContexts()
-clearActionContexts()
-setDefaultContext('json')
-initContext('json');
}

public function indexAction() {
$this-view-assign(array(
'status' = 'ok',
'message' = 'This is the index action'
));
}
}

?


All I want to do is, by default, output everything as json. I don't
want to have to send a format=json parameter in the URL.

According to 
http://framework.zend.com/manual/en/zend.controller.actionhelpers.html
I should be able to do this, but the above controller results in the
error

Fatal error: Uncaught exception 'Zend_View_Exception' with message
'script 'error/error.phtml' not found in path

What am I missing?

Thanks,
Tim


Re: [fw-general] how to use json action context?

2011-03-06 Thread Hector Virgen
The ContextSwitch helper requires the format parameter to be set (see
Zend_Controller_Action_Helper_ContextSwitch#initContext()).

However, you could cheat and add the format parameter to the request at the
top of your init() hook:

public function init()
{
$this-getRequest()-setParam('format', 'json');
/* ... the rest of your code ... */
}

--
*Hector Virgen*
Sr. Web Developer
http://www.virgentech.com


Re: [fw-general] how to use json action context?

2011-03-06 Thread Markizano Draconus

Hey Tim,

You could add something to disable the layout and set the proper headers:
In the controller, under init() or the action you want to execute:


$this-_helper-layout-disableLayout();
$this-_response-setHeader('Content-Type', 'application/json');
$this-view-json = array(
  'status' = 'ok',
  'message' = 'This is a status message.',
);


In application/scripts/view/index/index.phtml (or wherever your view scripts 
are):

?php print $this-json; ?

It's probably looking for error.phtml because it's missing the view scripts for 
the error controller to render the HTML for the error and exceptions. Try adding 
that and your debugging might be  made a bit easier ;)



Hope this helps,
-Kizano
//-
Information Security
eMail: asthral...@gmail.com
http://www.markizano.net/

On 03/06/2011 10:49 PM, Tim wrote:

I can't seem to get my controllers to recognize that I only want them
to display json. Here's my controller

?php

class IndexController extends Zend_Controller_Action {
 public function init() {
 $this-_helper-contextSwitch()
 -clearContexts()
 -clearActionContexts()
 -setDefaultContext('json')
 -initContext('json');
 }

 public function indexAction() {
 $this-view-assign(array(
 'status' =  'ok',
 'message' =  'This is the index action'
 ));
 }
}

?


All I want to do is, by default, output everything as json. I don't
want to have to send a format=json parameter in the URL.

According to 
http://framework.zend.com/manual/en/zend.controller.actionhelpers.html
I should be able to do this, but the above controller results in the
error

Fatal error: Uncaught exception 'Zend_View_Exception' with message
'script 'error/error.phtml' not found in path

What am I missing?

Thanks,
Tim