Re: How to return json message inside controller?

2014-03-13 Thread Wladimir Chopite
You have an error in your array. The key 0 not exists. check the array

Consider also use what euromark says:

So please see http://book.cakephp.org/2.0/en/views/json-and-xml-views.html on
how to leverage JsonView instead
Also see http://www.dereuromark.de/2014/01/09/ajax-and-cakephp/ for
additional information.


2014-03-13 7:14 GMT-04:30 Sam :

>
>
> On Thursday, March 13, 2014 7:29:42 PM UTC+8, wchopite wrote:
>>
>> Use at the beginning of your controller function:
>>
>> $this->autoRender=false;
>>
>
> Thanks. This worked. I still get some error message like this;
> Notice (8): Undefined offset: 0 [APP\\Model\\Model1.php, line 23]
> Are those cakephp debug messages? Can I remove them by setting the debug
> level down?
>
>
>> Wladimir Chópite
>> +584249700264
>> ve.linkedin.com/in/wchopite
>> "Mejor pirata de la armada". Hack the planet!
>> El 13/03/2014 06:57, "Sam"  escribió:
>>
>>
>>>
>>> On Thursday, March 13, 2014 7:21:26 PM UTC+8, wchopite wrote:

 Use the php function json_encode( ).

 http://php.net/manual/en/function.json-encode.php

 You can generate an associative array with the message you want, and
 use:

 return json_encode($your_array);

>>> Thanks. This worked. I can see the json message in the HTTP response. But
>>> I still have a problem. When I look at the HTTP response, it is full of
>>> other HTML code besides the json message. How can I remove the other HTML
>>> code and leave behind only a clean json message?
>>>
>>> Thank you.
>>>
>>>
 Wladimir Chópite
 +584249700264
 ve.linkedin.com/in/wchopite
 "Mejor pirata de la armada". Hack the planet!
 El 13/03/2014 06:45, "Sam"  escribió:

> I have a controller which takes in an id and checks whether this id
> exists inside the Model. If it does not exist, I would like the controller
> to return a validation error message "id not found" in json when it 
> returns
> the HTTP response. This controller takes in a normal HTTP POST which is 
> not
> in json.
>
> How can this be done in Cakephp 2.4.5?
>
> My controller code looks something like this;
>
> public function controller_function($id=null){
> if ($this->request->is('post'))
> {
>$field=$this->request->data['Model']['field'];
>$Model_id = $this->Model->findFieldID($field);
>if (empty($Model_id) ) //record not found. Return validation error
>{
>//Send validation error back in JSON. How??
>}
> }}
>
>  --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google
> Groups "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to cake-php+u...@googlegroups.com.
> To post to this group, send email to cake...@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/d/optout.
>
  --
>>> Like Us on FaceBook https://www.facebook.com/CakePHP
>>> Find us on Twitter http://twitter.com/CakePHP
>>>
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "CakePHP" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to cake-php+u...@googlegroups.com.
>>> To post to this group, send email to cake...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/cake-php.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>  --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cake-php+unsubscr...@googlegroups.com.
> To post to this group, send email to cake-php@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/d/optout.
>



-- 

*Atentamente: *Wladimir J. Chopite G. +58 424-9700264
Maturin, Venezuela

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: How to return json message inside controller?

2014-03-13 Thread Sam


On Thursday, March 13, 2014 7:29:42 PM UTC+8, wchopite wrote:
>
> Use at the beginning of your controller function:
>
> $this->autoRender=false;
>

Thanks. This worked. I still get some error message like this; 
Notice (8): Undefined offset: 0 [APP\\Model\\Model1.php, line 23] 
Are those cakephp debug messages? Can I remove them by setting the debug 
level down? 
 

