Tag Info

New answers tagged

0

I would use approach 2, putting it on the Comment model. I'd name the method something like loadAllCommentsForPost though, to clarify that it doesn't just load every single comment from the database. Though approach 1 wouldn't be too bad, consider that you might have a lot more models relating to Post later on. You wouldn't want your Post model cluttered ...


1

You could do this by creating 2 additional tables: Table Images ( ImageID int, ImagePath varchar ) Table ImagesXUsers ( UserID int, ImageID int ) (or ImagesXPages or whatever it is you need to associate these images with) Whenever images are uploaded, they are inserted into the Images table, and are appropriately associated with the user account via the ...


0

If you have enough of these little configuration values that you feel the need to put them in another file, then they should go in a configuration file, not a source code file. There are countless ways of implementing config files, but I believe PHP has some standard approaches. To answer your numbered questions more directly: 1) They're never really ...


0

So heres what I did in the end, rather than looping through each minute of each day and checking what should be showing I created a list of all the start and stop times (in one single list) then removed duplicates and sorted them in order. This way I can just cycled through that array and that will give me the start/end times when things change.


3

The connecting table that you speak of is called a junction table. Using the Wikipedia example, they have 3 tables defined. User ---- User ID User Login User Password User Name Permission ---------- Permission ID Permission Description UserPermission -------------- User ID Permission ID Now, you can map these 3 tables to PHP classes. It would probably ...


0

Since you didn't follow the convention of Eloquent you have to type it manually and it's easy just specify the second and third arguments into the hasOne or other functions of ORM obj. i.e: class User extends Eloquent { public function phone() { return $this->hasOne('Phone','id','phone_id'); } } Where the second argument is the column ...


2

It's a violation of Liskov's substitution principle. Basically any class that uses SomeClass must be able to rely on the fact that addMember accepts a SomeClass or any of its subclasses. In your example, that's no longer true, because now you have an implementation of SomeClass that will cause a fatal error whenever a SomeClass object is passed that is not ...


-4

You can use angularjs for the front-end and codeigniter or another php framework for the back-end without any issues. You just have to keep in mind that both are MVC (Model-View-Controller). Why use similar concepts but with different structures? Because angularjs works with template HTML and all views are HTML (not including the header and footer). As ...


1

The principle you're looking for is covariance and contravariance in type hints. To my knowledge, PHP doesn't support it.


0

A SDET role is pretty much what you make it, as evidenced by all its different names: QA/Developer, QA Engineer, Automation Developer. My current title is actually Test Engineer, which I had never heard it called prior to taking this job. Regardless of the specific title, it is a new position in most companies, so the expectations can be loose. "Help us ...


0

For this particular problem I would recommend something similar to your's second aproach. Check out Service Locator pattern (Is this a good service locator, and is this service locator pattern(?) OK?) this is basically what you called "registry". Secondly - don't put User as a service there. Most probably you need something like Session, and in your code ...


2

I would change few things: remove singleton, make private static $container = [] anyway you're just using static methods to retrieve it. consider throwing special exception when getting not set service. re-consider automatic caching for services (it is possible you may not want it for every service) Considering pattern/anti pattern discussion I've found ...


1

I think in any language/framework/application it is good to try to have single responsibility of components, for your case it would mean to have each of the ajax "events" in separate files. you could have files like: /ajax/posts.php /ajax/userInfo.php ... each file could then require some core/common functionality from one location it makes it much more ...


2

Error handling of an API is exactly the same as error handling of any web application. Exceptions should be logged to a central syslog server, and the central log should be reviewed on regular basis. If you use a framework, the framework should handle this for you. Sending e-mails through PHP every time an exception occurs is a risky path. What if ...


0

I think what you're looking for is a Service class. Controllers should be very thin and do literally nothing but forward the data from the request to a service and respond with the appropriate output. The service class should take care of validation delegation and dealing with the database abstraction.


0

I believe what you are trying to do is to reinvent Symfony Forms and add some bunch of ORM to them ;) They indeed contain all the data from the form and all the form HTML structure described in a very declarative way with a possibility of extension. But I think you are wrong when you want forms to be able to query backend data. This is incorrect. Form ...


2

If you are building a web framework, this implies you can serve resources including HTML, CSS and JS files. If it has to be, you could even inline all resources into HTML. You can therefore use CSS- and JavaScript-based techniques to make it arbitrarily difficult to spam your form. To each form field, you can apply a different class. Only one of these will ...


0

Try to answer this question individually for each configuration file. A dependency injection container tree is actually also a kind of configuration, but who could change the file? It might only be another developer. Writing a CMS means there are configuration files like database connection setups and so on, which might be edited by any luser, but they are ...


1

The best back end webserver language for an embedded C program is... C! There are plenty of embedded C webservers that are trivially easy to use, I added civetweb to my service a while ago and it was too easy. Civetweb is a non-GPL fork of Mongoose, but there are others such as NxWeb. Civetweb has some examples, including ones that include Lua support ...


1

Pre-populating images folder is a time consuming one. There might be a chance for empty leftovers. So while uploading images check for the existence of folder, if folder exists upload image else create folder and then upload.


