I'm using zend framework 2 and I need to edit the data from the form before validation.
With this function I will take the data from the post method, but do not know how to edit it because the object is a protected type
$request = $this->getRequest();
$data = $request->getPost();
and do what you want with it...
then you can do:
$form->setData($data);
Related
I want to be enable my user to click on an existing entity with, say, Id=123, fetch and copy that object, and then let the user edit it and create a new object using the same view that I'm using to create or edit. I tried the following action method:
' GET: /controller/copy/id
Function Copy(ByVal id As Integer) As ActionResult
Dim obj = db.MyTable.Find(id)
If obj.IsNothing() Then
Return HttpNotFound()
End If
'blank out the id to flag that this is a new entity
obj.Id = 0
'reuse the editing view
Return View("Edit", obj)
End Function
This renders fine, but the form HTML looks like this:
<form action="/Controller/Copy/123" method="post">
And when I post back, the passed model object has Id=123, same as the object being copied. I think this must be because the route /Controller/Copy/123 has the id in the third position, and model binding sees this.
So, how should I implement Copy so that I can copy object 123 but then forget all about that id, to avoid this problem? If there's an entirely different design pattern I should be using, that's fine too.
Override the form action to be "". This means that the current URL will be used.
If i understood you right.... just set id to null or to 0 in form routeValues property
In razor using c#
#using (Html.BeginForm("copy", "controller", FormMethod.Post, new { id = null /* or = 0 */ }))
// form code
In controller:
public ActionResult Copy(int? Id)
// action code
I am new to SAP ui5. I have successfully shown data using ODataModel to a table. Now I want to update the data in the table back into the database.
For this I know that we have something called 'update' function of the model in which we can specify the path and the data. My question here is what if I want to give the data in the form of json? How do I retrieve data in the table in the form of json and have it passed to the 'update' method?
Any help would be appreciated. If possible please share example such.
Thanks
You can use the OData model object to get it. Use the path to retrieve the JSON object, update what you need, and then call the update function. Here's an example:
getDataContext : function(oItem) {
var sPath = oItem.getBindingContextPath();
var oModel = this.getView().getModel();
return {
path : sPath,
data : oModel.getObject(sPath)
};
}
From there you can update the data in mDataContext.data as desired, then call the update:
this.getView().getModel().update(
mDataContext.path,
mDataContext.data,
{ // your context, success, error handlers etc }
)
Here's a fully working example that allows you to look at products in Northwind, select one, and increase or decrease that selected product's rating.
I need to POST a register model from another model without showing the register model to the user in MVC 4. Please suggest.
Move your business logic out of the actions and into methods. Let your actions call those to do their work. Then instead of trying to abuse the framework to post data between actions, just call the method with the parameters you have.
I would store it in temp data and redirect instead of re-POSTing.
Maybe is not the best approach, but you can put the model in hiddenfields
TempData example:
On redirecting Action:
TempData["model"] = model;
return RedirectToAction("DifferentAction");
On different Action
var myModel = (model)TempData["model"]
/* do register stuff */
i am new to the Zend Framework 2.Any body can tell me that where i can initialize the tb table in ZF2 model? For example i want to select all the records form the user table in FZ2 model.
Regards,
Tauqeer
$db = $this->db;
$select = $this->db->select(false)
->from('user');
Try this one
refer this url http://framework.zend.com/manual/1.12/en/zend.db.select.html
I am building a project with Symfony. Its blog-like web site. I need to implement:
Writing comment for every article. Every comment must be moderationed by editors etc.
Everything is ready. I have a backend, use group, perms. so on. Just i need to comment form on article's show page.
My question is can i use my comment module's newSuccess temp. If yes, how? When i copy and paste the content of newSuccess, its not working evenif some conf.
Do you know there is way to use comment module's form at article module? and how can i configure it?
Thanks for spend your time to read -maybe to answer (;-
Just create the form in your controller:
public function executeShowArticle(sfWebRequest $request)
{
// assume weve already retrieved and set $this->article
$comment = new Comment();
$comment->setArticle($this->article);
$this->commentForm = new CommentForm($comment);
}
then you can use echo $commentForm in the template for your article. If you are customizing the layout of the comment form then move that form to a partial and do include_partial('comment/form', array('form' => $commentForm); from your article view. alternatively you could make a componet instead of using a straight partial... something like:
// in commentComponents.class.php
public function executeArticleCommentForm()
{
$comment = new Comment();
$comment->setArticle($this->article);
$this->form = new CommentForm($comment);
}
// in article/showArticleSuccess.php
<?php include_component('comment', 'articleCommentForm', array('article' => $article)); ?>