0

私の投稿には本文テキストがあり、このテキストに [gallery=2] のような短いコードを入れました。これで、テキストに 2 つの引数 (ギャラリーと 2) を見つけることができます。ビューで関数 (ギャラリー) を動的に呼び出したいのですが、それは次のように要素(ギャラリーID = 2)を呼び出します:

アプリ/ビュー/投稿/index.ctp

findshortcode($posts[Post][Body]); // this function find short code and call his name like gallery(2) 

//my problem is :

function gallery($id = null){
    $this->element('gallery', array('galleryid' => $id), array('plugin' => 'gallerys'));  
}
4

1 に答える 1

0

そこにあるものはあまり意味がありません。あなたが説明している方法は、CakishまたはMVCの方法ではありません。しかし、私はあなたの質問を受け取り、あなたがやりたい方法を説明すると思います.

あなたがする必要があるのはこれです...コントローラー内からすべてのロジックを実行します...次に、完成したすべての変数をビューに送信して表示します...

class PostsController extends AppController {

var $shortCodeTypes = array('gallery');

function view($id){
    $post = $this->Post->find(null, $id);
    $post = $this->_insertShortCodes($post);
    $this->set(compact('post'));
}

function _insertShortCodes($post){

    foreach($this->shortCodeTypes as $shortCodeType){
        // Do logic to find shortcodes and insert data into post body
    }
    return $post
}
于 2012-05-14T21:08:52.520 に答える