doujia7162 2013-05-16 19:11
浏览 12

在现有的php类中添加额外的逻辑,我的保存/更新逻辑出现问题

Here's my class and I'm wishing to add a whole new table (from sql) to this class.

I changed a select box on an edit page and it now references a different table.

<tr><td>Trainer Group</td><td><?php sbox('name', sql::one_column_array("select substring(name, 1, 27) from et.do.trainer_group")); ?></td></tr>

my old select box referenced et.AS.trainer and so now the save logic is broken.

I wish to add a bunch of new class variables for all the fields in the new table which i know i can accomplish by adding to the static variables below.

class Trainer
    {

public $id,
        $first,
        $last,
        $trainer_address1,
        $trainer_address2,
        $CITY,
        $STATE,
        $trainer_zip,
        $trainer_phone,
        $trainer_fax,
        $trainer_cell,
        $website_trainer_id,
        $trainer_email,
        $trainer_group,
        $lat,
        $long,
        $group_name,
        $name,
        $inactive,
        $group_id;



public function __construct($array) 
    {
    foreach ($array as $k => $v) 
        {
        if (property_exists($this, $k))
            $this->{$k} = strtoupper($v);
        }
    }   

public static function db_trainer ($id) 
    {
    $results = sql::clean_row('Select * from et.AS.trainer where id ='. $id);
    return new \AS\Trainer($results);
    } 

public function save()
    {
    if(!$this->id)
        $this->id = '';
    sql::merge('et', 'AS', 'trainer', array('id'), get_object_vars($this));
    }

public function update($array)
    {

    foreach ($array as $k=>$v)
    {
        if (property_exists($this, $k) && $v != $this->{$k})
        {
            $this->{$k} = strtoupper($v);
        }
    }
    $this->save();  
    }

In my class i can not get the new select box to save.. in the db_trainer function i added a sql left outer join to include the new table and now i'm able to create new static variables from that trainer_group table like so:

Select * from et.AS.trainer a left outer join event.dbo.trainer_group b on a.group_id = b.id where a.id ='. $id

my problem is obviously in the save() or the update()

How can i use my save logic in the merge so when someone uses the select box it starts sticking?

I'm imagining since this problem is on my edit page i'll need to add some logic into the update function by editing the foreach loop..?

Any help would be greatly appreciated.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 有人能看一下我宿舍管理系统的报修功能该怎么改啊?链表那里总是越界
    • ¥15 cs loadimage运行不了,easyx也下了,没有用
    • ¥15 r包runway详细安装教程
    • ¥15 Html中读取Json文件中数据并制作表格
    • ¥15 谁有RH342练习环境
    • ¥15 STM32F407 DMA中断问题
    • ¥15 uniapp连接阿里云无法发布消息和订阅
    • ¥25 麦当劳点餐系统代码纠错
    • ¥15 轮班监督委员会问题。
    • ¥20 关于变压器的具体案例分析