blinky001
Newly Registered-
Posts
29 -
Joined
-
Last visited
About blinky001
- Birthday 01/01/1980
Profile Information
-
Gender
Male
-
Location
USA
blinky001's Achievements
Newbie (1/5)
0
Reputation
-
Found a work around online (credit to Daniel Cousineau). Apparently the ZF does not allow for multiple error controllers by default - God knows why not - it is very useful to be able to handle errors differently for different modules... <?php class APP_Controller_Plugin_ErrorControllerSelector extends Zend_Controller_Plugin_Abstract { public function routeShutdown(Zend_Controller_Request_Abstract $request) { $front = Zend_Controller_Front::getInstance(); # If the ErrorHandler plugin is not registered, bail out if(!($front->getPlugin('Zend_Controller_Plugin_ErrorHandler') instanceOf Zend_Controller_Plugin_ErrorHandler)) { return; } $error = $front->getPlugin('Zend_Controller_Plugin_ErrorHandler'); # Generate a test request to use to determine if the error controller in our module exists $testRequest = new Zend_Controller_Request_HTTP(); $testRequest->setModuleName($request->getModuleName()) ->setControllerName($error->getErrorHandlerController()) ->setActionName($error->getErrorHandlerAction()); # Does the controller even exist? if($front->getDispatcher()->isDispatchable($testRequest)) { $error->setErrorHandlerModule($request->getModuleName()); } } } and then in the bootstrap just register an extra plugin: <?php $frontController->registerPlugin(new APP_Controller_Plugin_ErrorControllerSelector()); ?> Hope this helps others...
-
Afraid I've never tried to do this in PHP, but I did have a go starting from someone elses script once in JS, sadly my Zelda clone was too boring to work on for very long... //pathFinder.js function pathFinder(grid) { this.grid = grid; this.cols = grid[0].length; this.rows = grid.length; this.limit = this.cols * this.rows; } pathFinder.prototype = { // Variables --------------------------------------------------------- grid: new Array(), start: new Array(), end: new Array(), cols: 0, rows: 0, limit: 0, // Returns boolean value (Grid cell is available and open) inGrid: function(x, y) { return this.grid[y][x] === 1; }, // Node function, returns a new object with Node properties node: function(parent, point) { return { parent: parent, value: point.x + (point.y * this.cols), x: point.x, y: point.y, f: 0, g: 0 }; }, calculatePath: function(start, end) { this.start = start; this.end = end; var startNode = this.node(null, {x:this.start[0], y:this.start[1]}), endNode = this.node(null, {x:this.end[0], y:this.end[1]}), AStar = new Array(this.limit), openArray = [startNode], closedArray = [], resultArray = [], successorNodes, currentNode, pathNodes, length, max, min, i, j; while(length = openArray.length) { max = this.limit; min = -1; for(i = 0; i < length; i++) { if(openArray[i].f < max) { max = openArray[i].f; min = i; } } currentNode = openArray.splice(min, 1)[0]; if(currentNode.value === endNode.value) { pathNodes = closedArray[closedArray.push(pathNodes) - 1]; do { resultArray.push([pathNodes.x, pathNodes.y]); } while(pathNodes = pathNodes.parent); AStar = closedArray = openArray = []; resultArray.reverse(); } else { successorNodes = this.successors(currentNode.x, currentNode.y); for(i = 0, j = successorNodes.length; i < j; i++) { pathNodes = this.node(currentNode, successorNodes[i]); if(!AStar[pathNodes.value]) { pathNodes.g = currentNode.g + this.manhattan(successorNodes[i], currentNode); pathNodes.f = pathNodes.g + this.manhattan(successorNodes[i], endNode); openArray.push(pathNodes); AStar[pathNodes.value] = true; } } closedArray.push(currentNode); } } return resultArray; }, // Find adjacent available cells - returns every available North, South, East or West cell successors: function(x, y) { var N = y - 1, S = y + 1, E = x + 1, W = x - 1, $N = N > -1 && this.inGrid(x, N), $S = S < this.rows && this.inGrid(x, S), $E = E < this.cols && this.inGrid(E, y), $W = W > -1 && this.inGrid(W, y), result = []; if($N) { result.push({x:x, y:N}); } if($E) { result.push({x:E, y:y}); } if($S) { result.push({x:x, y:S}); } if($W) { result.push({x:W, y:y}); } //this.diagonalSuccessors($N, $S, $E, $W, N, S, E, W, result); return result; }, diagonalSuccessors: function($N, $S, $E, $W, N, S, E, W, result) { if($N) { if($E && this.inGrid(E, N)) { result.push({x:E, y:N}); } if($W && this.inGrid(W, N)) { result.push({x:W, y:N}); } } if($S) { if($E && this.inGrid(E, S)) { result.push({x:E, y:S}); } if($W && this.inGrid(W, S)) { result.push({x:W, y:S}); } } }, diagonalSuccessors$: function($N, $S, $E, $W, N, S, E, W, result) { $N = N > -1; $S = S < this.rows; $E = E < this.cols; $W = W > -1; if($E) { if($N && this.inGrid(E, N)) { result.push({x:E, y:N}); } if($S && this.inGrid(E, S)) { result.push({x:E, y:S}); } } if($W) { if($N && this.inGrid(W, N)) { result.push({x:W, y:N}); } if($S && this.inGrid(W, S)) { result.push({x:W, y:S}); } } }, // Distance functions, returns ideal distance from 2 points diagonal: function(point, end) { // diagonal movement return Math.max(Math.abs(Point.x - end.x), Math.abs(Point.y - end.y)); }, euclidean: function(point, end) { // diagonal movement using Euclide (AC = sqrt(AB^2 + BC^2)) // where AB = x2 - x1 and BC = y2 - y1 and AC will be [x3, y3] return Math.sqrt(Math.pow(point.x - end.x, 2) + Math.pow(point.y - end.y, 2)); }, manhattan: function(point, end) { // linear movement return Math.abs(point.x - end.x) + Math.abs(point.y - end.y); } } and usage test: //pathFinderDemo.js window.onload = function() { var movementMap = [ [1, 1, 0, 1, 1, 1], [1, 1, 0, 1, 0, 1], [1, 1, 0, 1, 0, 1], [1, 1, 0, 1, 0, 1], [1, 1, 1, 1, 0, 1], ]; for(y = 0; y < movementMap.length; y++) { // Loop Width for(x = 0; x < movementMap[0].length; x++) { var element = document.createElement('div'); element.style.position = 'absolute'; element.style.left = (x * 32) + 'px'; element.style.top = (y * 32) + 'px'; element.style.width = 32 + 'px'; element.style.height = 32 + 'px'; element.id = x + '_' + y; if(movementMap[y][x] == 1) { element.style.backgroundColor = 'blue'; } else { element.style.backgroundColor = 'red'; } document.getElementById('map').appendChild(element); } } var startPoint = [0, 2]; var endPoint = [5, 4]; if(path = new pathFinder(movementMap)) { result = path.calculatePath(startPoint, endPoint, 'Manhattan'); if(result.length == 0) { alert('damn'); } else { for(var i = 0; i < result.length; i++) { x = result[i][0]; y = result[i][1]; var element = document.createElement('div'); element.style.position = 'absolute'; element.style.left = (x * 32) + 'px'; element.style.top = (y * 32) + 'px'; element.style.width = 32 + 'px'; element.style.height = 32 + 'px'; element.id = 'p_' + x + '_' + y; element.style.backgroundColor = 'green'; element.style.textAlign = 'center'; element.innerHTML = i + 1; document.getElementById('map').appendChild(element); } } } } and the basic html to let you see it: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title> Pathfinder Demo </title> <meta name="author" content="" /> <meta name="keywords" content="" /> <meta name="description" content="" /> <script src="pathFinder.js" type="text/javascript"></script> <script src="pathFinderDemo.js" type="text/javascript"></script> </head> <body> <div id="map"></div> </body> </html>
-
Seems that this isn't the right place for this post - any chane an admin could wing it over to the 3rd party scripts section (sorry - new to the board)
-
Classes are pretty simple... If you have a directory for includes just make a new file and put in that class info. Then include and use it. E.g. <?php include('../includes/core.php'); include('../includes/timing.php'); $timer = new Timer(); # All the rest of your page here echo $timer->getTime(); ?> The reason it is a bit more complicated is that it allows you to make new names (or something) - which is totally not required (not my class).
-
I'm no expert at this sort of thing... but php.net has plenty of these scripts... <?php $filename = "whatever.xxx"; $myFile = "/absolute/path/to/whatever.xxx"; $mm_type="application/octet-stream"; header("Cache-Control: public, must-revalidate"); header("Pragma: hack"); header("Content-Type: " . $mm_type); header("Content-Length: " .(string)(filesize($myFile)) ); header('Content-Disposition: attachment; filename="'.$filename.'"'); header("Content-Transfer-Encoding: binary\n"); readfile($myFile); ?>
-
Try this: <?php class Timing { private $store; public function __construct($name = 'default') { $this->store[$name]['start'] = explode(' ', microtime()); } public function stop($name = 'default') { $this->store[$name]['stop'] = explode(' ', microtime()); } public function getTime($name = 'default') { if(!isset($this->store[$name]['stop'])) { $this->stop($name); } $seconds = $this->store[$name]['stop'][1] - $this->store[$name]['start'][1]; $micros = $this->store[$name]['stop'][0] - $this->store[$name]['start'][0]; return $seconds + $micros; } } ?> Usage: <?php $timer = new Timer(); ## Whatever..... echo $timer->getTime(); ?> You need to include the class, and then initialise the timer in your bootstrap/setup file.
-
You sure? You shouldn't wee that if the headers are correctly set, do you have a link?
-
You need to output the correct headers to the browser telling it that your content is a file not a page. Try Googling the issue and I'm sure you will find a solution for your file types.
-
http://nz.php.net/manual/en/function.imagecopyresampled.php This is a far better function - I never use imageCopyRezised for just this reason. Resampling does take more memory though...
-
You need to use the full data in your functions - i.e. pull a bit more from your database. E.g. <?php $time = '14:26:13'; $date = '2008-09-01'; $timezone = 'GMT'; $new_time = strtotime($date.' '.$time.' '.$timezone); ?> Or better, you should store date and time together (datetime) and then pull them from the database using "SELECT UNIX_TIMESTAMP(`datetime_field`) WHERE ...."
-
Means that you haven't defined the function bottom. You need to include your functions file.
-
How to open excel sheet in browser using php
blinky001 replied to garrisonian14's topic in PHP Coding Help
There are lots of php classes to do this, from Google you could try this one: http://www.phpclasses.org/browse/package/3797.html - returns the data as a php array. Enjoy -
Really odd: I get The largest number in the file is: 1010
-
I think you can do this with JS helpers (try Mootools extensions), but the more common way to do this is with a Flash program. I'm sure the one I used once was called fupload, but I can't find it now...
-
forget php (although it is possible and I have written classes for this before) and look to perl. Search CPAN for Mechanize and tokeparser. They are the packages that you need to get going. If you are a m$ user you will likely need cygwin or something to run perl. Please don't build a spambot with these tools...