> Wladimir Chópite
> +584249700264
> ve.linkedin.com/in/wchopite
> "Mejor pirata de la armada". Hack the planet! 
> El 13/03/2014 06:57, "Sam" > escribió:
>
>>
>>
>> On Thursday, March 13, 2014 7:21:26 PM UTC+8, wchopite wrote:
>>>
>>> Use the php function json_encode( ). 
>>>
>>> http://php.net/manual/en/function.json-encode.php
>>>
>>> You can generate an associative array with the message you want, and use:
>>>
>>> return json_encode($your_array);
>>>
>> Thanks. This worked. I can see the json message in the HTTP response. But 
>> I still have a problem. When I look at the HTTP response, it is full of 
>> other HTML code besides the json message. How can I remove the other HTML 
>> code and leave behind only a clean json message? 
>>
>> Thank you.
>>  
>>
>>> Wladimir Chópite
>>> +584249700264
>>> ve.linkedin.com/in/wchopite
>>> "Mejor pirata de la armada". Hack the planet! 
>>> El 13/03/2014 06:45, "Sam"  escribió:
>>>
 I have a controller which takes in an id and checks whether this id 
 exists inside the Model. If it does not exist, I would like the controller 
 to return a validation error message "id not found" in json when it 
 returns 
 the HTTP response. This controller takes in a normal HTTP POST which is 
 not 
 in json.

 How can this be done in Cakephp 2.4.5?

 My controller code looks something like this;

 public function controller_function($id=null){
 if ($this->request->is('post')) 
 {
$field=$this->request->data['Model']['field'];
$Model_id = $this->Model->findFieldID($field);
if (empty($Model_id) ) //record not found. Return validation error
{
//Send validation error back in JSON. How??
}
 }}

  -- 
 Like Us on FaceBook https://www.facebook.com/CakePHP
 Find us on Twitter http://twitter.com/CakePHP

 --- 
 You received this message because you are subscribed to the Google 
 Groups "CakePHP" group.
 To unsubscribe from this group and stop receiving emails from it, send 
 an email to cake-php+u...@googlegroups.com.
 To post to this group, send email to cake...@googlegroups.com.
 Visit this group at http://groups.google.com/group/cake-php.
 For more options, visit https://groups.google.com/d/optout.

>>>  -- 
>> Like Us on FaceBook https://www.facebook.com/CakePHP
>> Find us on Twitter http://twitter.com/CakePHP
>>
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "CakePHP" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to cake-php+u...@googlegroups.com .
>> To post to this group, send email to cake...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/cake-php.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: How to return json message inside controller?

2014-03-13 Thread Wladimir Chopite
Thanks for this information

Wladimir Chópite
+584249700264
ve.linkedin.com/in/wchopite
"Mejor pirata de la armada". Hack the planet!
El 13/03/2014 07:08, "euromark"  escribió:

> Not using json_encode() manually in the controller is the cleanest way.
> So please see http://book.cakephp.org/2.0/en/views/json-and-xml-views.htmlon 
> how to leverage JsonView instead
> Also see http://www.dereuromark.de/2014/01/09/ajax-and-cakephp/ for
> additional information.
>
>
> Am Donnerstag, 13. März 2014 12:29:42 UTC+1 schrieb wchopite:
>>
>> Use at the beginning of your controller function:
>>
>> $this->autoRender=false;
>>
>> Wladimir Chópite
>> +584249700264
>> ve.linkedin.com/in/wchopite
>> "Mejor pirata de la armada". Hack the planet!
>> El 13/03/2014 06:57, "Sam"  escribió:
>>
>>>
>>>
>>> On Thursday, March 13, 2014 7:21:26 PM UTC+8, wchopite wrote:

 Use the php function json_encode( ).

 http://php.net/manual/en/function.json-encode.php

 You can generate an associative array with the message you want, and
 use:

 return json_encode($your_array);

>>> Thanks. This worked. I can see the json message in the HTTP response. But
>>> I still have a problem. When I look at the HTTP response, it is full of
>>> other HTML code besides the json message. How can I remove the other HTML
>>> code and leave behind only a clean json message?
>>>
>>> Thank you.
>>>
>>>
 Wladimir Chópite
 +584249700264
 ve.linkedin.com/in/wchopite
 "Mejor pirata de la armada". Hack the planet!
 El 13/03/2014 06:45, "Sam"  escribió:

