CakePHP - How do i set the page title to an item name?

后端 未结 10 924
囚心锁ツ
囚心锁ツ 2021-01-03 02:13

OK, so I\'m trying to teach myself the CakePHP framework, and I\'m trying to knock up a simple demo app for myself.

I have the controllers, views and models all set

10条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-03 02:37

    You can set this in the controller:

    function view($id = null) {
        $guitar = $this->Guitar->read(null, $id);
        $this->set('guitar', $guitar);
        $this->pageTitle = $guitar['Guitar']['name'];
    }
    

    Or in the view:

    pageTitle = $guitar['Guitar']['name']; ?>
    

    The value set in the view will override any value that may have already been set in the controller.

    For security, you must ensure that your layout / view that displays the pageTitle html-encodes this arbitrary data to avoid injection attacks and broken html

    
    

提交回复
热议问题