Dayo Posted July 29, 2010 Share Posted July 29, 2010 hiya i have never used class varables before untill my project the shadow realm, i want to make a CSS class for my game so i can add only the css i need to the page for example $css->AddId('CSS ID', 'CSS HERE eg margin:0px;'); $css->AddClass('CSS CLASS ID', 'CSS HERE eg border:none;'); i thought about laying it out like this class css { var $csssheet; function Show(){ // no problems with this! echo '<style type="text/css"> <!-- '.$this->csssheet.' --> </style> '; } function AddId($id, $css) { $var=' #'.$id.'{ '.$css.' }'; $this->csssheet .= $var; // this dosent work though } } this is probley a realy nobby question and will probly LOL at my self when i see what i done wrong but my mind has just gone blank :S Quote Link to comment Share on other sites More sharing options...
Dayo Posted July 29, 2010 Author Share Posted July 29, 2010 LOL dont worry, i was trying to show the css before i added it throght the function Quote Link to comment Share on other sites More sharing options...
Djkanna Posted July 29, 2010 Share Posted July 29, 2010 <?php class Css { public $cssSheet; public function show() { echo '<style>'.$this->cssSheet.'</style>'; } public function addClass($name, $content) { $newClass = '.'.$name.' { '.$content.' }'; $this->cssSheet .= $newClass; } public function addId($name, $content) { $newId = '#'.$name.' { '.$content.' }'; $this->cssSheet .= $newId; } } $css = new Css; ?> EDIT: Didn't see your previous post :S Quote Link to comment Share on other sites More sharing options...
Dayo Posted July 29, 2010 Author Share Posted July 29, 2010 thanks anyway, i just have to figure how to get the CSS from the bottom of the page to the top as it will bug me it being there lol edit: public function addId($name, $content) { $newId = '#'.$name.' { '.$content.' }'; $this->cssSheet .= $newClass; should be public function addId($name, $content) { $newId = '#'.$name.' { '.$content.' }'; $this->cssSheet .= $newId; i did mine diffrent to yours, plus i am going to do this with my JS files aswell, i just want to clean up my HTML files as atm on one site i have 21 JS files loading up and 3 CSS files :S Quote Link to comment Share on other sites More sharing options...
Djkanna Posted July 29, 2010 Share Posted July 29, 2010 thanks anyway, i just have to figure how to get the CSS from the bottom of the page to the top as it will bug me it being there lol Haha :) Quote Link to comment Share on other sites More sharing options...
Dayo Posted July 29, 2010 Author Share Posted July 29, 2010 i was thinking of using ob_start and preg but im no good with the preg so i may just have to deal with it Quote Link to comment Share on other sites More sharing options...
Djkanna Posted July 30, 2010 Share Posted July 30, 2010 function jsLoad($name) { if(file('assets/js/'.$name)) { return '<script src="assets/js/'.$name.'"></script>'; } } I use something along those lines to load Js Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.