Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat parameters to create REST API using CakePHP
    primarykey
    data
    text
    <p>I was creating a REST API for logging in using CakePHP. My question is:</p> <ol> <li>In <code>routes.php</code>, what do I fill in <code>mapresources("xxx")</code>? </li> <li>POST <code>/XXX.format XXXController::add() &lt;=</code> this is given in documentation. If my app folders are like this: <code>/localhost/FC/app/webroot/</code> etc. What would the URL be for the post request through which I would send JSON format username and password? Currently I access <code>index.php</code> in webroot by typing <code>localhost/FC</code>.</li> <li><p>If i name my controller Apis instead of recipes below, like <code>ApisController.php</code>, where do I do changes in the code below? And how do I use add? it's not given in the documentation:</p> <pre><code>class RecipesController extends AppController { public $components = array('RequestHandler'); public function index() { $recipes = $this-&gt;Recipe-&gt;find('all'); $this-&gt;set(array( 'recipes' =&gt; $recipes, '_serialize' =&gt; array('recipes') )); } public function view($id) { $recipe = $this-&gt;Recipe-&gt;findById($id); $this-&gt;set(array( 'recipe' =&gt; $recipe, '_serialize' =&gt; array('recipe') )); } public function edit($id) { $this-&gt;Recipe-&gt;id = $id; if ($this-&gt;Recipe-&gt;save($this-&gt;request-&gt;data)) { $message = 'Saved'; } else { $message = 'Error'; } $this-&gt;set(array( 'message' =&gt; $message, '_serialize' =&gt; array('message') )); } public function delete($id) { if ($this-&gt;Recipe-&gt;delete($id)) { $message = 'Deleted'; } else { $message = 'Error'; } $this-&gt;set(array( 'message' =&gt; $message, '_serialize' =&gt; array('message') )); } } </code></pre></li> <li><p>Lastly, if I send a user-id password in json to this url, what command do I do to return a 200 ok response?</p></li> </ol> <p>I know its a bit much, but I'm really a novice and I'm not able to grasp this concept even though I've been at it for 3 days and am about to faint of exhaustion. Please help!</p> <p>Right now, the controller is customer:</p> <pre><code>public function login() { if ($this-&gt;Session-&gt;check('Customer')) { //to check if already logged in $this-&gt;Session-&gt;setFlash('You are already logged in as ' . $this-&gt;Session-&gt;read('Customer.Customer.fname') . ' ' . $this-&gt;Session-&gt;read('Customer.Customer.sname')); $this-&gt;redirect($this-&gt;Session-&gt;read('ref')); } else { if ($this-&gt;request-&gt;is('post')||$this-&gt;request-&gt;is('ajax')) { //receives data by ajax from popup of login $name = $this-&gt;request-&gt;data('name'); $pwd = $this-&gt;request-&gt;data('pwd'); $pwd = md5($pwd); //hashing of password $customer = $this-&gt;Customer-&gt;findByEmail($name); if (!$customer) { $msg = 'Wrong Username or password/false'; } if ($customer['Customer']['active'] == 1) { $customer = $this-&gt;Customer-&gt;findByEmailAndPassword($name, $pwd); if (@$customer) { $this-&gt;Session-&gt;write('Customer', $customer); $msg = $customer['Customer']['fname'].'/true'; if ($this-&gt;Session-&gt;check('order')) { $msg = $this-&gt;Session-&gt;read('loc_id').'/set'; } } else { $msg = 'Wrong Username or password/false'; } } else { $msg = 'Your account in not active. Please check your mails to get the activation link/false'; } } } echo $msg; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload