CakePHP常用代码
自定义Component
class ApiComponent extends Component {
public $controller;
public function __construct(ComponentCollection $collection, $settings = array()) {
$settings = array_merge($this->settings, ( array ) $settings);
$this->controller = $collection->getController();
parent::__construct($collection, $settings);
}
public function initialize(Controller $controller) {
$this->controller = $controller;
}
public function startup(Controller $controller) {
$this->controller = $controller;
}
}
controller中根据不同情况显示view
class ProdController extends AppController {
function detail() {
return $this->setAction('detail_coupon', $param);
}
function detail_coupon() {
$this->render();
}
}
动态展示view
try {
$this->set('page_css', 'page.css');
$this->render('/Page/'.$name);
}catch (Exception $e){
exit( "很抱歉,您访问的页面不存在" );
}
posted on 2020-07-07 15:06 aworkstory 阅读(107) 评论(0) 收藏 举报
浙公网安备 33010602011771号