-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Training mahdy #3
base: master
Are you sure you want to change the base?
Changes from 1 commit
20bc31a
2c75246
c8e888b
29afbbe
f947f67
2430684
c358146
2f00c44
8f9e1bf
71ed690
72c737b
e4d3e86
fd4fc4a
ab3f10c
4480efa
c9180e7
da287ff
8f9b3c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,13 +35,29 @@ public function addAjaxAction() | |
// Fill in the form with POST data | ||
$data = $this->params()->fromPost(); | ||
// var_dump($data); | ||
$category->save($data); | ||
$category->create($data); | ||
} | ||
die; | ||
} | ||
|
||
public function editAction() | ||
{ | ||
return new ViewModel(); | ||
// Get post ID. | ||
$id = (int)$this->params()->fromRoute('id', -1); | ||
$category = new CategoryRepository($this->entityManager); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above re: using service instead of business logic directly inside controller. |
||
$data = $category->find($id); | ||
|
||
return new ViewModel(['category' => $data]); | ||
} | ||
|
||
public function updateAjaxAction() | ||
{ | ||
if($this->getRequest()->isPost()) { | ||
$category = new CategoryRepository($this->entityManager); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above re: using service instead of business logic directly inside controller. |
||
// Fill in the form with POST data | ||
$data = $this->params()->fromPost(); | ||
$category->update($data); | ||
} | ||
die; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above re: |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<div class="jumbotron"> | ||
<h2>Edit Category Information</h2> | ||
</div> | ||
<div class="row col-md-6 col-md-offset-2 custyle"> | ||
<a href="<?php echo $this->url('category-list') ?>" class="btn btn-primary"><b>+</b> All Categories</a> | ||
<br><br> | ||
<form role="form"> | ||
<div class="alert hidden"></div> | ||
<div class="form-group"> | ||
<input type="text" class="form-control" id='name' name="name" value='<?php echo $category->name ?>' placeholder="Name" required> | ||
</div> | ||
<button type="button" id="submit" name="submit" class="btn btn-primary pull-right">Update</button> | ||
</form> | ||
</div> | ||
<script type="text/javascript"> | ||
$(document).ready(function(){ | ||
$('#submit').click(submit); | ||
|
||
function submit(){ | ||
$.post( "<?php echo $this->url('category-edit-ajax') ?>",{name:$('#name').val(),id:'<?php echo $category->id ?>'} ,function( data ) { | ||
var response = '<i class="glyphicon glyphicon-check"></i> Data Saved, Thanks! '; | ||
$('.alert').html(response).removeClass('hidden').addClass('alert-success'); | ||
}); | ||
} | ||
}); | ||
</script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should not
die
inside a controller. Please see this URL about ways of returning different output (i.e. not HTML):https://olegkrivtsov.github.io/using-zend-framework-3-book/html/en/Model_View_Controller/View_Rendering_Strategies.html