Post by Mikor » Wed Mar 16, 2016 6:42 pm

Hello,

how can you get the admin id (id = 1 )
exactly in the file admin /view/template/user/user_from.tpl want to admin id = 1 could not change the firstname and lastname

I checked if $ user_id ( [ ' user_id '] == '1') {

but unfortunately it did not work

Newbie

Posts

Joined
Wed Mar 16, 2016 2:44 am

User avatar
Guru Member

Posts

Joined
Wed Nov 16, 2011 11:53 am
Location - Singapore

Post by Mikor » Fri Mar 18, 2016 8:33 pm

unfortunately, does not work

Notice: Undefined property: Loader::$user

Newbie

Posts

Joined
Wed Mar 16, 2016 2:44 am

Post by MarketInSG » Fri Mar 18, 2016 9:21 pm

use that in the controller, not the template file if you are using OpenCart 2.


User avatar
Guru Member

Posts

Joined
Wed Nov 16, 2011 11:53 am
Location - Singapore

Post by ocart777 » Fri Mar 18, 2016 10:46 pm

code snippet for oc2.2
controller:

Code: Select all

$this->user = new Cart\User($this->registry);
$data['admin_id'] = $this->user->getId();
tpl:

Code: Select all

if ($admin_id == 1) {
// admin_id is 1
} else {
// admin_id is NOT 1
}

You can't control the weather, but you can change your mood.
You can't modify the visage, but you can show your smile.
You can't command someone else, but you can hold yourself.
You can't forecast tomorrow, but you can using today.
You can't obtain thanks, but you can exert yourself in everything.


OCEXTENSION.COM - YOUR PROFESSIONAL OPENCART EXTENSION STORE


User avatar
Active Member

Posts

Joined
Mon Jun 10, 2013 4:57 pm
Location - Malaysia

Post by Mikor » Sat Mar 19, 2016 1:42 am

still the same error

Notice: Undefined variable: admin_id in admin/view/template/user/user_form.tpl on line 55

Newbie

Posts

Joined
Wed Mar 16, 2016 2:44 am

Post by MarketInSG » Sat Mar 19, 2016 8:40 am

did you add it into the controller? You need to add the codes into the controller first.
$data['admin_id'] = $this->user->getId();
is the correct code


User avatar
Guru Member

Posts

Joined
Wed Nov 16, 2011 11:53 am
Location - Singapore

Post by Mikor » Sat Mar 19, 2016 4:13 pm

i add i controller admin/controller/user/user.php

Code: Select all

	public function edit() {
		$this->load->language('user/user');

		$this->document->setTitle($this->language->get('heading_title'));

		$this->load->model('user/user');
		$data['admin_id'] = $this->user->getId();
and in admin/viev/template/user/user_from.tpl

Code: Select all

			<?php if ($admin_id == 1) { ?>
			 <input type="text" name="firstname" value="<?php echo $firstname; ?>" placeholder="<?php echo $entry_firstname; ?>" id="input-firstname" class="form-control"/>	
			   <?php } ?>
and all the time the same error

Notice: Undefined variable: admin_id in admin/view/template/user/user_form.tpl on line 55

Newbie

Posts

Joined
Wed Mar 16, 2016 2:44 am

Post by ocart777 » Sat Mar 19, 2016 6:55 pm

first of all that code need to be placed inside a getForm(), and second i was misunderstanding at first, i thought you want to show on front end and get the admin id. however..inside your controller just after "protected function getForm() {" put below code

Code: Select all

$data['admin_id'] = isset($this->request->get['user_id']) ? $this->request->get['user_id'] : '';

You can't control the weather, but you can change your mood.
You can't modify the visage, but you can show your smile.
You can't command someone else, but you can hold yourself.
You can't forecast tomorrow, but you can using today.
You can't obtain thanks, but you can exert yourself in everything.


OCEXTENSION.COM - YOUR PROFESSIONAL OPENCART EXTENSION STORE


User avatar
Active Member

Posts

Joined
Mon Jun 10, 2013 4:57 pm
Location - Malaysia

Post by Mikor » Sat Mar 19, 2016 9:24 pm

Now works properly thank you very much for your help

Newbie

Posts

Joined
Wed Mar 16, 2016 2:44 am
Who is online

Users browsing this forum: No registered users and 11 guests