2

CodeIgniter に問題があります。という名前のsiteコントローラーがあり、このコントローラーには と の 2 つのメソッドがproductionありstoryます。

productionを作成するモデルを介して特定のプロダクションを呼び出しますproduction/slug

私が達成したいのは、次の URL を作成することです。

site/production/slug/story 

どうすればそれを達成できますか?スラッグが変化するので、ストーリー関数で を使用してデータベースからストーリーを呼び出したいと思います$this->uri->segment(3)

4

2 に答える 2

1

複数のパラメーターを投稿できます。

URI: site/production/slug/story/5

public function production($one, $two, $there)
{
    echo $one."<br />";
    echo $two."<br />";
    echo $there."<br />";
}

# OUTPUT
slug
story
5
于 2013-07-19T11:49:31.257 に答える
0

method名前を 2 番目のパラメーターとして最初のメソッドに渡します。たとえば、URI が の場合、メソッドsite/production/slug/storyに渡しstoryて、production以下のように必要なチェックを行います。

class Site extends CI_Controller {

    public function __construct()
    {
        parent::__construct()
    }

    public function story($text) {
        echo $text;
    }

    public function production($slug = '', $callback = NULL)
    {
        // Do something with $slug

        if (isset($callback) && method_exists(__CLASS__, $callback)) {
            $this->{$callback}($slug);
        }
    }
}

PHPFiddle デモ

于 2013-07-19T12:02:38.783 に答える