Is It Possible to write.. 'name' => $this->request->getName() ????
|
Aug '15 |
4 |
324 |
0 |
public function createAction() { if ($this->request->isPost()) {
$blog = new Blogs();
$blog->assign(array(
'title' => $this->request->getPost('title', 'striptags'),
'description' => $this->request->getPost('description'),
'name' => $this->request->getName()
));
if (!$blog->save()) {
$this->flash->error($blog->getMessages());
} else {
$this->flash->success("Blogs was created successfully");
Tag::resetInput();
}
}
$this->view->form = new BlogsForm(null);
}
here i'm try to get author name and save it in my database. is it possible or not? if it is not possible how could i save author name in my database?
I think it is fine.
I can found a way to show author name.
<input type="text" value="{{ auth.getName() }}" class="form-control" disabled>
I don't know it is right process or wrong. if it will wrong please post that.
{{ auth.getName() }} is working because the dependency injection auth have a method getName() see here
another problem here I've found.
{{ auth.getName() }} is working, but I want to view it in an input form. How can I do that?
like.. {{ form.render('description', ['class': 'form-control']) }}
solve my problem. 1st i was write a function in base controller
public function getName() { $user = $this->auth->getIdentity(); return $user['name']; }
then i was create this
$blog->name = $this->getName(); in blogController
and create a name field in data table.
and now i store current user name in may database.