Jump to content

CrimpJiggler

Members
  • Posts

    72
  • Joined

  • Last visited

CrimpJiggler's Achievements

Member

Member (2/5)

0

Reputation

  1. I read a security article a while ago that claimed it is dangerous to browse the web while you are logged into gmail, facebook, whatever because any website can get the profile ID of these accounts if you are logged into them. That sounds like bs to me, but the article seemed relatively legitimate so I'm wondering about this. Can you, with PHP or javascript get the profile ID of social media/whatever accounts a user is logged into?
  2. I just made this procedure which will do for now: DELIMITER $$ CREATE PROCEDURE rearrangeNodes(IN parentId INT) BEGIN DECLARE parentLft INTEGER; SET parentLft = (SELECT lft FROM table WHERE category_id = NEW.parentId); UPDATE `table` SET lft = CASE WHEN lft > parentLft THEN lft + 2 ELSE lft + 0 END, rght = CASE WHEN rght >= parentLft THEN rght + 2 ELSE rght + 0 END WHERE lft >= newLft; END$$
  3. I can't edit my post, I wanna ask a better question. Is there a simple way to make MySQL handle nested hierarchical database tables for you. My table has a parent_id, lft and rght value. CakePHP handles this automatically but does MySQL have built in functionality for that? If not, can anyone point me towards a simple stored procedure to do it? I know what I need to do, just find out whether the parent node is empty or not, if its empty then I expand it by 2, and shift everything to the left and right of it two. If its not empty, then I just shift everything from the start of the parent node to the right. There must be an automatic way to do it though.
  4. I'm using a CRUD system which won't automatically update the lft and rght values of my hierarchical tables when I enter a new row. I don't know what the best way to solve this is, all I can think of is adding a stored procedure to the table so that whenever a new row gets added, the procedure will make sure the lft and rght values get shifted. Is this even possible with stored procedures?
  5. I've played around with CakePHP, then XCrud (a decent CRUD application) but I gave up on both of them, XCrud was great for everything up until it came to managing complicated relational database tables. Anyhow, I'm using wordpress a lot now cuz it lets me stop reinventing the wheel so much and although I was able to integrate XCrud into WordPress as a plugin, I think the best way to go is just transfer my database tables to WordPress tables and display them as custom post types. My time is really limited right now though, is there a plugin/set of plugins I can use to automate the process? To show you what I mean, heres the XCrud list display of one of the tables: thats great because it automatically sets up the CRUD thing and lets you add and edit fields to the table, and doesn't heavily box you into their system but I have a table of plants, one for products, one for pharmacology, one for categories which are all related to each other, and some of them are structured in a tree/nested hierarchy structure so long story short, I need to do advanced searches based on these relations and handle these tree structured tables and CakePHP didn't work out, and XCrud has crappy documentation and isn't popular enough to find good info. So how would you go about transfering this system to WordPress? I'm guessing I need to make custom post types for each table but what I don't yet know is how to transfer the DB tables to WordPress format, how to handle the relationships between each table and how to handle the hierarchical tree structures.
  6. What you said about the difference, I get that. No need to create an instance of an globally if you only need to create it inside your class, but the method I mentioned above does the exact same thing. I never had to add __construct(ExtraObject $ExtraObject) to the constructor, and to instantiate my class and make sure it instantiates the second class, I never had to do $instance = new MyClass(new ExtraClass()); I just put $this->ExtraClass = new ExtraClass(); inside the constructor function itself. I hope theres something I'm missing here because I was hoping this __construct(Object $object); would let me do something new. Theres a problem I need to learn how to solve right now, I do a shitload of extending classes, I've been extending classes in chains and that can become a problem because sometimes the same class gets inherted twice. Another part of this problem is that only classes at the end of the chain have access to all methods, a class further up the chain can't access the class at the bottom because it hasn't extended it.
  7. Why would something in my website suddenly stop working when I haven't edited it in months. I have a website on a free server, which I recently upgraded to a premium account to host my other sites. When I went to that old site today, I get this error: Heres line 162: $array_cartesian = function() use (&$array_cartesian) { but in my experience errors like this are caused by something before the line with the unexpected code, heres the whole class: class colorCombos { public function __construct() { } static public function get_combos() { $colors = array('blue', 'red', 'green'); $array_cartesian = function() use (&$array_cartesian) { $args = func_get_args(); if(count($args) == 0) { return array(array()); } $a = array_shift($args); $c = call_user_func_array($array_cartesian, $args); $r = array(); foreach($a as $v) { foreach($c as $p) { $r[] = array_merge(array($v), $p); } } return $r; }; $combo = $array_cartesian($colors,$colors); $combo_array['code'] = $combo_array['display'] = array_filter( $combo, function (&$row) { return ($row[0] !== $row[1]); } ); $walk_call = function (&$row,$key) { $row = $row[0] . "-" . $row[1]; }; array_walk_recursive( $combo_array['display'], function(&$item,$key) { $item = ucwords($item); } ); array_walk($combo_array['code'],$walk_call); array_walk($combo_array['display'],$walk_call); return $combo_array; } } Its for generating a list of combinations of two objects, in this case colours, so it'll output an array of items like red-blue, blue-green, green-red etc. It was working fine before, I don't know if it was right after upgrading the account that it happened or not, all I know is I didn't do anything myself to cause the error. Could that empty constructor be the problem? I rarely ever use static methods, I used it here just to learn, do I need to make the constructor static too?
  8. Oh yeah sorry, thats what I meant. What I meant about Config, is it I have a class containing properties common to all my classes. I used extend my classes with that Config class. I just learned about traits, this is brilliant, thanks a lot. This will solve my issues with chains of extended classes.
  9. Brilliant explanations, nice one. So inheritence is what happens when I use "class1 extends class2" and inheretence means that every method and property from class2 becomes part of class one, kind of like if I have a function page and add include('functionspage2.php'). But this $__construct(Objectname $ObjectContainerVariable) thing is more like loading an instance of the Battery object into your Device objects instances. Is that it? I'm still a bit confused. The idea I have in mind, how I do it is like this: class Battery { } class Device { public __construct() { $this->battery = new Battery(); } } then that Battery instance is available to all my methods inside the Device class, and any classes that extent Device. Is this what you mean by me making Battery a subclass of Device, rather than Device having a Battery? An issue I have is lets say Device extends say my Config class, if I need to use the $battery instance inside my Config class I can't access it, I have to make a new instance. I've run into plenty issues like that so my method isn't very good, I'm hoping that this other method solves some of those issues for me. I haven't learned about traits yet but will ASAP, they sound interesting. Nice one for the terminology, but I'm still a bit confused about what inheritence and composition is. Is inheretence what happens when I extend one class with another? If so, then I get it. I see that like merging the two classes. Composition I'm guessing is where you add an instance object of a another class to your class so the second classes methods are contained in the $variable holding the instance.
  10. I've been spending long hours learning about classes and their magic methods. I just came across a tutorial which showed a constructor like this: class Device { //... public function __construct(Battery $battery, $name) { // $battery can only be a valid Battery object $this->battery = $battery; $this->name = $name; // connect to the network $this->connect(); } //... } the Battery part instantly caught my attention. Here had previously made a Battery class (and a more complete Device class) but the next thing he did really caught my interest: $device = new Device(new Battery(), 'iMagic'); // iMagic connected echo $device->name; // iMagic what the hell is going on here? Is this another way to include the methods and properties of one class into another class, in order words is this the same thing as: class Device extends Battery I don't think so because this new Battery() thing looks more like its creating an object inside the Device object. Previously the only way I could to that was to type $battery = new Battery() inside one of my methods. But this looks like hes doing something different. Can anyone explain whats going on here? The whole tutorial is here: http://code.tutsplus.com/tutorials/deciphering-magic-methods-in-php--net-13085 in the main Device method he has a premade $battery variable to hold the Battery object. Sometimes I have multiple classes containing functions which I'd like to include in my main class. I can only extend one class, so I usually extent a class containing only properties, no methods. I still don't know what difference making that info class abstract is, I'd appreciate if anyone could tell me. Also I'd love to know what the point in static methods is. I've never used them because I've never seen the point. Is it just to make it easier to call the methods because you don't need to create an object instance to call them? Sorry for the extra questions, the first one is what I'm really wondering about.
  11. Using CakePHP as an example, the steps I'm talking abot are enabling URL rewriting, chmod 777ing the app/tmp directory, including the plugins in bootstrap.php, setting up a new database + user for the site, enabling jquery etc. All these little things add up and become time consuming. NetBeans has a CakePHP plugin which installs the framework for you and lets you choose which javascript frameworks you wanna install with it and stuff like that, but its still not something that sets the whole thing up for you with the click of a button.
  12. I started learning how to use composer, I read about it numerous times in the past but didn't realise that this is what it does. Does it have built in functions to set the cipher + seed of a new CakePHP project, bootstrap the plugins for you, setup the database, add jquery to webroot/js + include it in layouts/default.ctp etc? I only started learning it recently so I don't know how to use it yet, but the little I do know is gonna make things a whole lot easier for me. An issue I've run into is I don't know how to make it download plugins that don't have composer.json files. To work around that can you just create your own composer.json file for the plugin, then plug it into composer? I'll look into phing, thanks. I'm guessing it would be easy to make a script that controls composer and bake to do the heavy lifting and framework part for you.
  13. I notice plenty of CakePHP plugins don't have composer.json files in their github repositories (I'm not sure where composer downloads from if you don't specify a repository, is it github?) so I can't automatically download and update them. For composer to recognise and download the plugins, all thats needed is the composer.js file itself isn't it? Why wouldn't plugin authors just spend an extra 10 minutes and make a composer.js file? I'm guessing theres something I'm missing here, it must not be that simple. I only started using composer so I don't really know what its about yet.
  14. I hear CakePHP 3.0 being talked about like its something for the future but I also see that you can download it and there are tutorials for it out already. Is it ready for developmental use, or is it still too early for that?
×
×
  • 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.