0
NOTE: UPDATED MY QUESTION

I am using zend.I have the file "stylesettings.php" under css folder. Having the following line to convert php file to css.

header("Content-type: text/css");

stylesetting.php is under application/css/stylesettings.php Now i want to get the color code from my DB in stylesettings.php.Here i can write basic DB connection code to get values from DB. I guess there might be another way to get all DB values by using zend. How can we connect DB like "Zend_Db_Table_Abstract" in stylesettings file ?

Is it possible to use zend component in that file ? Kindly advice on this.

I hope you understand.

mymotherland
  • 7,968
  • 14
  • 65
  • 122
  • excuse the curiosity, but why you want to take the colors from the database to compose the file stylesheet? – JellyBelly Nov 25 '11 at 14:10
  • @JellyBelly Actually I have the style setting module in my admin end which is having font style,color style for the front end. How can we implement this in zend? – mymotherland Nov 28 '11 at 05:33
  • I found answer by using http://stackoverflow.com/questions/1537700/sending-variables-to-the-layout-in-zend-framework – mymotherland Nov 28 '11 at 06:54

2 Answers2

0

You are breaking the basic separated model assumed in a MVC framework. For such color code, if it's only used in one place, I would suggest that you output the color in the "style="color: <color>"" in-line style in order to keep the dynamic part in HTML and your CSS file static.

If you really want to do this, then you should consider output your dynamic stylesheet in a URL path other than css, and use the controller/views etc to generate the stylesheet.

timdream
  • 5,914
  • 5
  • 21
  • 24
  • @trimdream Thanks, ok let me call function for style settings in init() under every controller and use the view variable in phtml file. – mymotherland Nov 28 '11 at 05:38
  • @trimdream I have used plugin like Zend_Controller_Front::getInstance()->registerPlugin(new My_Layout_Plugin()); by using this i can able to use my color settings only in layout.phtml. but not in other template files. Can you tell me how we use the same in other phtml files. – mymotherland Nov 28 '11 at 07:09
0

i am using the following way to apply color settings in layout.phtml

Use below code in bootstrap file

<?php
require_once 'plugins/StyleController.php';
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
 protected function _initRouter() {
            $front = Zend_Controller_Front::getInstance ();
            $front->setControllerDirectory ( dirname ( __FILE__ ) . '/controllers' );
            $router = $front->getRouter ();
            $front->registerPlugin ( new StyleController ( $router ) );
    }    

}

Created folder plugins under application and create a new file called stylecontroller.php

<?php

class StyleController extends Zend_Controller_Plugin_Abstract
{
   public function preDispatch(Zend_Controller_Request_Abstract $request)
   {
      $layout = Zend_Layout::getMvcInstance();
      $view = $layout->getView();
      /* code for getting color settings */
      $this->settings = new Admin_Model_DbTable_Settings();
      $view->colorsettings = $this->settings->getStyleSettings();
      //print_obj($view->colorsettings);      
   }
}

?>

Also to get color code,

<?php
class Admin_Model_DbTable_Settings extends Zend_Db_Table_Abstract
{
        public function getStyleSettings()
    {
            $select = $this->_db->select()
                        ->from('style_settings');
            $result = $this->getAdapter()->fetchAll($select);
            return $result['0'];
        }
}
?>

By using above code i can able to use $this->colorsettings in layout page.

This one fix my dynamic color in layout but not in other template files.

mymotherland
  • 7,968
  • 14
  • 65
  • 122