> I have a controller which takes in an id and checks whether this id
> exists inside the Model. If it does not exist, I would like the controller
> to return a validation error message "id not found" in json when it 
> returns
> the HTTP response. This controller takes in a normal HTTP POST which is 
> not
> in json.
>
> How can this be done in Cakephp 2.4.5?
>
> My controller code looks something like this;
>
> public function controller_function($id=null){
> if ($this->request->is('post'))
> {
>$field=$this->request->data['Model']['field'];
>$Model_id = $this->Model->findFieldID($field);
>if (empty($Model_id) ) //record not found. Return validation error
>{
>//Send validation error back in JSON. How??
>}
> }}
>
>  --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google
> Groups "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to cake-php+u...@googlegroups.com.
> To post to this group, send email to cake...@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/d/optout.
>
  --
>>> Like Us on FaceBook https://www.facebook.com/CakePHP
>>> Find us on Twitter http://twitter.com/CakePHP
>>>
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "CakePHP" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to cake-php+u...@googlegroups.com.
>>> To post to this group, send email to cake...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/cake-php.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>  --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cake-php+unsubscr...@googlegroups.com.
> To post to this group, send email to cake-php@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: How to return json message inside controller?

2014-03-13 Thread Jeremy Burns | Class Outfit
I put this in AppController beforeFilter:

if ($this->request->is('ajax')) {
Configure::write('debug', 0);
$this->autoRender = false;
$this->layout = 'ajax';
$this->disableCache();
}

On 13 Mar 2014, at 11:29, Wladimir Chopite  wrote:

> Use at the beginning of your controller function:
> 
> $this->autoRender=false;
> 
> 
> Wladimir Chópite
> +584249700264
> ve.linkedin.com/in/wchopite
> "Mejor pirata de la armada". Hack the planet!
> 
> El 13/03/2014 06:57, "Sam"  escribió:
> 
> 
> On Thursday, March 13, 2014 7:21:26 PM UTC+8, wchopite wrote:
> Use the php function json_encode( ).
> 
> http://php.net/manual/en/function.json-encode.php
> 
> You can generate an associative array with the message you want, and use:
> 
> return json_encode($your_array);
> 
> Thanks. This worked. I can see the json message in the HTTP response. But I 
> still have a problem. When I look at the HTTP response, it is full of other 
> HTML code besides the json message. How can I remove the other HTML code and 
> leave behind only a clean json message? 
> 
> Thank you.
>  
> Wladimir Chópite
> +584249700264
> ve.linkedin.com/in/wchopite
> "Mejor pirata de la armada". Hack the planet!
> 
> El 13/03/2014 06:45, "Sam"  escribió:
> I have a controller which takes in an id and checks whether this id exists 
> inside the Model. If it does not exist, I would like the controller to return 
> a validation error message "id not found" in json when it returns the HTTP 
> response. This controller takes in a normal HTTP POST which is not in json.
> 
> How can this be done in Cakephp 2.4.5?
> 
> My controller code looks something like this;
> 
> public function controller_function($id=null)
> {
> if ($this->request->is('post')) 
> {
>$field=$this->request->data['Model']['field'];
>$Model_id = $this->Model->findFieldID($field);
>if (empty($Model_id) ) //record not found. Return validation error
>{
>//Send validation error back in JSON. How??
>}
> }
> }
> 
> -- 
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
> 
> --- 
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to cake-php+u...@googlegroups.com.
> To post to this group, send email to cake...@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/d/optout.
> 
> -- 
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
> 
> --- 
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to cake-php+unsubscr...@googlegroups.com.
> To post to this group, send email to cake-php@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/d/optout.
> 
> -- 
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
> 
> --- 
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to cake-php+unsubscr...@googlegroups.com.
> To post to this group, send email to cake-php@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/d/optout.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: How to return json message inside controller?

2014-03-13 Thread euromark
Not using json_encode() manually in the controller is the cleanest way.
So please see http://book.cakephp.org/2.0/en/views/json-and-xml-views.html 
on how to leverage JsonView instead
Also see http://www.dereuromark.de/2014/01/09/ajax-and-cakephp/ for 
additional information.


