Jump to content

topcat

Members
  • Posts

    26
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

topcat's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Actually looking at ZF2 the exceptions are still hardcoded however the exceptions seem much more standardized across all components with each exception being defined within each namespace. So there is at least no dependency on a file outside the namespace used by that particular component.
  2. Any ideas what a neat solution could be? Still looking at zf2 classes at the moment. Cheers.
  3. Aha I see the confusion - the example was a purely abstract one simply to show my thinking regarding the instantiation of a named class. Sorry about that. Should have made it clearer that this was a hypothetical scenario. The actual issue I am facing is that when I use Zend_Db if there is any error with the SQL statement then it tries to throw a Zend_Db_Exception. However Zend_Db_Exception is not available in my framework. I realise that I could easily make it available but this is avoiding the issue rather than solving it. I wish to remove this dependency. Also I do not want to substitute it with another dependency by simply replacing all of the Zend_Db_Exceptions with my own hardcoded classes. I would have the same situation if I wished to move the component to another system later on.
  4. Again, thanks for the reply, I appreciate your time. The calling code does not need to know what type of error object has been created in the router (in this example), only that it is an instance of the Exception class (which it will be as all exception classes would be a child of Exception) the exception object is then just dispatched to an error controller which logs the error and displays the details in a view script for debugging. My understanding of DI at least at a basic level was that the poiint (or at least a point) was to inject classes depended on by another class rather than instantiating them within the "consuming" class. This avoids the refactoring required if for any reason you wish to substitute the injected class for another at some point. Eg as I wish to do so now by using my own error objects rather than Zend's error classes. Basically to remove coupling based on dependency?
  5. Thanks for the reply trq. I see your point and agree with it. However I also don't like the idea of instantiating an object that may not (and hopefully will not) be used. It doesn't feel right either. If this were a functional component which will definitely be required by the class I wouldn't consider any other option other than instantiating the object and injecting it in the constructor, eg if it were a db connection object etc. but that isn't really the case. To be honest I'm using ZF1 components because I have used them a lot and I am familiar with them. I don't really have the time right now on this project to learn another framework from the ground up. Especially ones such as zf2 or Symfony2 which have a completely different design principle to zf1. I will take a look at some zf2 classes to see how they implement error handling.
  6. The above response is still the way to go just replace the 200 with the value from the form field: $value = $_POST['the_id_of_the_formfield']; or however you retrieve the value from the form. I would do some checking here to make sure that the value really is an integer to avoid sql injection attacks. such as: if(!is_int($value)){ show a messsage to user saying it must be an integer and exit" } otherwise add it to the existing database field $sql = "UPDATE `table` SET `column`=`column`+ $value WHERE `id`=1"; (obviously you would have to dynamically set the id. hope that helps
  7. Hi there, I have been writing my own MVC framework which is basically a lightweight version of ZF1. One thing I am tying to improve on in my version is the decoupling of objects. As I am on a tight deadline I decided to implement Zend_DB until I can develop/find a better alternative, I quickly realised that all of the Zend components have their own error objects which extend the PHP Exception object, this obviously creates a dependency, if you don't use Zend framework then you do not have access to the Zend_Db_Exception object. To avoid this I was thinking of injecting the name of a specialised error class in the constructor call to each of my classes. It would not make sense to pass an error object instance as there may be more than one error object required but I could pass the class name and initialise an error object using the class name from within each object. DI is something that I am aware of as a concept but have had no practical experience of implementing and I was wondering what people thought of the approach I intend to take? Alternatively if someone is aware of a common clean technique for error handling without adding dependency and coupling I'd love to hear about it. Cheers. An example: class router{ private $error_class public function __construct(Array $Params = Array()){ $this->error_class = $Params['error_class_name']; ... } public function routeStuff($url){ try{ ...... }catch($e){ throw new $this->error_class("something went wrong"); } } }
  8. Hi Christian, Thanks for the response. I get what you're saying but how would you actually implement the nested templates? Conceptually it's very simple but when I actually try to implement it is when I run into issues. What you suggest is exactly what I am trying to do, but the nesting of one template in to another without know ing where the template will be nested until runtime is where I am having a problem. If I know beforehand where the template will be nested I can use a placeholder as described above, but how can I pull in a template and inject it where I choose from the view object? A concrete example would be really useful! Many thanks.
  9. OK, so if I have a view object that pulls in a view.phtml file and a layout.phtml file. How do I "inject" the view.phtml into the layout.phtml file? If I have the line <? echo $this->content; ?> in the layout file. Then in the view object I use something like: function (loadTemplates){ $viewCode = readfile('path/to/viewScript'); $this->content = $viewCode; } $this is in the same scope for the layout.phtml, view.phtml and the view object so should be ok but the php code in the view script does not work, the line <? echo $this->welcomeMessage; ?> just echos "orld< ?>" I guess I could have <? require $this->viewTemplate; ?> in the layout where I want the code inserted, and then set $this->viewTemplate = "path/to/view.phtml" in the view object but I would prefer to insert it from the view script and I think I should be able to. Hope that makes sense!
  10. Thanks for the reply!! The problem is the lack of control over the response. For example if I want to pull in a layout template that is consistant for all actions in a controller and then pull in the specific view template for each action and place it at a certain position in the layout template, I can't see a way of doing this without including the view templatedirectly fro m the layout template which is not ideal. Thanks for the comment about ZF2. I would just like to get this working first before I start redesigning it!
  11. Hi folks, Strange problem I hope someone can help me with. I've written an MVC framework but am having a small issue witht he view code. I want it to work in a similar fashion to Zend Framework where you can just assign variables to the view from the controller and then echo them out in the view template which works perfectly well. This is achieved by magic methods. eg In controller: $this->view->welcomeMessage = "Hello World"; In the view template: echo $this->welcomeMessage; The controller instantiates a new view object, the view object in turn loads up the view template for the required controller action. The view obnect contains other features such as escaping output and various helpers for common tasks. I want to store all of the response code in the view object until the response is complete and then return it as a response but this is where I run into problems. The php in the view template only works when I use require to include the view template (.phtml) in the view class. If I use readfile() for example to read the contents of the view template into the class then the php code in the template is not executed when I finally return the response. I've tried looking to see how Zend achieves this but it gets quite complicated in ZF when you get to the view and layout code . Any ideas of how to get round this issue would be very welcome, it's the only issue left to resolve to get my MVC up and running!! Many thanks, Tony
  12. Have you checked table level privileges?
  13. I'm using a MySQL database as a queue for pages that have been downloaded by a php based crawler. Sets of pages will be added several times per second and pages will be read by a seperate php indexer running as a daemon also several times a second. This would obviously lead to clashes - I guess the obvious solution to this is to use TSQL for the web crawler although this would cause delays for the indexer. The other issue is the number of database interactions that the indexer would use and the performance lag this would create, I guess that this could be reduced by pulling records out of the db in groups but then memory could be an issue. Another option would be to store the pages in flat files but then I'm not sure how I could avoid issues with both applications trying to access the same file simultaneously. Does anyone have any experiemce of handling a situation like this or have any ideas how to go about doing it in an efficient way? I've also been looking at queue software like beanstalkd but not sure how I would implement this? Any suggestions welcome - cheers!!
  14. You will still have to create the file on the server filesystem before you can download it (as far as I am aware). After you create the file you can then set the headers and download it with the following: $filename = 'whatever you called the file'; header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($filename)); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . filesize($filename)); ob_clean(); flush(); readfile($filename); unlink($filename); exit; That will then delete the file after it has completed the download.
  15. I'd actually take that a step further and create a third table with a many to many relationship with columns user_id | topic_id | status. That way you don't have to parse anything and you can let the SQL do the work.
×
×
  • 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.