Jump to content

ignace

Moderators
  • Posts

    6,448
  • Joined

  • Last visited

  • Days Won

    25

Everything posted by ignace

  1. The UI is not intuitive. I had no idea how to add a new workout. Also the formatting help returned nothing. Not everything has a weight like push-up or sit-up (which is not equal to your bodyweight) unless you would use a weighted vest.
  2. Like scootsah already mentioned. Now you are the only one guarding the security whereas otherwise thousands. I also didn't say you need to go and download the entire Zend framework. I don't even like Zend. I tried Apigility (by Zend on ZF), yet a simple composer update breaks the entire thing (it could not find it's own core tools ZFTool for some reason)... I proposed simple libraries that do ONE thing and do it WELL. The unix philosophy.
  3. Add this line to finaladd.php $json = $_POST['output']; var_dump($json, json_decode(stripslashes($json)));And post the output here.
  4. Don't reinvent the wheel. It's okay to create your own little framework but be sure to utilize available libraries. Like Doctrine for example as your ORM or DB Abstraction Layer. Something like Silex as a way to utilize a CMS. Build on the shoulders of giants. your far better off this way.
  5. I guess you are referring to compiled and interpreted code. Compiled code is translated to CPU instructions where as interpreted code like PHP, HTML, CSS, and JavaScript are translated to instructions in whatever language they were programmed in. For PHP it's C. For HTML, CSS, and JavaScript it depends on the language of the browser. For more information: https://en.wikipedia.org/wiki/Abstract_syntax_tree You can create your own programming language using a BNF generator: https://en.wikipedia.org/wiki/Extended_Backus–Naur_Form Some libraries provide a working lexer: https://github.com/doctrine/lexer/blob/master/lib/Doctrine/Common/Lexer/AbstractLexer.php
  6. It's really simple. Add a referred_by to your table and when IS NOT NULL then apply 5% to the ID.
  7. No, he probably saw them editing JavaScript. In this case all occurrences are changed at the same time.
  8. Like scootsah already pointed out, you can only pass instances of A. That said to make it more natural to arithmetic operations you can use value objects. class Operand { private $value; public function __construct($val) { $this->value = $val; } public function add(self $other) { return new static($this->value + $other->value); } public function __toString() { return $this->value; } }So your program can look like this: $seven = new Operand(7); $four = new Operand(4); $eleven = $seven->add($four); var_dump($seven, $four, $eleven); $twentytwo = $eleven->add($seven)->add($four); var_dump($seven, $four, $eleven, $twentytwo);As you can see $seven remains the value 7 as does $four remain the value 4 throughout the application.
  9. You can print a cheat sheet by going to Help > Default Keymap Reference. I must admit I use Sequel PRO for actual querying (no real reason just force of habit I guess). The only reason I have the database navigator active is for autocompletion of tables and columns in my code.
  10. If your project is coupled/synced to the FTP then you don't need to know which file is changed, since it uploads it for you when it saves the file. You'll see it when you CTRL+TAB, it'll say at the bottom: "Uploaded file X to server Y in Z seconds." That said, this is not a typical workflow. Like scootsah already pointed out normally you'd use a VCS then commit and deploy from there. That said, you can also deploy from within the IDE when you commit. CTRL+K (or VCS > Commit Changes) in the right pane it says: "After commit > Upload files to:" You can also add several tools that will execute (like Phing) when you commit etc.. I love this IDE too, the only limit is your imagination I guess
  11. self points to the current class, so basically it says function add(A $b). You'll see also other like static. However this won't work, since static is late bind, while self is early bind which is why this works.
  12. PHP does not support arithmetic operator overloading. You can however use a simple method to achieve this. class A { public $value; function add(self $b) { $this->value += $b->value; } }
  13. No, they are not. Your constructor does a require_once() which means that with every instance you'll load the same file over and over. Move it somewhere else or at the top of the file before your class definition. public function __construct(Google_Client $googleClient) { $this->client = $googleClient; if($this->client)Not sure why you think you need to test $this->client, in case PHP wouldn't PHP?
  14. Like I already said you know when to load up dependency X and Y when you call the method on the mapper. Loading extra during presentation will lead to problems. Doctrine provides this functionality just to not break your code. And it is also easy to trace back when reviewing your query log. It'll show up something like: SELECT .. FROM table WHERE id = 1 SELECT .. FROM table WHERE id = 2 SELECT .. FROM table WHERE id = 3 ..
  15. Very nice use of SaaS. A lot of services I hadn't even heard about. Did you just google these, or already knew them? And why exactly did you decide to use these?
  16. http://forums.phpfreaks.com/topic/262327-bored-looking-for-ideas-heres-a-list/
  17. The dependency is "wrong" because your entities depend on a higher layer. In other words the DAO layer should be dependent upon the entities (Motor, Product) not the other way round. Doctrine solves this problem by using Proxy Entity objects. More on that here: http://stackoverflow.com/a/17787070 This is kinda the same as what you did with the exception that this dependency is hidden and inexistent when the full object is loaded. Which is also what the Mapper pattern allows you to do. For example when a User logs in, it may not be required to load the groups he is a member of. So in this case this becomes either null (resulting in an Exception or Fatal Error) or a ProxyCollection (in case of someone does access it, of course for performance reasons it is best to not be used). However when you want to view the groups he is a member of it is required to load the Groups. Since you access business methods on the Mapper object. You know exactly what you should and should not load (or lazy-load).
  18. Your code looks good although I would move the redirect back to the controller and not handle it in your service.
  19. It would help to post the PHP code. Also mostly these are cut-and-paste/works-out-of-the-box type of code. Since you have a website I assume you have at least a little technical background? And I assume your server supports PHP? Have you tried creating a new file pasting in the code and see what it outputs?
  20. The difference is that in my case the Mapper has context so related objects are also loaded. While your chained method calls need to be called every time you need more data, resulting in more queries. Also because your Entity uses the DAO directly it is actually tied to your DB which has the dependency the wrong way like an object created by a Factory object would be tied to its creator. These should be decoupled. As to why the Mapper I link to this article: http://stackoverflow.com/a/814479
  21. Yes, you went too far. Also your business classes should not be aware of DB classes. If your Product needs a Motor then make sure your DAO injects it. class ProductMapper { private $SQL_LOAD_PRODUCT_WITH_MOTOR = 'SELECT .. FROM .. JOIN .. WHERE ..'; public function someBusinessIdentifiableMethod() { $rows = db_query($this->SQL_LOAD_PRODUCT_WITH_MOTOR, [..]); foreach ($rows as $row) { $products[] = $product = new Product(); //.. $product->setMotor($motor = new Motor()); } return $products; } }Your Mapper class would query your database and then "map" the result to objects. Much like the ResultSetMapping from Doctrine.
  22. Wow, my worst days are like accidentally wipe clients database with no back-up. But everyone has done that once or twice. And that's about it
  23. There is no reason you should have one class that does and knows everything. It's far better to create specialised classes for your pages. It's also far better for performance as you'll quickly be loading too many unneeded classes.
  24. As a side note I want to point out that MVC does not mean create a Model class, a Controller class, and a View class. It means separation of concerns, where the important bits are Model (Business Logic) and View (Presentation Logic). The Controller is the part that binds these two together. A simple (W)MVC example would be a contact page: // contact.php if (isset($_POST['submit'])) { mail('hello@some.website', $_POST['subject'], $_POST['message']); } include 'views/contact.html';Believe it or not, but this is really an (W)MVC implementation. Where: - contact.php -- is the controller (model and view are unaware of each other, yet together they achieve a specific goal, contacting the owner) - mail() -- is the model (hiding how mailing works and providing a simple interface) - views/contact.html -- is the view (hiding the interface how the user will enter the required data) - Apache -- is the frontController (like your App.php, translate a route to a controller) It's important that the model is unaware of the view and the controller otherwise it would severely limit it's re-use. Your LoginModel is also not correct because it violates the Single Responsibility Principle. It finds a user based on user and pass, and it stores a session cookie. You'll also have to duplicate the "find a user based on user and pass" every time you need it thus violating the Don't Repeat Yourself principle. class UserMapper .. { private $pdo; function __construct(PDO $pdo) { $this->pdo = $pdo; } function findByNameAndPassword($username, $password) { // implementation } } class Session .. { function set($key, $value, $lifetime) { // implementation } function get($key, $default = null) { // implementation } } class LoginService { private $userMapper; private $session; function login($username, $password) { // $user = $this->userMapper->findByNameAndPassword($username, $password); // if (null !== $user) { // $this->session->set('loggedin', true, 86400); // } } function isLoggedIn() { return $this->session->get('loggedin', false); } }As an example. You would use the LoginService in your controller as it hides how a user is logged in and is completely re-usable in another project if needed. Controller and View are considered to be project specific and thus (mostly) throw-away-code. The Model however not so much. This kind of programming will help keep your controllers thin and your (model) code re-usable.
  25. I would definitely tell them. Not sure what the laws are in the US but I haven't run in any trouble so far. It's not like your hacking their software plus it gives them an incentive to choose you now and in the future. I found they can appreciate someone with proper knowledge of things, someone they can trust and build their business on. That's what you do as a freelancer after all, build relations.
×
×
  • 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.