Am Donnerstag, 13. März 2014 12:29:42 UTC+1 schrieb wchopite:
>
> Use at the beginning of your controller function:
>
> $this->autoRender=false;
>
> Wladimir Chópite
> +584249700264
> ve.linkedin.com/in/wchopite
> "Mejor pirata de la armada". Hack the planet! 
> El 13/03/2014 06:57, "Sam" > escribió:
>
>>
>>
>> On Thursday, March 13, 2014 7:21:26 PM UTC+8, wchopite wrote:
>>>
>>> Use the php function json_encode( ). 
>>>
>>> http://php.net/manual/en/function.json-encode.php
>>>
>>> You can generate an associative array with the message you want, and use:
>>>
>>> return json_encode($your_array);
>>>
>> Thanks. This worked. I can see the json message in the HTTP response. But 
>> I still have a problem. When I look at the HTTP response, it is full of 
>> other HTML code besides the json message. How can I remove the other HTML 
>> code and leave behind only a clean json message? 
>>
>> Thank you.
>>  
>>
>>> Wladimir Chópite
>>> +584249700264
>>> ve.linkedin.com/in/wchopite
>>> "Mejor pirata de la armada". Hack the planet! 
>>> El 13/03/2014 06:45, "Sam"  escribió:
>>>
 I have a controller which takes in an id and checks whether this id 
 exists inside the Model. If it does not exist, I would like the controller 
 to return a validation error message "id not found" in json when it 
 returns 
 the HTTP response. This controller takes in a normal HTTP POST which is 
 not 
 in json.

 How can this be done in Cakephp 2.4.5?

 My controller code looks something like this;

 public function controller_function($id=null){
 if ($this->request->is('post')) 
 {
$field=$this->request->data['Model']['field'];
$Model_id = $this->Model->findFieldID($field);
if (empty($Model_id) ) //record not found. Return validation error
{
//Send validation error back in JSON. How??
}
 }}

  -- 
 Like Us on FaceBook https://www.facebook.com/CakePHP
 Find us on Twitter http://twitter.com/CakePHP

 --- 
 You received this message because you are subscribed to the Google 
 Groups "CakePHP" group.
 To unsubscribe from this group and stop receiving emails from it, send 
 an email to cake-php+u...@googlegroups.com.
 To post to this group, send email to cake...@googlegroups.com.
 Visit this group at http://groups.google.com/group/cake-php.
 For more options, visit https://groups.google.com/d/optout.

>>>  -- 
>> Like Us on FaceBook https://www.facebook.com/CakePHP
>> Find us on Twitter http://twitter.com/CakePHP
>>
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "CakePHP" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to cake-php+u...@googlegroups.com .
>> To post to this group, send email to cake...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/cake-php.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: How to return json message inside controller?

2014-03-13 Thread Wladimir Chopite
Use at the beginning of your controller function:

$this->autoRender=false;

Wladimir Chópite
+584249700264
ve.linkedin.com/in/wchopite
"Mejor pirata de la armada". Hack the planet!
El 13/03/2014 06:57, "Sam"  escribió:

>
>
> On Thursday, March 13, 2014 7:21:26 PM UTC+8, wchopite wrote:
>>
>> Use the php function json_encode( ).
>>
>> http://php.net/manual/en/function.json-encode.php
>>
>> You can generate an associative array with the message you want, and use:
>>
>> return json_encode($your_array);
>>
> Thanks. This worked. I can see the json message in the HTTP response. But
> I still have a problem. When I look at the HTTP response, it is full of
> other HTML code besides the json message. How can I remove the other HTML
> code and leave behind only a clean json message?
>
> Thank you.
>
>
>> Wladimir Chópite
>> +584249700264
>> ve.linkedin.com/in/wchopite
>> "Mejor pirata de la armada". Hack the planet!
>> El 13/03/2014 06:45, "Sam"  escribió:
>>
>>> I have a controller which takes in an id and checks whether this id
>>> exists inside the Model. If it does not exist, I would like the controller
>>> to return a validation error message "id not found" in json when it returns
>>> the HTTP response. This controller takes in a normal HTTP POST which is not
>>> in json.
>>>
>>> How can this be done in Cakephp 2.4.5?
>>>
>>> My controller code looks something like this;
>>>
>>> public function controller_function($id=null){
>>> if ($this->request->is('post'))
>>> {
>>>$field=$this->request->data['Model']['field'];
>>>$Model_id = $this->Model->findFieldID($field);
>>>if (empty($Model_id) ) //record not found. Return validation error
>>>{
>>>//Send validation error back in JSON. How??
>>>}
>>> }}
>>>
>>>  --
>>> Like Us on FaceBook https://www.facebook.com/CakePHP
>>> Find us on Twitter http://twitter.com/CakePHP
>>>
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "CakePHP" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to cake-php+u...@googlegroups.com.
>>> To post to this group, send email to cake...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/cake-php.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>  --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cake-php+unsubscr...@googlegroups.com.
> To post to this group, send email to cake-php@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: How to return json message inside controller?

