跪求php大侠,不懂可以帮忙顶下

xb12369 2012-02-27 03:00:05
php中将业务处理跟逻辑区分开,分别由这些control,tpl,php共同实现一个页面!!!

现在类中的code

class HR {
function __construct(){}

public static function get_emp_list($cid){//我一般用静态函数

return DB::getAll('select * from erp_employee where cid='.DB::quote($cid));
//DB为数据库操作类

}

}

控制器中【__control.php】的

public function default_action(){
$hr = new HR;
$empid = "S0001";
$info = $hr->get_emp_list($empid); //[这个怎么知道Info里有啥啊?]
$args=array('arg1' => $empid,'arg2' => 'aaaaaaaaa');
//$args['empinfo'] = $info;
$this->show_page('index',$args);
}


public function show_page($tpl,$data=null,$return=false){
if(!is_null($data) && is_array($data)){
foreach($data as $key=>$item)[code=PHP]
{
$this->page->add($key,$item);
}
}
$this->page->name=$tpl;
if($return){
return $this->page->fetch();
}else{
$this->page->show();
}
}
[/code]

我页面如何去数据啊【.tpl中】????

<div class="sContent">
<dl>
<dt>员工流水号</dt>
<dd><ul><li><a href=""><{$arg1}></a></li></ul></dd>
</dl>
<dl>
<dt>昵称</dt>
<dd><{$arg2}></dd>
</dl>
</div>
...全文
165 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
xb12369 2012-02-28
  • 打赏
  • 举报
回复
感谢大家的热情帮助,我上面的问题已经解决了!!

smarty中code这样写:


这里是class
public static function get_emp_all(){

return DB::getAll("select b.id,b.cid,b.staff_company,b.guakao,a.dept_code,d.title_code,b.idencard,b.phone,b.staff_realname,b.staff_nicheng,c.role_code from erp_deptment a,erp_employee b,erp_role c,erp_title d
where
b.deptID = a.ID
and b.title_id = c.ID
and b.role_id = d.id");
}


这里是control:
public function default_action(){
$list = HR::get_emp_all();

$args=array('list' => $list);

$this->show_page('index',$args);
}


页面上:
<table>
<{foreach from=$list item=item}>
<tr><td><{$item.id}></td></tr>
<tr><td><{$item.staff_realname}></td></tr></{forwach}>
</table>


每次遇到问题,其实就在csdn上寻找心灵的寄托,我知道可能我自己的问题只有我自己最清楚

但是就想在这写写,灰常感谢亲们的热情解答!!!

在上进ing...
xuzuning 2012-02-28
  • 打赏
  • 举报
回复
你只给出了代码片段,无法做测试

请说明你遇到了什么问题

xb12369 2012-02-28
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 zy205817 的回复:]
你是用的smarty,还是自己手动写的模板呢?
[/Quote]

手动编写的!!!
码无边 2012-02-28
  • 打赏
  • 举报
回复
你是用的smarty,还是自己手动写的模板呢?
luojxun 2012-02-27
  • 打赏
  • 举报
回复
<?php
print <<<EOT
<div class="sContent">
<dl>
<dt>员工流水号</dt>
<dd><ul><li><a href=""><{$arg1}></a></li></ul></dd>
</dl>
<dl>
<dt>昵称</dt>
<dd><{$arg2}></dd>
</dl>
</div>
EOT;
?>

$args=array('arg1' => $empid,'arg2' => 'aaaaaaaaa');
include ('**.tpl');
xb12369 2012-02-27
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 foolbirdflyfirst 的回复:]
数组要pirnt_r或者var_dump.
[/Quote]

能不能说详细一点啊!!

$args=array('arg1' => $empid,'arg2' => 'aaaaaaaaa');

这样:print_r $args;

貌似不行
foolbirdflyfirst 2012-02-27
  • 打赏
  • 举报
回复
数组要pirnt_r或者var_dump.
xb12369 2012-02-27
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 happypiggy2010 的回复:]
mvc都是以struct等形式传数据的。
[/Quote]

我不知道这个:$info = $hr->get_emp_list($empid);
有木有值,用echo 和 print 都显示不到

这种语法 我根本就不会啊!!!

happypiggy2010 2012-02-27
  • 打赏
  • 举报
回复
mvc都是以struct等形式传数据的。
xb12369 2012-02-27
  • 打赏
  • 举报
回复
控制器中的
public function default_action(){
$hr = new HR;
$empid = "S0001";
$info = $hr->get_emp_list($empid);

$args=array('arg1' => $empid,'arg2' => 'aaaaaaaaa');
//$args['empinfo'] = $info;
$this->show_page('index',$args);
}


public function show_page($tpl,$data=null,$return=false){
if(!is_null($data) && is_array($data)){
foreach($data as $key=>$item){
$this->page->add($key,$item);
}
}
$this->page->name=$tpl;
if($return){
return $this->page->fetch();
}else{
$this->page->show();
}
}

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