Smarty + CodeIgniter - proper way to use a model

谁都会走 提交于 2019-12-11 05:43:35

问题


First off: I do realize that using models in a view is against the MVC hierarchy - but that's the smoothest solution I've found so far.

I've integrated Smarty into my CodeIgniter CMS application. One of its features is the usage of templates along with minifying static content such as CSS and JavaScript. Hence, I'm trying to do something like this in the template file:

//Adding the static content
<?php
$this->content->css( array('my.css', 'style.css') );
?>

<html>
   <head>
      //Displaying the now minified static content
      <?php $this->content->display() ? >
   </head>
</html>

Since the final template should be editable by the end user or similar, I believe that this is the most simple solution.

Appreciating all input!


回答1:


I think you shouldn't use any codeigniter-releated function in Smarty-templates. The CSS directory is constant so unnecessary to call a php-function.

If you'll need some information from CI, you'll assign to a smarty-variable in your controller-function - so doesn't break MVC:

$smarty->assign(array(
   "display" => $this->content->display(),
   "css_include" => $this->content->css(array("my.css","style.css"))
));

As jco wrote above in simple cases CI&Smarty maybe "overkill". But same cases it's very useful (e.g. template inheritance and blocks can use to create same form-types).




回答2:


I've used both smarty and codeigniter and in my experience using both is overkill. Smarty just mucks up your code and IMHO is cumbersome to use. Think of codeigniter views as the equivalent of your smarty templates.

If you are worried about minification you could try using something like this: CSS Minification Library

Hope this is helpful.



来源:https://stackoverflow.com/questions/10259484/smarty-codeigniter-proper-way-to-use-a-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!