0

私は 2 つのコントローラーを持っています。1 つはベース コントローラーで、もう 1 つはベース コントローラーにありsubjectます。モデルからいくつかの配列を定義しました。

class Controller_Base extends Controller_Template {

    public $template = 'main';

    public function before()
    {
        parent::before();

        $webs = array();
        $apps = array();

        $app = new Model_Application();
        $apps = $app->get_all();

        $web = new Model_Web();
        $webs = $web->get_all();

        $this->template->content = '';
        $this->template->styles = array('style');
        $this->template->scripts = '';

        $this->template->webs = $webs;
        $this->template->apps = $apps;

    }

}

コントローラーの件名で、関数 in_array を使用しています

class Controller_Subject extends Controller_Base {

public function action_all()
{

    $url = $this->request->param('url');

    $this->template->caption = $url;


    if (in_array($url,$this->template->webs)) { 
        echo "web";
    }
        elseif (in_array($url,$this->template->apps)) { 
        echo "apps";
    }

    $links = array("a"=>"1","b"=>"2");

    $view = View::factory('subject')
                ->set('links',$links);

    $this->template->content = $view;

}

}

しかし、コハナは私にエラーを返します:

ErrorException [ Warning ]: in_array() [<a href='function.in-array'>function.in-array</a>]: Wrong datatype for second argument

どうしたの?

4

2 に答える 2

2

Database_Result オブジェクトの代わりに配列変数が必要です。

...
$apps = $app->get_all()->as_array();
...
$webs = $web->get_all()->as_array();
...
于 2012-09-02T18:48:37.550 に答える
1

モデルが返すデータ、つまり は、Database_MySQL_Result最初に配列に変更する必要があります。あなたが使用することができます

foreach($query as $v) 
    $arr[]=$v; 
return $arr;

あなたのget_all()

于 2012-09-04T08:11:37.523 に答える