Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Store Author Name in database

Is It Possible to write.. 'name' => $this->request->getName() ????



36.4k

Can you explain detail clearly ?

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?


36.4k
Accepted
answer

Hi

The method getName() does not in service request, you need to create a input author name like description , then you call it

$this->request->getPost('name')
edited Aug '15

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']) }}

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.

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.



36.4k

{{ 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.