Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VictorSouzas/767f80f419d99d92efe2b9ad0ea39133 to your computer and use it in GitHub Desktop.
Save VictorSouzas/767f80f419d99d92efe2b9ad0ea39133 to your computer and use it in GitHub Desktop.
<?php
/**
* @var \App\View\AppView $this
*/
$this->start('script');
echo '$().ready(function() {
$( "#cadForm" ).submit(function( event ) {
var request = $.ajax({
url: "",
method: "POST",
data: { name: $("#name").val(),
email: $("#email").val(),
password: $("#password").val() },
dataType: "json"
});
request.done(function( msg ) {
$alert( msg );
});
request.fail(function( jqXHR, textStatus ) {
alert( "Request failed: " + textStatus );
});
});
});';
$this->end();
?>
<nav class="large-3 medium-4 columns" id="actions-sidebar">
<ul class="side-nav">
<li class="heading"><?= __('Actions') ?></li>
<li><?= $this->Form->postLink(
__('Delete'),
['action' => 'delete', $user->id],
['confirm' => __('Are you sure you want to delete # {0}?', $user->id)]
)
?></li>
<li><?= $this->Html->link(__('List Users'), ['action' => 'index']) ?></li>
</ul>
</nav>
<div class="users form large-9 medium-8 columns content">
<?= $this->Flash->render() ?>
<?= $this->Form->create($user, ['id'=> 'editUser']) ?>
<fieldset>
<legend><?= __('Edit User') ?></legend>
<?php
echo $this->Form->control('name');
echo $this->Form->control('email');
echo $this->Form->control('password');
echo $this->Form->control('admin');
echo $this->Form->control('picture');
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>
public function edit($id = null)
{
if($id === null)
$id = $this->Auth->user('id');
$user = $this->Users->get($id, [
'contain' => []
]);
if ($this->request->is(['patch', 'post', 'put', 'ajax'])) {
$this->render(false);
$user = $this->Users->patchEntity($user, $this->request->getData());
if ($this->Users->save($user)) {
$response = $this->response;
$response = $response->withStringBody('error');
return $response;
//$this->Flash->success(__("Usuario salvo com sucesso."));
//return $this->redirect(['action' => 'view']);
}
if($user->errors()){
$response = $this->response;
$response = $response->withType('application/json');
$response = $response->withStringBody('error');
return $response;
//$this->Flash->error(__($user->errors()));
}
exit();
}
$this->set(compact('user'));
$this->set('_serialize', ['user']);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment