请教关于控制器内方法调用的问题

#1 改变命运2023

我想在控制器下调用其它方法,来避免重复使用。应该怎么办?比如
function s_select2(){
            $tpl=$this->spArgs("tpl","default");
            $products=spClass("products");
            $images=spClass("s_images");
            

   
            $condition=array('c2name'=>$this->spArgs("c2name"));            
        $this->results=$products->spPager($this->spArgs('page', 1), 5)->findAll($condition);// 这里使用了spPager,同时用spArgs接受到传入的page参数
        $this->images=$images->findAll();
        $this->pager = $products->spPager()->getPager();// 这里获取分页数据并发送到smarty模板内
            $this->display("{$tpl}/product.html");
            $this->display("{$tpl}/pro_left.html");
    }
    function s_select3(){
            $tpl=$this->spArgs("tpl","default");
            $products=spClass("products");
            $images=spClass("s_images");
            
            $condition=$this->spArgs("name");
            $sql ="SELECT * FROM products WHERE name like '%".$condition."%'";   
        
                $this->results=$products->spPager($this->spArgs('page', 1), 5)->findSql($sql);// 这里使用了spPager,同时用spArgs接受到传入的page参数
        
        $this->images=$images->findAll();
        $this->pager = $products->spPager()->getPager();// 这里获取分页数据并发送到smarty模板内
            $this->display("{$tpl}/product.html");
            $this->display("{$tpl}/pro_left.html");
    }
我想在s_select2中调用s_select3中的方法,这样我就不用重复写方法了。

2012-05-06 17:09:58

#2 jake

在s_select2中调用s_select3

$this->s_select3();

详细见PHP基础语法 http://cn.php.net/manual/zh/language.oop5.basic.php

2012-05-06 17:32:59

#3 改变命运2023

jake 发表于 2012-5-6 17:32
在s_select2中调用s_select3

$this->s_select3();
非常感谢jake的耐心回答,这个问题让我有些不好意思了,基础不扎实,一定补上。{:soso_e113:}

2012-05-07 10:05:38