Jump to content

trq

Staff Alumni
  • Posts

    30,999
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by trq

  1. I use Skulpin to generate my blog from static files, so all my content is under version control in Git and can simply be merged and pushed to publish on the web.
  2. What have you done to debug the code?
  3. You need to pass your $connection instance into your Account class via the __construct and store it on a property. class Account { protected $db; public function __construct(Database $db) { $this->db = $db; } } You can now use your Database object within your Account object by referencing $this->db.
  4. Im not sure you understand the purpose of a "help" forum. We are not here to write code for people, and frankly, what you have posted hurts my eyes.
  5. You have a few questions rolled into a single post here. I'll try to answer as many of them as i can inline then maybe provide an example of sorts. This is pretty much spot on. You would "model" your part using a class. You should try and keep the methods in your controllers as small as possible. Most of the logic should be abstracted out into other objects. Avoid interacting with "models" within your controllers. While it may seem like the easiest option, it is also the route that leads to code duplication. At minimum there should be a "repository" between your controllers and the models. You can then ask the repository to get whatever data you need. You need multiple views. You are displaying multiple types of data. I've already answer the first two of these and the second two don't really apply/make a lot of sense. I'm going to try and build a very simple example, using mostly pseudo type code. How this the controllers are called and that sort of thing would really depend on the framework you are using. If you're not using a framework, you're doing it wrong. Find one and learn it. Model <?php class Part { protected $id; protected $name; protected $description; public function setId($id) { $this->id = $id; } public function getId($id) { return $this->id; } public function setName($name) { $this->name = $name; } public function getName($name) { return $this->name; } public function setDescription($description) { $this->description = $description; } public function getDescription($description) { return $this->description; } } Repository <?php class PartRepository { public function findById($name) { // some logic to find a Part by id and return it } public function findByName($name) { // some logic to find a Part by name and return it } public function all() { // some logic to get all parts // returns a collection of Part objects } public function findLike($name) { // some logic to find Parts where name like $name // returns a collection of Part objects } public function persist(Part) { // some logic to save a Part to the database } } The Controller <?php class PartsController { protected $view; protected $repo; public function __construct(View $view, PartRepository $repo) { $this->view = $view; $this->repo = $repo; $this->view->setLayout('layout.html.php'); } /** * Used to display a list of all parts */ public function index() { $parts = $this->repo->all(); return $this->view('list.html.php', $parts); } /** * Used to display a single part */ public function show($id) { $part = $this->repo->findById($id); return $this->view('show.html.php', $part); } /** * Used to search for a list of parts */ public function search($name) { $parts = $this->repo->findLike($name); return $this->view('list.html.php', $part); } } layout.html.php <html> <head> </head> <body> <?php echo $content; ?> </body> </html> list.html.php <ul> <?php foreach ($parts as $part): ?> <li><a href="/<?php echo $part->getId(); ?>"><?php echo $part->getName(); ?></a></li> <?php endforeach; ?> </ul> show.html.php <h2><?php echo $part->getName(); ?></h2> <p><?php echo $part->getDescription(); ?></p> Like I said, a VERY simple example. But hopefully it's enough to let you easily see the different layers, and to get an idea about how they might interact. I didn't implement any search or filter, I'm hoping that shouldn't be too hard to see how that would simply be another method on the controller though.
  6. This is the IIS board.
  7. Instead of re-inventing your own templating system, why not use one that already exists? You could start with something simple like Plates (which is just a few simple helpers) or a complete templating engine like Twig (which requires you learn a new syntax). Either way, people have already resolved the issues that you are running into, in far more elegant ways.
  8. Cake probably isn't one of the more popular frameworks around. It's a bit dated these days. The best I can suggest is to start Googling.
  9. Both these services are used for sending email, not receiving or parsing mail data. Indeed. 10-12k is not considered huge by any means.
  10. trq

    Bash syntax

    http://www.catb.org/esr/faqs/smart-questions.html
  11. If your just looking for random open source, visit https://github.com. Its the largest source of open source source.
  12. TOP is not valid syntax in MySQL.
  13. It doesn't matter how many different ways you put the question or how many times you ask it, the is is always, it depends.
  14. What are the permissions on the files in question?
  15. What open source projects do you use? It would be very rare to contribute to something that you yourself aren't actually using.
  16. Any of todays modern frameworks would be suited. The question is which would you prefer to learn. Out of the three you have talked about, Laravel is popular and getting more and more so by the minute. The other two, I (personally) wouldn't even consider, but that's just me. Yii is a bit behind the times in that it doesn't use Composer for package management and Phalcon would just be a nightmare to debug I should imagine. My personal favourite is Symfony. It is modern (in fact one of the leaders in driving php forward - Laravel is based on some of Symfony's components), robust and very flexible. My 2c, you need to download a few and build a simple test app. Maybe a simple todo app or something. If your going to be in it for the long haul, its hard to judge a project from documentation alone and gathering other peoples opinions are just that, other peoples opinions. You need to form your own.
  17. wtf? How do you get any real work done?
  18. All comments in my previous reply still apply.
  19. Firstly, your model sounds like it does too much. Why would you ask a User to find a User? You wouldn't. Models should should model your data is it would be represented in the real world. Users don't know the details about how to login, that is the responsibility of some other model, maybe an Auth model? Then your logic would look more like: ``` $auth->login($user); ``` Auth might also be responsible for checking permissions: ``` $auth->hasPermission($resource, $user); ``` None of these are the responsibility of the User. As for your User needing to be instantiated on each page, your would generally store your User in a Session. This way it can maintain state for the duration of their visit.
  20. wtf? Why would you avoid learning one of the tools that most developers would consider an essential part of their job.
×
×
  • 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.