Re: REST, Xml::fromArray() and find('all')

2012-08-31 Thread Alexandre Leprêtre
Thanks for your answer. Yes indeed it doesn't behave the way the manual 
says it should.

For now I will use an alternative ;-)

Le jeudi 23 août 2012 11:47:02 UTC+1, Alexandre Leprêtre a écrit :
>
> Hi everyone,
>
> I am trying to build a nice REST API for my website and I had never tried 
> it through CakePHP. I started to follow the (short) instructions, however, 
> the way it works looks totally different from what I can read in the 
> Cookbook.
>
> I use CakePHP 2.2.1.
>
> Here's what I've done so far:
>
> *app/Controller/OrdersController.php*
>  class OrdersController extends AppController {
> public function fetch($accountId) {
> $this->loadModel('Account'); 
> $this->Account->id = $accountId;
>  $orders = $this->Order->find('all', array(
> 'conditions' => array('Order.account_id' => $accountId)
> ));
>  $response = $orders;
>  $this->set(compact('response'));
> }
> }
>
> *app/View/Orders/xml/fetch.ctp* 
>  $xml = Xml::fromArray(array('orders' => $orders));
> echo $xml->asXML();
>
> I tried this with the first account and everything was fine
>
> *Ouput:*
> 
> 
> 502cc39f-5b74-4a25-9bb2-670458d0d2b2
> 96277
> 502cc39d-8640-465a-b0da-670458d0d2b2
> 2012-08-16 09:55:43
> 2012-08-16 09:55:43
> 
> 
>
> Everything is fine with an account that has one order.
>
> However, with an account that has several orders, this doesn't work 
> anymore.
>
> *Expected output:*
> 
> 
> 502cc39f-66eb-59d2-2337-670458d0d2b2
> 96255
> 502cc39d-6325-ad25-5b64-670458d0d2b2
> 2012-08-16 09:42:33
> 2012-08-16 09:42:33
> 
> 
> 502cc39f-ee21-3c89-8120-670458d0d2b2
> 96231
> 502cc39d-6325-ad25-5b64-670458d0d2b2
> 2012-08-16 09:21:01
> 2012-08-16 09:21:01
> 
> 
> *
> *
> *What I get:*
> This page contains the following errors:
> error on line 1 at column 367: Entity 'nbsp' not defined 
> Below is a rendering of the page up to the first error.*Warning* 
> (2)<http://devapi.ssl247.net/orders/fetch/502cc1be-7e48-4913-89c2-65f058d0d2b2.xml>:
>  
> SimpleXMLElement::__construct() 
> [simplexmlelement.--construct<http://devapi.ssl247.net/orders/fetch/simplexmlelement.--construct>]:
>  
> Entity: line 3: parser error : Extra content at the end of the document [*
> CORE\Cake\Utility\Xml.php*, line 
> *197*]Code<http://devapi.ssl247.net/orders/fetch/502cc1be-7e48-4913-89c2-65f058d0d2b2.xml>
>  
> Context<http://devapi.ssl247.net/orders/fetch/502cc1be-7e48-4913-89c2-65f058d0d2b2.xml>
>
> I assume that Xml::fromArray() doesn't accept multiple numeric keys. Or 
> something like this. I don't mind editing my PHP array to get he XML I 
> expect but I really don't know how I should write my array for this :-(
>
> Any help is welcome.
>
> Thank you!!
>
> Alex
>

-- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




REST, Xml::fromArray() and find('all')

2012-08-23 Thread Alexandre Leprêtre
Hi everyone,

I am trying to build a nice REST API for my website and I had never tried 
it through CakePHP. I started to follow the (short) instructions, however, 
the way it works looks totally different from what I can read in the 
Cookbook.

I use CakePHP 2.2.1.

Here's what I've done so far:

*app/Controller/OrdersController.php*
loadModel('Account'); 
$this->Account->id = $accountId;
 $orders = $this->Order->find('all', array(
'conditions' => array('Order.account_id' => $accountId)
));
 $response = $orders;
 $this->set(compact('response'));
}
}