2014-03-13 Thread Sam


On Thursday, March 13, 2014 7:21:26 PM UTC+8, wchopite wrote:
>
> Use the php function json_encode( ). 
>
> http://php.net/manual/en/function.json-encode.php
>
> You can generate an associative array with the message you want, and use:
>
> return json_encode($your_array);
>
Thanks. This worked. I can see the json message in the HTTP response. But I 
still have a problem. When I look at the HTTP response, it is full of other 
HTML code besides the json message. How can I remove the other HTML code 
and leave behind only a clean json message? 

Thank you.
 

> Wladimir Chópite
> +584249700264
> ve.linkedin.com/in/wchopite
> "Mejor pirata de la armada". Hack the planet! 
> El 13/03/2014 06:45, "Sam" > escribió:
>
>> I have a controller which takes in an id and checks whether this id 
>> exists inside the Model. If it does not exist, I would like the controller 
>> to return a validation error message "id not found" in json when it returns 
>> the HTTP response. This controller takes in a normal HTTP POST which is not 
>> in json.
>>
>> How can this be done in Cakephp 2.4.5?
>>
>> My controller code looks something like this;
>>
>> public function controller_function($id=null){
>> if ($this->request->is('post')) 
>> {
>>$field=$this->request->data['Model']['field'];
>>$Model_id = $this->Model->findFieldID($field);
>>if (empty($Model_id) ) //record not found. Return validation error
>>{
>>//Send validation error back in JSON. How??
>>}
>> }}
>>
>>  -- 
>> Like Us on FaceBook https://www.facebook.com/CakePHP
>> Find us on Twitter http://twitter.com/CakePHP
>>
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "CakePHP" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to cake-php+u...@googlegroups.com .
>> To post to this group, send email to cake...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/cake-php.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: How to return json message inside controller?

2014-03-13 Thread Wladimir Chopite
Use the php function json_encode( ).

http://php.net/manual/en/function.json-encode.php

You can generate an associative array with the message you want, and use:

return json_encode($your_array);

Wladimir Chópite
+584249700264
ve.linkedin.com/in/wchopite
"Mejor pirata de la armada". Hack the planet!
El 13/03/2014 06:45, "Sam"  escribió:

> I have a controller which takes in an id and checks whether this id exists
> inside the Model. If it does not exist, I would like the controller to
> return a validation error message "id not found" in json when it returns
> the HTTP response. This controller takes in a normal HTTP POST which is not
> in json.
>
> How can this be done in Cakephp 2.4.5?
>
> My controller code looks something like this;
>
> public function controller_function($id=null){
> if ($this->request->is('post'))
> {
>$field=$this->request->data['Model']['field'];
>$Model_id = $this->Model->findFieldID($field);
>if (empty($Model_id) ) //record not found. Return validation error
>{
>//Send validation error back in JSON. How??
>}
> }}
>
>  --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cake-php+unsubscr...@googlegroups.com.
> To post to this group, send email to cake-php@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


How to return json message inside controller?

2014-03-13 Thread Sam


I have a controller which takes in an id and checks whether this id exists 
inside the Model. If it does not exist, I would like the controller to 
return a validation error message "id not found" in json when it returns 
the HTTP response. This controller takes in a normal HTTP POST which is not 
in json.

How can this be done in Cakephp 2.4.5?

My controller code looks something like this;

public function controller_function($id=null){
if ($this->request->is('post')) 
{
   $field=$this->request->data['Model']['field'];
   $Model_id = $this->Model->findFieldID($field);
   if (empty($Model_id) ) //record not found. Return validation error
   {
   //Send validation error back in JSON. How??
   }
}}

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.