PHP - Class Not Found Issue
I am using a PHP class for a web app that works perfectly well when developing on local machine (PHP 5.2) using the NuSphere IDE. NuSphere sees the class, and when I run the app locally everything seems to work, but when i port the app to the host (Linux Ubuntu with Apache2, PHP 5.3, MySQL 5.1 ), the class is not found (using the remote host debugger).
The exact mesage is: Class 'ExcelXML' not found at <line of code>. Here is the code snippet: Code: [Select] <?php function setExcelData($sql, $title, $fileName, $idref=0) { $retVal=false; //$fileName=$fileName.'.xml'; $fileName=$fileName.'.xls'; include ('ExcelXML.inc.php'); include_once $_SERVER['DOCUMENT_ROOT'].'/truck/inc/db.inc.php'; $input = ($idref==0?"blank1.xml":"blank.xml"); // create ExcelXML object $xml = new ExcelXML(); // read template file if (!$xml->read($input)) { echo "Failed to open Tempalate Excel XML file<br>"; } ... ?> Here is the class Code: [Select] <?php /** * Class ExcelXML * Provide functions to modify the content of file in Excel's XML format. * * REQUIRED: * - An ExcelXML file as template * * FEATURES: * - read, modify, and save Excel's XML file * - create download stream as Excel file format (*.xls) * * CHANGELOG: * 06-08-2008 * - Update setCellValue function * - Fix setCellValue bug * 13-07-2008 * - First created * * * @author Herry Ramli (herry13@gmail.com) * @license GPL * @version 0.1.1 * @copyright August 06, 2008 */ class ExcelXML { var $domXML; var $activeWorksheet; function ExcelXML() { } ... ?> The class is in the same folder location as the calling php file. Any ideas? I don't get it. Similar TutorialsHi This is a strange one, and I'm not sure whats going on here. I've tried googling the answer to no avail. Basically, I'm writing a Wordpress plugin, and here's my setup: install.php has a class called 'two_install' The main plugin file code snippet: Code: [Select] // Installation require(plugin_basename('installer.php')); // Initiate installation class $twp_install = new twp_install; This results in this on activation: Fatal error: Class 'twp_install' not found in path-on-server\wp-content\plugins\twitter_parser\twitter_parser.php on line xx Anyone got any ideas? Just a note, there is definitely a class called 'twp_install' in installer.php! Thanks in advance Hello, I am trying to implement a simple script that ZIPs up a text file. The problem is that I don't think the ZIPArchive is available on my server. Here is an example of my code: Code: [Select] <?php $zip = new ZipArchive(); $filename = "./PJR.v2.zip"; if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) { exit("cannot open <$filename>\n"); } if ($handle = opendir('WORKDIR')) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { $zip->addFile($entry); } } closedir($handle); } $zip->close(); ?> When I run it from the command line, I get Code: [Select] PHP Fatal error: Class 'ZipArchive' not found in /users/albert/zip_POC.v2.php on line 2 This is the version info on my server: Code: [Select] php -v PHP 5.1.6 (cli) (built: Nov 12 2008 11:22:53) Copyright (c) 1997-2006 The PHP Group Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies Is there a way that I can install that class even though I am not the 'root' user?? So I'm trying to mess around with the HttpRequest class and it can't be found. I looked it up and it said I have to enable the extension in the php.ini file but I couldn't find the php_http.dll extension that the website said I should be able to find and un-semicolon. What exactly is a PHP HttpRequest? It seems like a few languages have this functionality. What is possible with the PHP HttpRequest, do I need other languages to get, send or display data through HttpRequest? Thanks for any help. Hi guys, I am trying to calculate hours a person works by calculating the values of text fields in a form. However, when I load the page I get "Class 'times_counter' not found. Here is the calculation code" if(isset($_POST['calculate']) != ""){ class times_counter { private $hou = 0; private $min = 0; private $sec = 0; private $totaltime = '00:00:00'; public function __construct($times){ if(is_array($times)){ $length = sizeof($times); for($x=0; $x <= $length; $x++){ $split = explode(":", @$times[$x]); $this->hou += @$split[0]; $this->min += @$split[1]; $this->sec += @$split[2]; } $seconds = $this->sec % 60; $minutes = $this->sec / 60; $minutes = (integer)$minutes; $minutes += $this->min; $hours = $minutes / 60; $minutes = $minutes % 60; $hours = (integer)$hours; $hours += $this->hou % 24; $this->totaltime = $hours.":".$minutes; } } public function get_total_time(){ return $this->totaltime; } } $times = array( $mondiff->format('%H:%I'), $tudiff->format('%H:%I'), $weddiff->format('%H:%I'), $thdiff->format('%H:%I'), $fridiff->format('%H:%I'), $satdiff->format('%H:%I'), $sundiff->format('%H:%I'), ); $counter = new times_counter($times); I had this on an old project, which I no longer have but it worked then. Any ideas? Hi all.
Just seeing this error now.
funny enough the site have been live for about a week only to bring this error now!
Fatal error: Class 'PDO' not found in /home/mysite/public_html/includes/file.php on line 21
and this is the file.php
$database='mydb'; $user='username'; $password='password'; $dsn="mysql:host=localhost;dbname=$database"; try { $pdo = new PDO($dsn,$user,$password); // mysql } catch(PDOException $e) { die ('Failed to connect'); // Exit, displaying an error message }i just saw this today and it's on godaddy thanks hello, i am hoping someone can help, been working on my own mvc with help from tutorials, but i am stuck with this error: Fatal error: Class 'services' not found in C:\xampp\htdocs\Workspace\Cyberglide\libs\Bootstrap.php on line 27 were it says services that changes when i type a different item in the url, loads the error page but says that at the bottom of the page. hoping someone can help me where i gone wrong: Code: [Select] <?php class Bootstrap { function __construct() { $url = isset($_GET['url']) ? $_GET['url'] : null; $url = rtrim($url, '/'); $url = explode('/', $url); //print_r($url); if (empty($url[0])) { require 'controllers/index.php'; $controller = new Index(); $controller->index(); return false; } $file = 'controllers/' . $url[0] . '.php'; if (file_exists($file)) { require $file; } else { $this->error(); } $controller = new $url[0]; $controller->loadModel($url[0]); // calling methods if (isset($url[2])) { if (method_exists($controller, $url[1])) { $controller->{$url[1]}($url[2]); } else { $this->error(); } } else { if (isset($url[1])) { if (method_exists($controller, $url[1])) { $controller->{$url[1]}(); } else { $this->error(); } } else { $controller->index(); } } } function error() { require 'controllers/error.php'; $controller = new Error(); $controller->index(); return false; } hope someone can help, many thanks guys. This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=315284.0 I closed everything down last night and it was all fine, website was working as normal etc, but I've turned on the Xxamp server today and I am getting this error. Seems very random as nothing has changed since it was last on? Does anyone know how to sort this out and why I'm now getting this error? Thanks! would anyone know how to assign the value (value returned by some function in the class) of variable $temp in the class: source looks like: class newRecord{ var $temp = listCat('gallery_menu', 'submenu', 'submenu_id'); ////// this line is not working, does not assign? function listCat($table, $submenu, $submenu_id) { $return = '<select name="'.$submenu_id.'" id="'.$submenu_id.'">'; $result = mysql_query("SELECT * FROM $table"); while($row=mysql_fetch_object($result)) { $return = $return.'<option value="'.$row->id.'">'.$row->$submenu.'</option>'; } $return = $return.'</select>'; return $return; } } if function is used out of the class and used in index.php directly, returns expected value of it (there is no doubts - works ok) I have a basic pagination class, I have used on several pages of a site I am working on. It works fine on 3 of the pages, but when I try to use it on any other pages, or even a new blank page I wrote, it does not work. class Pagination { public $current_page; public $per_page; public $total_count; public function __construct($page=1, $per_page=20, $total_count=0) { $this->current_page = (int)$page; $this->per_page = (int)$per_page; $this->total_count = (int)$total_count; } public function offset(){ return ($this->current_page - 1) * $this->per_page; } public function total_pages(){ return ceil($this->total_count/$this->per_page); } public function previous_page(){ return $this->current_page - 1; } public function next_page(){ return $this->current_page + 1; } public function has_prev_page(){ return $this->previous_page() >= 1 ? true : false; } public function has_next_page(){ return $this->next_page() <= $this->total_pages() ? true : false; } That is the pagination class, and this is the code I use to call it, along with some debugging information I am using. if(isset($_GET['order'])){ $order = $_GET['order']; } else { $order = "id"; } if(isset($_GET['orderby'])){ $order_by = $_GET['orderby']; } else { $order_by = "ASC"; } $page = !empty($_GET['page']) ? (int)$_GET['page'] : 1; $per_page = 2; $sql = mysql_query("SELECT * FROM orders WHERE customerid = 4"); $result = mysql_fetch_array($sql); $total_count = mysql_num_rows($sql); //$total_count = Order::count_by_cust(4); $pagination = new Pagination($page, $per_page, $total_count); $sql = "SELECT * FROM orders WHERE customerid = 4 ORDER BY {$order} {$order_by} "; $sql .= "LIMIT {$per_page} "; $sql .= "OFFSET {$pagination->offset()}"; $orders = Order::find_by_sql($sql); echo "Page:" . $page . "<br />PerPage:" . $per_page . "<br />Total:" . $total_count . "<br />Total Pages:" . $pagination->total_pages(); ?> SOME FOREACH INFORMATION HERE <?php echo "Has Prev Page:" . $pagination->has_prev_page() . "<br />"; echo "Total Pages:" . $pagination->total_pages() . "<br />"; echo "Has Next Page:" . $pagination->has_next_page() . "<br />"; ?> <div id="pagination" style="clear: both; text-align: center;"> <?php if ($pagination->total_pages() > 1){ if ($pagination->has_prev_page() == 1){ echo "<a href=\"orders.php?search&uid={$order->customerid}&order={$order}&orderby={$order_by}&page="; echo $pagination->previous_page(); echo "\">« Previous</a>"; } for($i=1; $i<=$pagination->total_pages(); $i++){ if($i == $page){ echo " <span class=\"selected\">{$i}</span> "; } else { echo " <a href=\"orders.php?search&uid={$order->customerid}&order={$order}&orderby={$order_by}&page={$i}\">{$i}</a> "; } } if ($pagination->has_next_page() == 1){ echo "<a href=\"orders.php?search&uid=" . $order->customerid . "&order=" . $order . "&orderby=" . $order_by . "&page="; echo $pagination->next_page(); echo "\">Next »</a>"; } } ?> </div> The customer ID is dynamic, but for debugging sake I am using the customer ID of 4. The output of the page has the following informaton: Page:1 PerPage:2 Total:15 Total Pages:8 Has Prev Page: Total Pages:8 Has Next Page:1 So i know all the variables are right, the problem is, it only prints a bold "1". Thats all, no numbers, or Next Page option. However i use the EXACT same code in another couple pages, and it works fine, but with this current page and a few others. It does not work. I have also tryed extracting just this information into a blank file to just get the page numbers, taking out all the pages other code, and it still only gives me "1". Any ideas? I have an issue that with some testing on an Access class with a method getControlAccess it should only return true or false but as soon as I place a string of any sort into the return my tests always returns true. Any help to point out if it is the way I am testing or the way I have written the method would be great. In the example below it would return true. In one class I have this method Code: [Select] class Access{ public function getControlAccess(){ return 'I am stuffed'; } } In the second class I have this Code: [Select] class AccessTests extends Access{ public function controlAccessTest(){ $return = "<ul>"; if ($this->getControlAccess() == TRUE){ $return .= "<li>getControlAcess should be true and is returning:<b> ". $this->getControlAccess() ."</b></li>"; } elseif ($this->getControlAccess() == FALSE){ $return .= "<li>getControlAcess should be false and is returning:<b> ". $this->getControlAccess() ."<b></li>"; } else { $return .= "<li>getControlAcess is really stuffed:<b>". $this->getControlAccess() ."<b></li>"; } $return .= "</ul>"; return $return; } public function setAccessTest($set){ return $set; } } I am doing some practice with classes. MY class below echoes out input and radio fields based on the instantiation of the Form class (the code below is working!), but I am trying to resolve how to get my form radio fields so they are not in between every other form field as they are supposed to be next to eachother. If you run the below, you will see what I mean. And also is my approach at all sensible? I am only doing this for learning experience, so any advice please. <?php class Form { private $fields = array(); private $radios = array(); private $actionValue; private $submit = "Submit Form"; private $Nradios = 0; private $Nfields = 0; function __construct($actionValue, $submit) { $this->actionValue = $actionValue; $this->submit = $submit; } function displayForm() { echo "<form action='{$this->actionValue}' method='post'>\n\n"; for ($j = 1, $i = 1; $j <= sizeof($this->fields), $i <= sizeof($this->radios); $j++, $i++) { echo "<p>\n<label>{$this->fields[$j-1]['label']} : </label>\n"; echo "<input type='text' name='{$this->fields[$j-1]['name']}'>\n</p>\n\n"; echo "<p>\n<label>{$this->radios[$i-1]['rlabel']} : </label>\n"; echo "\n<input type='radio' name='{$this->radios[$i-1]['rname']}' value='{$this->radios[$i-1]['rvalue']}'>\n</p>\n\n"; } echo "\n\n<input type='submit' value='{$this->submit}'>\n</form>"; } function addField($name, $label) { $this->fields[$this->Nfields]['name'] = $name; $this->fields[$this->Nfields]['label'] = $label; $this->Nfields = $this->Nfields + 1; } function addRadio($rname, $rvalue, $rlabel) { $this->radios[$this->Nradios]['rname'] = $rname; $this->radios[$this->Nradios]['rvalue'] = $rvalue; $this->radios[$this->Nradios]['rlabel'] = $rlabel; $this->Nradios = $this->Nradios + 1; } } ?> <?php $contact_form = new Form("process.php", "Submit Data >>"); $contact_form->addField("first_name", "First Name"); $contact_form->addField("last_name", "Last Name"); $contact_form->addRadio("gender", "male", "Male"); $contact_form->addRadio("gender", "femail", "Female"); $contact_form->displayForm(); ?> Hi Still very new to PHP but getting some good use out of it with includes. I'm currently using this code to check the file name of the page and then give the corresponding anchor tag a class of active in order to style my main menu. This is all working for most of my pages but my problem is that I now have multiple files called index.php one in the root of my site and some are in folders. Is there any way around this issue? Can PHP check to see if its the index file in the root of the site or is there a better way. I suppose I could create a second variable in the index file in my root ie my home page and then check to say if the current page is called index and has the variable of home but how would I write this? My code Code: [Select] $currentPage = basename($_SERVER['SCRIPT_NAME'], '.php'); <li><a href="/" <?php if ($currentPage == 'index') {echo 'class="active"';} ?>>Home</a></li> I have mysqli object in Database class base: [color=]database class:[/color] class Database { private $dbLink = null; public function __construct() { if (is_null($this->dbLink)) { // load db information to connect $init_array = parse_ini_file("../init.ini.inc", true); $this->dbLink = new mysqli($init_array['database']['host'], $init_array['database']['usr'], $init_array['database']['pwd'], $init_array['database']['db']); if (mysqli_connect_errno()) { $this->dbLink = null; } } } public function __destruct() { $this->dbLink->close(); } } Class derived is Articles where I use object dBLink in base (or parent) class and I can't access to mysqli methods (dbLink member of base class): Articles class: require_once ('./includes/db.inc'); class Articles extends Database{ private $id, .... .... $visible = null; public function __construct() { // Set date as 2009-07-08 07:35:00 $this->lastUpdDate = date('Y-m-d H:i:s'); $this->creationDate = date('Y-m-d H:i:s'); } // Setter .... .... // Getter .... .... public function getArticlesByPosition($numArticles) { if ($result = $this->dbLink->query('SELECT * FROM articles ORDER BY position LIMIT '.$numArticles)) { $i = 0; while ($ret = $result->fetch_array(MYSQLI_ASSOC)) { $arts[$i] = $ret; } $result->close(); return $arts; } } } In my front page php I use article class: include_once('./includes/articles.inc'); $articlesObj = new articles(); $articles = $articlesObj->getArticlesByPosition(1); var_dump($articles); [color=]Error that go out is follow[/color] Notice: Undefined property: Articles::$dbLink in articles.inc on line 89 Fatal error: Call to a member function query() on a non-object in articles.inc on line 89 If I remove constructor on derived class Articles result don't change Please help me I have an existing instance of my class Database, now I want to call that instance in my Session class, how would I go about doing this? Hi Can you call Class A's methods or properties from Class B's methods? Thanks. Ok. I know you can pass the object of a class as an argument. Example: class A { function test() { echo "This is TEST from class A"; } } class B { function __construct( $obj ) { $this->a = $obj; } function test() { $this->a->test(); } } Then you could do: $a = new A(); $b = new B($a); Ok so that's one way i know of. I also thought that you could make a method static, and do this: (assuming class A's test is 'static') class B { function test() { A::test(); } } But that is not working. I'd like to know all possible ways of accomplishing this. Any hints are appreciated. thanks If a class has a constructor but also has a static method, if I call the static method does the constructor run so that I can use an output from the constructor in my static method? --Kenoli I am making login system using codeigniter. When I run my code i get this error. Code: [Select] The requested URL /ci_login/user/login was not found on this server. here is my code so far user.php file which is in controller folder Code: [Select] <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class User extends CI_Controller { function __construct() { parent::__construct(); } function index() { } function login() { if($this->form_validation->run() == FALSE) { $this->load->view('view_login'); } else { echo "Successfull"; } } } view_login.php file which is in view folder Code: [Select] <html> <head> <title>Login</title> </head> <body> <h1>Please Login!</h1> <p>Use the login form below to login.</p> <div id="login_form"> <?php echo form_open(base_url(). 'user/login' ) ?> <label>Username:</label> <div> <?php echo form_input(array('id' => 'username', 'name' => 'username')); ?> </div> <label>Password:</label> <div> <?php echo form_password(array('id' => 'password', 'name' => 'password')); ?> </div> <div> <?php echo form_submit(array('name' => 'submit'),'Login'); ?> </div> <?php echo form_close(); ?> </div> </body> </html> help please how can I solve this error? I'm trying to show my friend my website and it's not letting him or me view it. I am using my own IP-address. (dashed out for security, but it is correct) http://--.---.--.---/index-1.php When he and I type this into our browser, we can an error called "Resource Not Found". But, when I use localhost address, it works fine. http://localhost/index-1.php Does anyone know what is wrong? Do I need to open a specific port? USING XAMPP. |