*app/View/Orders/xml/fetch.ctp* 
 $orders));
echo $xml->asXML();

I tried this with the first account and everything was fine

*Ouput:*


502cc39f-5b74-4a25-9bb2-670458d0d2b2
96277
502cc39d-8640-465a-b0da-670458d0d2b2
2012-08-16 09:55:43
2012-08-16 09:55:43



Everything is fine with an account that has one order.

However, with an account that has several orders, this doesn't work anymore.

*Expected output:*


502cc39f-66eb-59d2-2337-670458d0d2b2
96255
502cc39d-6325-ad25-5b64-670458d0d2b2
2012-08-16 09:42:33
2012-08-16 09:42:33


502cc39f-ee21-3c89-8120-670458d0d2b2
96231
502cc39d-6325-ad25-5b64-670458d0d2b2
2012-08-16 09:21:01
2012-08-16 09:21:01


*
*
*What I get:*
This page contains the following errors:
error on line 1 at column 367: Entity 'nbsp' not defined 
Below is a rendering of the page up to the first error.*Warning* 
(2):
 
SimpleXMLElement::__construct() 
[simplexmlelement.--construct]:
 
Entity: line 3: parser error : Extra content at the end of the document [*
CORE\Cake\Utility\Xml.php*, line 
*197*]Code
 
Context

I assume that Xml::fromArray() doesn't accept multiple numeric keys. Or 
something like this. I don't mind editing my PHP array to get he XML I 
expect but I really don't know how I should write my array for this :-(

Any help is welcome.

Thank you!!

Alex

-- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: Auth Component CakePHP 2.0

2012-02-13 Thread Alexandre Leprêtre
It actually worked with 'fields'. thanks for your help :)

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Auth Component CakePHP 2.0

2012-02-13 Thread Alexandre Leprêtre
Hi Ahmed, thanks a lot for your help.

My array looks like this now, but it doesn't work better.

public $components = array(
'Acl',
'Auth' => array(
'authorize' => array(
'Actions' => array('actionPath' => 
'controllers')
),
'authenticate ' => array(
'Form' => array(
'Fields' => array(
'username' => 'email_address',
'password' => 'password'
)
)
)
),
'Session'
);

I'm still being kicked when I try to log in.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Auth Component CakePHP 2.0

2012-02-10 Thread Alexandre Leprêtre
Hi everyone,

I started to learn CakePHP recently and followed the ACL tutorial step
by step, trying to understand every single piece of it.
Sadly, I couldn't achieve it correctly since my app doesn't work.
Indeed, I can't log in. Every time, it says that my user name or
password is incorrect (while it should be correct).

I don't login with "User.username" and "User.password" but with
"User.email_address" and "User.password". Therefore my AppController:

public $components = array(
'Acl',
'Auth' => array(
'authorize' => array(
'Actions' => array('actionPath' => 
'controllers')
),
'authentificate' => array(
'Form' => array(
'username' => 'email_address',
'password' => 'password'
)
)
),
'Session'
);

And in my UsersController:

public function login() {
if ($this->Session->read('Auth.User')) {
$this->Session->setFlash('You are logged in!');
$this->redirect('/', null, false);
}
if ($this->request->is('post')) {
if ($this->Auth->login()) 
$this->redirect($this->Auth->redirect());
else $this->Session->setFlash('Your email address or 
password was
incorrect.');
}
}

I'm being careful and my password is encrypted in MD5 in my User model

public function beforeSave() {
$this->data['User']['password'] = AuthComponent::password($this-
>data['User']['password']);
return true;
}

If always ends in "Your email address or password was incorrect." and
I can't figure out what I did wrong.
It's frustrating, I find the tutorial very abstruse on some important
points as I'd like to understand how it works.

Thank you in advance for your help.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php