我使用2张桌子。该表的第一个是Department。我想在用户个人资料页面中显示部门。用户可以在配置文件页面中编辑部门。但首先,他可以在“个人资料页面”和“个人资料编辑页面”中看到自己的部门。但是,“配置文件页面”和“配置文件编辑页面”中都没有“部门”字段。也许我能做到吗?
我的代码如下:
配置文件的控制器:
public function index()
{
$viewData = new stdClass();
$viewData->user = $this->db->get("user")->result();
$viewData->departments = $this->db->get("department")->result();
$this->lang->load('content', $this->session->userdata('userLang'));
$this->load->view('profile', $viewData);
}
我的个人资料视图:
<aside class="profile-info col-lg-9">
<section class="panel">
<div class="bio-graph-heading">
<?php echo $this->lang->line('profile_top_profile_text'); ?>
</div>
<div class="panel-body bio-graph-info">
<h1><?php echo $this->lang->line('profile_text_informations'); ?></h1>
<div class="row">
<div class="bio-row">
<p><span><?php echo $this->lang->line('profile_first_name'); ?></span>: <?php echo $this->session->userdata('people_name'); ?></p>
</div>
<div class="bio-row">
<p><span><?php echo $this->lang->line('profile_last_name'); ?> </span>: <?php echo $this->session->userdata('people_surname'); ?></p>
</div>
<div class="bio-row">
<p><span>Username </span>: <?php echo $this->session->userdata('people_username'); ?></p>
</div>
<div class="bio-row">
<p><span>Email </span>: <?php echo $this->session->userdata('people_email'); ?></p>
</div>
<div class="bio-row">
<p><span>Language</span>: <?php if ($this->session->userdata('people_lang') == 'en') echo 'English'; else { echo 'Arabic'; } ?></p>
</div>
<div class="bio-row">
<p><span>Department </span>: <?php if ($this->session->userdata('people_department') == $departments->departmentId) { echo $departments->departmentName;} ?></p>
</div>
<div class="bio-row">
<p><span>User Type</span>: <?php if ($this->session->userdata('people_department') == 'en') echo 'English'; else { echo 'Arabic'; } ?></p>
</div>
<div class="bio-row">
<p><span>User Status</span>: <?php echo ($this->session->userdata('people_status') == 1) ? "<span class='label label-success''>Active</span>" : "<span class='label label-danger''>Deactive</span>" ?></p>
</div>
<div class="bio-row">
<p><span>Registered Date </span>: <?php echo $this->session->userdata('people_date'); ?></p>
</div>
<div class="bio-row">
<p><span>Modified Date </span>: <?php echo $this->session->userdata('people_mdate'); ?></p>
</div>
</div>
</div>
</section>
</aside>
部门数据库:
CREATE TABLE `department` (
`departmentId` int(11) NOT NULL AUTO_INCREMENT,
`departmentOffice` int(11) NOT NULL,
`departmentName` varchar(80) COLLATE utf8_turkish_ci NOT NULL,
`departmentAuthPerson` int(11) DEFAULT NULL,
PRIMARY KEY (`departmentId`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci;
我应该那样做吗?或者我该怎么办?感谢您的帮助,大社区。 p>
答案 0 :(得分:0)
希望这对您有帮助:
在索引方法中使用row()
代替result()
public function index()
{
$viewData = new stdClass();
$viewData->user = $this->db->get("user")->result();
$viewData->departments = $this->db->get("department")->row();
$this->lang->load('content', $this->session->userdata('userLang'));
$this->load->view('profile', $viewData);
}