Jump to content

Sasuun

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Sasuun's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I'm having problems with my classes inheriting methods and functions. In the past I've used a different method of accessing all of my classes within each other by making pointers to a class wrapping around all of my other classes so they interact with each other nicely. I did something like this $Class = new Class; $Class->someclass = new someclass; $Class->someclass->class = &$class; This time, I thought I'd try using inheritance for my controllers, so I could access all of my classes by wrapping them inside of an App_Base class class someController extends App_Base { someAction() { $this->inheritedClass->inheritedMethod() } } but my class isn't inheriting properly, Instead it only gets the values of variables at initiation of the original class, so my $requestPath, for example which is populated after initialization remains the same. Am I doing something wrong, or is that just how inheritance works. I've included my dispatch function if it helps anyone, but I suspect the answer does not require reading it function dispatch( $routes = null ) { //////////////////////////////////////////////////// // do we have route rules present? //////////////////////////////////////////////////// define( 'USE_ROUTES', ( $routes != null) ? true:false ); $controller = strtolower( $this->getController( )); if ( $controller == "" ) { $controller = $this->config->defaultController; $action = strtolower( $this->getAction( 0 )); define('IS_DEFAULT_CONTROLLER', true); } else { $action = strtolower( $this->getAction( )); define('IS_DEFAULT_CONTROLLER', false); } if ( $action == "" ) { $action = 'index'; } if ( USE_ROUTES ) { //////////////////////////////////////////////////// // Routes... check to see if the specified controller has a route... //////////////////////////////////////////////////// if ( array_key_exists( $controller, $routes )) { $action = $routes[ $controller ][ 'action' ]; $controller = $routes[ $controller ][ 'controller' ]; #reset our information to fit the route, set the action first or our controller will be overwriten with the new one } } //////////////////////////////////////////////////// // check to see if the controller is present in the CONTROLLER_ROOT //////////////////////////////////////////////////// if ( file_exists( CONTROLLER_ROOT . $controller . "Controller.php" )) { require_once CONTROLLER_ROOT . $controller . "Controller.php"; $controllerName = $controller . "Controller"; $action = $action . "Action"; if ( class_exists( $controllerName )) { $Controller = new $controllerName; //check for everything and execute, if there is a problem, we throw an exception if ( method_exists( $Controller, $action )) { $Controller->$action( ); } else { if ( method_exists( $Controller, 'indexAction' )) { $Controller->indexAction(); } else { $this->throwError( 'No index action defined' ); } } } else { $this->throwError( $controllerName . " does not exist in " . $controllerName . ".php" ); } } else { $this->throwError( $controller . "Controller does not exist" ); } }
  2. maybe using something like imagecolortransparent() would help preserve it
  3. Does anyone know of a way to display a preview for a psd using PHP, maybe the GD library. photoshop generates previews as part of the file, so does anyone have an idea of how to retrieve it?
  4. I'm getting the following error whenever I try to execute a query using my db class. [code]No Database Selected pwned[/code] I have no idea why this is happening because I know for a fact a database is being selected and I've tried seeing if there were any connection errors, but nothing worked. I'm hoping someone else's input can help me solve this problem [b]db_mysql.php[/b][code] class db_mysql { public $connection = ''; protected $db = ''; public $query_id = ''; public $cur_query  = ''; public $error = ''; public $query_count = '0'; public $row = ''; function __construct() { global $INFO; //------------------------------------------------ // do we want to make a persistant db connection //------------------------------------------------ $this->connection = mysql_connect($host,$user,$pass); mysql_select_db($db,$this->connection); //------------------------------------------------ // setup our sql prefix //------------------------------------------------ if ( ! defined( 'SQL_PREFIX' )) { define ( 'SQL_PREFIX', $INFO['dbprefix']); } } public function dbconnect($host,$user,$pass,$db) { $this->connection = mysql_connect($host,$user,$pass); mysql_select_db($db,$this->connection); } public function do_query( $query = '') { if ($query == '') { $query = $this->cur_query; } if ( SQL_PREFIX != "xms_" ) { $query = preg_replace("/\sxms_(\S+?)([\s\.,]|$)/", " ".SQL_PREFIX."\\1\\2", $query); } $this->query_id = mysql_query($query) or die(mysql_error() . "<br />pwned"); echo $this->query_id; $this->query_count++; } public function fetch_row( $ci = '') { if ( $ci == '') { $ci = $this->query_id; } $this->row = mysql_fetch_array( $ci ); return $this->row; $this->row = ''; } public function simple_construct( $q ) { if ( $q['SELECT'] ) { $this->construct_select( $q['SELECT'], $q['FROM'], &$q['WHERE'] ); } elseif ( $q['UPDATE']) { $this->construct_update( $q['UPDATE'], $q['SET'], &$q['WHERE'] ); } elseif ( $q['DELETE']) { $this->construct_delete( $q['DELETE'], $q['WHERE'] ); } elseif ( $q['INSERT']) { $this->construct_insert( $q['INSERT'],  $q['FIELDS'], $q['VALUES']); } if ( @$q['ORDER'] ) { $this->construct_order( &$q['ORDER'] ); } if ( $q['LIMIT']) { $this->construct_limit( &$q['LIMIT']); } if ( !$q) { $this->cur_query = ''; } if ($this->cur_query != '') { $this->do_query(); $this->cur_query = ''; } } public function construct_insert( $insert, $fields, $values ) { $this->cur_query = "INSERT INTO $insert ($fields) VALUES($values)"; } public function construct_select( $select, $from, $where = "" ) { $this->cur_query = "SELECT " . $select . " FROM " . SQL_PREFIX . $from; if ($where != "") { $this->cur_query .= "WHERE " . $where; } } public function construct_update( $update, $set, $where) { $this->cur_query = "UPDATE " . SQL_PREFIX . $update . "SET " . $set; if ( $where ) { $this->cur_query .= "WHERE " . $where; } } public function construct_delete( $delete, $where) { $this->cur_query = "DELETE FROM " . SQL_PREFIX . $delete; if ( $where ) { $this->cur_query .= "WHERE $where"; } } public function construct_order( $order ) { $this->cur_query .= "ORDER BY $order"; } public function construct_limit( $limit ) { $this->cur_query .= " LIMIT $limit"; } public function num_rows( $ci = '' ) { if ( $ci = '' ) { $ci = $this->query_id; } return mysql_num_rows( $ci ); } public function get_query_count() { return $this->query_count; } }[/code]
  5. [quote author=Prismatic link=topic=100131.msg394855#msg394855 date=1152583303] You creating the object before attempting to use it? [code] <?php $core = new ClassName; ?> [/code] Now you would be able to call your methods [/quote] hm... I'm doing that, it seems I'll have to find my test code to show you guys what I mean
  6. Hey, I'm try to create a series of classes for my website where each function is seperated into it's own class group, and I can call them into each other easily. For example, my user class will contain functions for checking all kinds of user stuff from a mysql database, which I would like to access via my mysql class. Basically what I'm trying to do is tohave one base class to contain all of my other classes, so lets call my base class $core, I would like to have my user class be $core->user->function_to_execute, and I would like to, within my classes be able to go $this->{classname}->{function}. I've seen this done in many scripts, like ipb and phpbb, but I can't figure out how to avoid that anoying fatal error: called member function from a non member object. thanks in advance
  7. I don't think $$ means anything, or that it would really matter if it did. all a variable does is store data, if there is a variable defined with $$ it would function the same as one defined with only one $ most likely, however, while $john is the var john, $$variable is the variable $variable.
  8. insert statements can be a real pain... my guess is mysql wants you to do something with how your values are stated, I would start by adding '' around all of the varues in the VALUES() part of your query. try this [code] $sql_item = "INSERT INTO Order_Item (orderID, quantity,price) VALUES ('$orderID', '$value','{$row['price']}')"; $result = mysql_query($sql_item,$connect) or die("sql_item: ".mysql_error($connect));[/code] I know it doesn't seem like much of a change, but it's worked for me before
  9. perhaps you could use the function is_numeric()?
  10. I'm using eval to execute php I have stored in a mysql database for a blocks system, but in order to aviod any problems using function such as header() or session_start() after output has been sent, I store all of my output in a variable $OUTPUT and on the last line of my script echo that var. This was all going fine until I added a php filter to my block system, which worked great, except my output would always be printed above everything else on my site, so I went to php.net and read up on the eval() function, and lo and behold I finally realized they had a tip for using eval [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Tip: As with anything that outputs its result directly to the browser, you can use the output-control functions to capture the output of this function, and save it in a string (for example).[/quote] I have no idea how to use output-control functions, and I've been reading about them searching for a couple of hours with no luck Does anyone know how I could capture the output and put it in my $OUTPUT var? incase it helps, here is my get_blocks function [code]function get_blocks($position)     {         $ACHTML = '';         #initialize variable and make sure it doesn't have any data in it         $sql = "SELECT * FROM ac_blocks WHERE `position` = '$position' ORDER BY `order` ASC";         $get = mysql_query($sql)                 or die(mysql_error());                 while ($blocks = mysql_fetch_array($get))                 {                     if ($position == "C")                     {                         $ACHTML .= site_box($blocks['block_title']);                     }else                     {                         $ACHTML .= make_menu($blocks['block_title']);                     }                     if ($blocks['filter_method'] == 0)#bbcode                     {                         $ACHTML .= $this->bbcode2html($blocks['content'],'1');                     }                     elseif ($blocks['filter_method'] == 1)#we're parsing raw php                     {                                                      $ACHTML .= eval($blocks['content']);                                              }else                     {                         $ACHTML .= "block error";                     }                     $ACHTML .= close_menu();                 }             return  $ACHTML;     }[/code]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.