Jump to content

ballhogjoni

Members
  • Posts

    1,026
  • Joined

  • Last visited

Everything posted by ballhogjoni

  1. I didn't right this code but I can't figure out why the $db var isn't available in the DBPersister() constructor and in the functionName(). $s = new somePersister(); print_r($s->functionName(123)); class somePersister extends DBPersister { public function functionName($id) { ... do stuff ... print_r($this->db); //DOES NOT print DB instance } } <?php include_once('db.inc.php'); print_r($db); //prints the DB instance class DBPersister { var $db; function DBPersister() { global $db; print_r($db); //DOES NOT print the DB instance $this->db =& $db; } } db.inc.php class DB extends _Database_ { var $host; var $dbname; var $user; var $password; var $result; var $record; var $connected; function DB() { $this->_Database_(); $this->host = DATABASE_HOST; $this->dbname = DATABASE_NAME; $this->user = DATABASE_USERNAME; $this->password = DATABASE_PASSWORD; } } $db = new DB();
  2. Sorry i didn't post much, but your comment was all I needed. I realized that the ShippingManager function was calling MarketplaceWebServiceOrders_Client() from a different location. I just altered my include path to this: set_include_path(get_include_path() . PATH_SEPARATOR . 'orders' . PATH_SEPARATOR . '../orders' . PATH_SEPARATOR . 'feeds' . PATH_SEPARATOR . '../feeds' . PATH_SEPARATOR . '../lib');
  3. I running a script which autoloads ShippingManager. An instance of ShippingManager calls a function that should create a new instance of another class that is located in the orders folder. I am getting Fatal error: Class 'MarketplaceWebServiceOrders_Client' not found. How do I fix this? autoload code: set_include_path(get_include_path() . PATH_SEPARATOR . 'orders' . PATH_SEPARATOR . 'feeds' . PATH_SEPARATOR . '../lib'); function __autoload($className) { $filePath = str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; $includePaths = explode(PATH_SEPARATOR, get_include_path()); foreach ($includePaths as $includePath) { if (file_exists($includePath . DIRECTORY_SEPARATOR . $filePath)) { require_once $filePath; return; } } } handle_shipping.php <?php include_once ('path/to/config.php'); $shipping_manager = new ShippingManager("ESHIP-" . date('Ym23') . ".txt"); if ($shipping_manager->getShippingFileFromFTP(URL, USER, PASS)) { $shipping_manager->createShippingCSVFile(); } ShippingManager function that is called from the createShippingCSVFile function. The class MarketplaceWebServiceOrders_Client isn't being autoloaded. private function __getOrderItemId() { $service = new MarketplaceWebServiceOrders_Client(); $orderItems = new MarketplaceWebServiceOrders_Model_ListOrderItemsRequest(); $orderItemList = $orderItems->getOrderItem(); foreach ($orderItemList as $orderItem) { print_r($orderItem->getOrderItemId()); } }
  4. Awesome thanks for that info. This is how I am fixing the issue. Let me know if this is the best way to remove control characters: str_replace(range("\x00","\x1F"), "", $str)
  5. So I am receiving order information from Amazon.com and writing it to a file to send to my supplier to fulfill the order but some orders have these ^ and @ characters in the address. I've checked the data in Amazon and the order doesn't include the ^ and @ characters. What could my code be doing to add these characters? This is a semicolon delimited file row: 002-8228257;10;^@william lastname^@;^@123 TEST RD^@;^@THE CITY^@;OHIO;12345;8017055555;Y;email@email.com I create a $data array and loop through the orders adding each row into the array. I then use fputcsv to write the rows to the file foreach ($orders as $order) { $data[] = array( $order["amazon_order_id"], "10", $order[0]["ship_to_name"], $order[0]["ship_to_addr_one"], $order[0]["city"], $state, $order[0]["zip"], str_replace('-', '', $order[0]["phone"]), "Y", "email@email.com" ); } foreach ($data as $row) fputcsv($handle, $row, ";", chr(0));
  6. Is there a strict type for decimal? I've done it with int and float. php > $a = (int)1.2; php > echo $a; 1 php > $a = (decimal)1.2; PHP Parse error: parse error in php shell code on line 1 php > $a = (float)1.2; php > echo $a; 1.2
  7. Using fopen how do I set the file pointer to end of file when opening a file?
  8. Im trying to loop through a 145mb csv file but I keep getting Fatal error: Allowed memory size of xxxxxxxxxx bytes exhausted (tried to allocate 71 bytes) I've tried setting the memory limit to 512m, 1024m, 2048m while (($data = fgetcsv($handle, 0, ",")) !== FALSE) { if (in_array($data[0], array( 1, 4, 6, 40, 50, 136, 451, 933, 1529, 2006, 2155, 2271, 2603, 2640, 3173, 3619, 3789, 4479 ))) { continue; } $in_data[] = $data; } Whats the best way to do this? What am I not understanding here? Any examples would help.
  9. You are macgyver! Awesome thanks, this is what I need!
  10. Is there a php class to update a csv file? I'm not very well versed with fputcsv, but looking at the documentation it doesn't seem to give me what I want. I see that I pass it the file handler and an array of data to write to the csv. I want to update one column of data at a time not an entire row. I'm stuck on where to go from here. In one csv I have a product sku that is located in column 9 and the other csv column 13. These columns are the identifying info I need to know I am looking at the same product on both csv's. The "In" csv is the origin which contains the inventory quantity. I need to transfer that quantity to the "out" csv. I figure the way to do this is by reading the origin line by line and placing the sku and the inventory in an array. I then loop through that array and read the "out" csv and search for a match. Once I find a match I need to update that products' inventory column from the origin csv. Makes sense? Any help would be helpful. This is the code I have so far, probably far off from what I need. <?php error_reporting(E_ALL); ini_set('display_errors', '1'); ini_set('auto_detect_line_endings', true); if (empty($_GET['in'])) die("Please pass file name to check inventory."); if (empty($_GET['out'])) die("Please pass file name to update inventory."); $in = $_GET['in'] . ".csv"; $out = $_GET['out'] . ".csv"; $h_in = fopen($in, "r"); if (!$h_in) die("$in can't be read."); $h_out = fopen($out, "r+"); if (!$h_out) die("$out can't be opened to read and write"); $rsr_inv = array(); $productskus = array(); $products = array(); $flag = true; while (false !== ($row = fgetcsv($h_out))) { if($flag) { $flag = false; continue; } $productskus[] = $row[13]; $products[] = $row; } while (false !== ($row = fgetcsv($h_in))) { $key = array_search($row[0], $productskus); if ($key) { $rsr_inv[] = array($productskus[$key], $row[8]); } } fclose($h_in); foreach($products as $key => $prod){ echo $inv[0] . ":" . $products[$key][13] . "<br>"; //if($inv[0] == $products[$key][13]){} } fclose($h_out);
  11. So all my routes work correctly right now except one. The one that doesn't work is a new action which causes a 404 but the page still displays what I want, or rather still renders the view. Thing is, when I try to post to the same action I get that 404 error and zend just redirects me to that action, which in turn sends a get request to the server losing what I post. FYI: the action shows a form on the get request and shows a thank you message on the post request. I just added a requestAction to the controller and all other actions work. I haven't added any new routes to the routing file. The other actions work fine. What am I missing?
  12. So I was just hired on at this company and the way they program is on a server using vi. Do you guys like this way of programming? We are using svn which seems to me to be old and outdated. Do you like Git or SVN? What are the pros and cons? For me I like to program locally on a local git clone of the dev branch then push my changes to the git dev branch.
  13. This is cool, been out of the php world for a while and into the ruby community. Just recently switched back to php, glad to see they have composer which is like a gemfile in ruby.
  14. So i have an .htaccess file that has this in it: SetEnv APPLICATION_ENV development RewriteEngine On RewriteRule ^/path/to/app/(.*)$ /path/to/app/public/$1 [NC,L] When I go to /path/to/app/ in the browser it displays the directory structure instead of redirecting the server to /path/to/app/public/$1 What am I doing wrong?
  15. I keep getting this error when I run this command: php-build -i development 5.4.2 ~/local/php/versions/5.4.2 1 warning generated. PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled. ----------------------------------------- [Warn]: Aborting build. Anybody know where to go from here?
  16. awesome thanks. that led me to Zend_Db_Table which is what i'm looking for. Also nice to hear about the Table Data Gateway that Zend_Db_Table uses.
  17. So I want to make CRUD easier. Right now we use the zend framework and the devs before me setup persisters with store (save) functions. The problem is that they hard coded the fields in the store functions. So when I add a field to the db I also have to go in and update the code with the new field. To me this is bad programming because you have things like activerecord. If ZF 1.12.3 doesn't use AR then what other alternatives do I have to clean this up a bit?
  18. Just trying to get others opinions on a subject I've thought about for a while. Lets say I have a csv full of 100k products I want to write all the products from the csv to mysql and then display that products to the end user. The main idea is to make the products easy and quickly accessible. I've thought about having a master slave solution where i'd write to the master and have the slave duplicate the master. So the reads would come from the slave. Anyway, what are your thoughts? Is this the best solution?
  19. ok fixed it ... i hate trying to figure out the problem for hours and then writing up a post and then fixing the problem a minute later. In my Sname_Autoloader::loadClass method I had the following code if (!file_exists($file)) return false; I didn't realize file_exists was returning null so the method was always returning false. I changed that code to if (file_exists($file) === null) return false; and it works perfect!
  20. This is so weird ... the class does exist. In my index.php I am calling this line of code and this is the line that is throwing the error: $router = new Sname_Router(); I am using a custom __autoload method and I am defining that function in index.php. Here it is function __autoload($class_name) { require_once APPLICATION_PATH . '/../libraries/Sname/Autoloader.php'; //Check to see if the class is in the app directory $loaded = Sname_Autoloader::loadClass($class_name, array(APPLICATION_PATH . "/controllers/", APPLICATION_PATH . "/models/", APPLICATION_PATH . "/helpers/")); //Check to see if the class is in the libraries if (!$loaded) $loaded = Sname_Autoloader::loadClass($class_name, APPLICATION_PATH . '/../libraries/'); //Check to see if the class is in active record if (!$loaded) { require_once APPLICATION_PATH . '/../libraries/activerecord/ActiveRecord.php'; activerecord_autoload($class_name); } //Check to see if the class is in the include path if (!$loaded) { Sname_Autoloader::loadClass($class_name, explode(PATH_SEPARATOR, get_include_path())); } } App directory structure sname-git - app -- controllers -- models -- helpers -- views -libraries --Sname ---Router.php --activerecord The Sname_Router class is located here /Users/myname/dev/git/sname-git/libraries/Sname/Router.php. I have checked to make sure that this is the correct location. This is the first few lines of my Router.php <?php class Sname_Router { ... What's going on? Any help would be much appreciated!
  21. so im trying to match the path of a url. example: /p/alsdjjlse My regex so far: ^\/([a-z])(?:\/(\w+))?$ this will match the following: /p/alsdjjlse /p but it won't match: /p/ I can't figure this out, any ideas? Thanks
  22. Ok thanks this is what I didn't want to do ... running php 5.3 ... looks like i don't have a choice unless i upgrade. Ok thanks! I will do this, easiest way to handle it. Don't want to have to keep making variables every time I want to access the array.
  23. i tried that and i get Fatal error: Uncaught exception 'ActiveRecord\UndefinedPropertyException' with message 'Undefined property: User->attributes in ...
×
×
  • 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.