0

thingy/stuffたとえば、ディレクトリにあるコントローラーがあります

<?php public function index() { /*thingy stuff */ }

public function anotherfunction() {/*other thingy stuff*/} ?>

次のような URL が表示されますindex.php?route=thingy/stuff&var=dd

私が望むのは、そのコントローラー内のこの関数に $.post を呼び出すことです

そのため、別のテンプレート ファイルthingy.tplを使用し、使用する html を返します

URLは何ですか??

私は何時間も検索しましたが、オープンカートの開発ドキュメントがないようです

4

2 に答える 2

6

たとえば、thingy フォルダーの下に「stuff」というコントローラーがあり、そのクラス内に「my function」という関数があるとします。これは次のようになります。

class ControllerThingyStuff extends Controller {
    public function index() {  
  // Some code
}
public function myfunction() {
// Your code
}
}

URL を使用してこの関数と直接通信したい場合は、関数名をルート パラメーターの末尾に追加し、"route=thingy/stuff/myfunction& ..." を指定して、thingy.tpl を関数内にロードし、後で返すことができます。レンダリング:

// some code
$this->template = 'template/product/thingy.tpl';
...
$this->response->setOutput($this->render());

オープン カート 1.5 を使用していて、JSON で jQuery AJAX を使用する場合は、レンダリングする前に JSON ライブラリをインポートする必要があります。

$this->template = 'thingy/stuff/thingy.tpl';
$json['output'] = $this->render();
$this->load->library('json');
$this->response->setOutput(Json::encode($json));

いくつかのアイデアを得るためにチェックアウト ページを見てみましょう。デフォルトのオープン カート 1.5 テンプレートは、同じ手法を使用して各セクションのテンプレートを読み込みます。

于 2011-11-02T16:16:13.973 に答える
3

インデックスでない場合、ルートに追加されます。たとえば、デフォルトではインデックスです。

<?php
class ControllerThingyStuff extends Controller {

    public function index() {
        // This is called with route=thingy/stuff or thingy/stuff/index
    }

    public function something() {
        // This is called with route=thingy/stuff/something
    }
}
于 2011-11-02T15:56:39.393 に答える