1

There are points to keep in mind for each approach, and there may not be a clear winner. Protected Field If not constant, a protected field allows the subclass to modify parent class state directly. This means a subclass may be able to violate the parent's invariants or validations. State may be able to change at inopportune times, which may cause problems ...


0

Use a multidimensional array like $key => $value, $key2 => $value2 and iterate? $data = array( 'column_name' => 'value' ); querysorter ( 'tblname', $data ); function querysorter{ foreach($data) //bindparam here } Hope this helps, just had to do something similair.


0

good morning, i think this could part of the answer (SQL) : the last 2 queries give the top comment : the less the average the better the position (upvote = 1 and downvote = 2) CREATE TABLE t_comment ( comment_id INT NOT NULL , question_id INT NOT NULL, user_id INT NOT NULL, timestamp TIMESTAMP ); ALTER TABLE t_comment ADD CONSTRAINT pk_comment ...


0

You said that a lot of websites are already scheduled to change to your CMS system, so it sounds like a question for them. Will these be managed by people so programming illiterate that they would be more comfortable editing an INI file that a PHP file with simple options? Would the loss in speed from parsing the INI file be an issue for them? Would they ...


0

IMHO, Model-View-Controller (MVC) design pattern purpose is to separating your application concern into Data (model), Presentation (view) and Business logic (controller) to increase the reusability and maintainability of your code[1][2]. In MVC design pattern, the controller component contains every method in your application which have the same domain. Lets ...


0

Generally speaking, the more you follow the "guideline, not law" of Demeter, the more code you will be writing, as you must hide objects from one another.


2

PHP provides the int fpassthru(resource $handle) function. You open a file, and then have fpassthru send the file outby simply copying it to the output without storing it, allowing potentially very large files to be sent. <?php // open the file in a binary mode $name = './img/ok.png'; $fp = fopen($name, 'rb'); // send the right headers ...


0

Architecturally "search" is no different from "getCustomerDetails" its a request, the system reads a datastore to get the data and the result is formatted for the screen. "Replace" is really no different from "changeAddressDetails" a request is sent, the data store is updated, and details of the update are displayed to the user. The MVC paradigm is meant ...


1

Yes. Keywords are: file streaming with php. It is something like this: echo file_get_contents('secretfolder/the_file.pdf'); Do a search or have a look at: http://stackoverflow.com/questions/6914912/streaming-a-large-file-using-php


0

Prosody XMPP server (Open source, previously it was Jabber..) Use Google Cloud Messaging (GCM) service for android Use BOSH for your website. I believe BOSH stands for 'Bidirectional-Streams over Synchronous HTTP'. BOSH (previously known as 'HTTP binding' or "http-bind") is a technology to use XMPP over HTTP. This allows XMPP applications to run in web ...


2

You can use the strategy pattern to switch essential functionality. This seems to be more about behavior than about creating different kinds of subtypes of one supertype - so the behavioral strategy pattern seems more appropriate to me than the creational Abstract Factory pattern, though they can be combined: Strategy pattern for switching behavior, Abstract ...


4

This is a classic use case for an abstract factory. You'd have a single interface and then separate concrete factories for each individual implementation. You'd then use factory methods to control the initialization of each set of factories.


3

If the amount of work you would need to expend to refactor towards a transparent implementation of authentication in your controllers is indeed absolutely prohibitive, a decorator will work. The reason it ought feel somewhat 'hacky' is because relying on magic methods makes functionality somewhat opaque (magic methods, as well as call_user_func also have ...


0

I have done something similar with javascript validation, not execution. I use the command line tool gjslint from Google to validate javascript. /** * * @test * @dataProvider dataprovider_javascript_file */ public function javascript_files_are_valid ($fn){ $dn = getcwd(); $fn = "$dn/$fn"; // most of these are whitespace- file-ending- and ...


3

@DavinTyon's answer was very good, but I think that there are a couple other things worth mentioning. For better or for worse, the router/controller part of MVC is functional. The hierarchy works like this: The router takes the URL and figures out which function it should call The controller acts as a module to encapsulate related functions The action is ...


1

I think you are referring to the Single Responsibility Principle (SRP). Which, in summary states: that every class should have a single responsibility, and that responsibility should be entirely encapsulated by the class However, this does not mean that one class should only do a single thing. In means that a class or module should only have one ...


7

An ORM is not a requirement for any project of any scale. More often, small projects start with an ORM, then abandon it when scaling up. If database changes become too complex: Ask yourself why is the database changing too often. I had to work on projects where database was changed at least once per day, just because the project was badly thought, ...


0

Yes, that is the template method pattern Currently there is no need to make the getType methods public, "protected" would be enough. If you actually need them outside of that class hierarchy, you can make them public, of course.


0

The best way I have found to do this is as follows: class This_Is_My_Class { use My_Trait; protected $prefix = ''; function __construct() { $this->prefix = 'not_empty'; } protected function get_prefix() { if ( empty($this->prefix) ) { throw new Exception("Prefix must be non empty."); } ...



Top 50 recent answers are included