Jump to content

Redroest

Members
  • Content Count

    150
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Redroest

  • Rank
    Member
  1. Well some frameworks apply the method I just told. I guess it depends on what is important. Smart technologie or performance
  2. Hey people. Im stuck again.I am building a framework based on the Model View Controller principe. My model has an query function like below: <?php //Load all default modules public function getBlockModules() { $sql = 'SELECT * FROM core_modules WHERE blockMode=1'; if(!$ModuleQuery = $this->db->query($sql)) { trigger_error('Error in the modulequery: '.$this->db->error); } else { $rows = array(); while($row = $ModuleQuery->fetch_object()) { $rows[] = $row; } return $rows; } }?> And my controller function to retreive data looks like this: <?php //Load all blocks $modules = $this->Model->getBlockModules(); foreach($modules AS $property) { //Load module into the view object $this->View->setContainer('modules/'.$property->controllerFile, 'modules/'.$property->headerFile, 'themes/Redroest/'.$property->layoutFile, $property->title, $property->positionTag); } }?> As you can see, I need 2 loops in order to keep the data separated from the logic part. Is there a way to prevent multiple loops from happening and still keeping the logics separated?
  3. Well, try to make a navigation structure in your website. For exampleindex.php <?phpinclude './config/config.php';include './libraries/output.php';include './libraries/session.php';if(!$_GET['page'] == 'picture'){ include './libraries/siteDB.php'; $dbConn = new siteDB;}else{ echo 'My image'; echo '<img src="image.png" alt="image" title="my image" />';}?>
  4. Redroest

    MVC model

    Ok here's the problem. I am trying to make a model object for my system. I'm trying to work step by step so things like a registerclass and a controller etc are not yet implemented. First of all the procedural code: <?phperror_reporting(E_ALL);$included = true;//configuration globals//This will be arranged by the registry object later on$host = "localhost";$username = "root";$password = "";$database = "core";$dbprefix = 'core';//Load classfilesinclude('classes/class_database.php');include('classes/class_module.php');include('classes/class_layout.php');include('classes/class_model.php');//Start database connection$db = new database($host, $username, $password, $database);//The container object is an extention of the module object. It loads files and returns its output//In this case it loads the template and returns its html$template = new container('themes/Redroest/layout.php', '', 'layout');//The template html will be stored in the template object to insert containers that load later on$layout = new layout($template->getBody());//The model will load moduleinfo from the database using query's//To switch to another storage type just change this model$model = new dbModule($db);//The model contains a method to load all the requested modules//If no condition is set it will load the home module + the blocks using 'WHERE home=1 OR blockMode=1';$model->condition = 'WHERE moduleID=13 OR blockMode=1';$model->getModules();//Output the final layoytecho $layout->getLayout(); Second is my model. This is where it goes wrong. The model contains a query that loads the modules using a while loop. My goal is to process these modules using my moduleclass without writing them in my model. This should be controlled using the controller....??? I inserted my situation in the code, I hope to get a solution or another approach to solve this problem. <?phpclass publicModel{ private $db; function __construct(database $db) { //Check if the database connection exists if($db->ping()) { $this->db = $db; } } //Load a default condition when no condition is set public function __get($value) { if(!isset($this->condition)) { $this->condition = 'WHERE home=1 OR blockMode=1'; } } //Load all required modules public function getModules() { $sql = 'SELECT * FROM core_modules '.$this->condition; if(!$ModuleQuery = $this->db->query($sql)) { //I know I know, this should be an exeption trigger_error('Error in the modulequery: '.$this->db->error); } else { //$modules = array(); while($ResultModule = $ModuleQuery->fetch_assoc()) { //This is where it goes wrong..... I can push the modules into another array and return it //but this requires me to make another loop in for example my controller object to load them //into containers and to push them into a layout. //Load a new module object $modules[$ResultModule['moduleID']] = new container('Modules/'.$ResultModule['controllerFile'], 'Modules/'.$ResultModule['headerFile'], $ResultModule['title']); //Set the layout for the module $modules[$ResultModule['moduleID']]->setLayout('themes/Redroest/'.$ResultModule['layoutFile']); //get the final output marked up with layout $container = $modules[$ResultModule['moduleID']]->getOutput(); //Insert the container into the layout $layout->setContainer($ResultModule['positionTag'], $container); } } }} ?> Help me on this please. I spend some hours trying to solve this puzzle, but couldn't find any usable examples
  5. Ah ok, thanks. Its important for me to know that. I never learned php from an education. Its just something I learned in my spare time.
  6. Cool, so I finally seem to get it now :)But how would you implement the optional parameter in the constructor then?
  7. Hello, I just made an moduleclass which loads files using filelinks and combines it with a layout. I just want to know, is this a correct OOP class? And do you people have any hints on how to make this better? <?phpclass module{ private $controllerFile; private $headerFile; private $title; public function __construct($controllerFile, $headerFile = '', $title) { if(is_file($controllerFile)) { $this->controllerFile = $controllerFile; } if(is_file($headerFile)) { $this->headerFile = $headerFile; } if(is_string($title)) { $this->title = $title; } } public function getTitle() { return $this->title; } public function getControllerFile() { return $this->controllerFile; } public function getHeaderFile() { return $this->headerFile; } public function getBody() { if(isset($this->controllerFile)) { $output = $this->getContent($this->controllerFile); if($output) { return $output; } } } public function getHeader() { if(isset($this->headerFile)) { return module::getContent($this->headerFile); } else { return ''; } } public function getContent($file) { ob_start(); include($file); $content = ob_get_contents(); ob_end_clean(); return $content; }}class container extends module{ public function setLayout($layoutFile) { if(is_file($layoutFile)) { $this->layout = module::getContent($layoutFile); } } public function getOutput() { $body = module::getBody(); $output = preg_replace('/<!-- blockcontent -->/', $body, $this->layout); $output = preg_replace('/<!-- blocktitle -->/', $this->getTitle(), $this->layout); return $output; }}?>
  8. Aw omg I made one little error. I've been struggling with it for over 2 days now and now suddenly it works just as you say.. Don't really know what went wrong though!Thanks anyway
  9. Well is it possible to group the buffers? like below??? <?php//Start primary bufferob_start('primary');//Start secondary buffer (for example in a function)ob_start('secondary');//End secondary bufferob_end_clear('secondary');//End primary bufferob_end_clear('primary');?> On php.net they say that ob_start() is a function that nests.. like: <?php//Start primary bufferob_start('primary');//Start secondary buffer (for example in a function) //This will output the first bufferob_start('secondary');//End bufferingob_end_clear('secondary');?>
  10. Make sure not to forget security (mysql_real_escape_string etc)
  11. Hey, I am working on a system that includes modules by using outputbuffering. The following function loads files from modules. The output generated by the module will be checked for so called "custom tags" and replaces them with modules. These modules will then be included into a template for example. <?phpfunction file_to_var($file){ if (is_file($file)) { ob_start();//Load the modulefile include($file); $content = ob_get_contents(); ob_end_clean(); return $content; }}?> This code works fine to me, but there is one problem. I just made a module in another system. This system has no outputbuffering and my module works fine in it. Here comes the problem:The module contains its own outputbuffering (I made a photoalbum manager using the JUpload applet which uses ob_start.To simplify: <?phpfunction file_to_var($file){ if (is_file($file)) { ob_start();//Load the modulefile include($file);//Module also contains ob_start()//as simulated on the below line: ob_start(); $content = ob_get_contents(); ob_end_clean(); return $content; }}?> As you can see and guess, the module will be outputted before the rest of the themplate and appears on top of the website.How to prevent this from happening? I don't want to modify every class, module or function that contains outputbuffering.
  12. I know thats the way I used to work, but this does not work also:function callback(xmlhttp){ var output = xmlhttp.responseText; return output;}Is there a way to simulate this ?
  13. Hey people I am trying to make an AJAX object that returns its values to a variable. Every time when I try to alert the output from the server it says undefined or [Object]. When I alert the xmlhttp.responseText within the sendRequest function it works! var XMLHttpFactories = [ function () {return new XMLHttpRequest()}, function () {return new ActiveXObject("Msxml2.XMLHTTP")}, function () {return new ActiveXObject("Msxml3.XMLHTTP")}, function () {return new ActiveXObject("Microsoft.XMLHTTP")}];function GetXmlHttpObject() { var xmlhttp = false; for (var i=0;i<XMLHttpFactories.length;i++) { try { xmlhttp = XMLHttpFactories[i](); } catch (e) { continue; } break; } return xmlhttp;}function sendRequest(url,postData){ //alert('sendRequest'); var xmlhttp = GetXmlHttpObject(); if (!xmlhttp) return; var method = (postData) ? "POST" : "GET"; xmlhttp.open(method,url,true); xmlhttp.setRequestHeader('User-Agent','XMLHTTP/1.0'); //xmlhttp.setRequestHeader('X-AJAX', 'True'); if (postData) xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded'); xmlhttp.onreadystatechange = function () { //alert('readyState: ' + xmlhttp.readyState); if (xmlhttp.readyState != 4) return; if (xmlhttp.status != 200 && xmlhttp.status != 304) { alert('HTTP error ' + req.status); return; } this response = xmlhttp; } if (xmlhttp.readyState == 4) return; xmlhttp.send(postData);} Call users values (for example) function getServerUsers(username, password){ var ServerValues = sendrequest('users.php', username='+username+'&password='+password); alert(ServerValues.responseText);} Im not very familier with javascript but I know that it has to be something like this to make it work. The Serverside script works and outputs. I always used a callback function but I think it can be shorter. So how to make this work?
  14. Simply said: real_escape_string is for making a legal query to INPUThtmlspecialchars is used for legal OUTPUT to your html/xhtml
  15. Redroest

    Moduleclass

    That was my original way of thinking synook. But I used this in an function oriented style and it gave the modulebuilder strict giudelines on how to make a module. So when I inserted something like a photoalbum that was used on many other websites it had to be rebuilded before I was able to use it.
×
×
  • Create New...