Questions about PHP, a widely-used general-purpose scripting language that is especially suited for Web development.

learn more… | top users | synonyms

0
votes
0answers
11 views

PHPUnit > Best approach to mock container objects? (e.g. $item->id)

I'm using PHPUnit test doubles to mock models, libraries etc. But when I want to return an array perhaps of container objects, how best to do so. Here is what I'm currently doing: /** * This is just ...
-2
votes
0answers
32 views

PHP only showing records by id? [on hold]

I am having trouble with this PHP code and I am not sure how to title it! I have a car showcase and I am wanting the Database to display the cars depending on their ID e.g 1 Ferrari Enzo, 2 Porsche ...
1
vote
1answer
31 views

PHP MVC Model with a method to fetch all of the model from database

I have a crazy question, consider I'm developing a blog website, There is two model named Post and Comment, now I wanna add a method to fetch all comments from database, which model should I choose to ...
0
votes
0answers
13 views

How to push data from one page to another [PHP] [migrated]

I'm using sockets.io, express and php and I was wondering if it is possible to push something of a page (that only a specific user can see at the time) to another page other can see. For example, if ...
1
vote
1answer
45 views

Need to store Multiple Images (path) into MySQL after upload

I am trying to build my own little eCommerce CMS, and i want the expert opinion on how to handle multiple uploaded files (images). For Example: A user adds a new item, fills the necessary form data ...
0
votes
1answer
42 views

Storing and retrieving simple data within a framework

I'm writing a framework, a project for learning, not commercial. Basic overview of the framework: htaccess sends all requests to Front Controller (index.php); Front Controller loads ...
0
votes
0answers
21 views

Preserving Pre-formatted Multi-Line Strings in Node.js Scripts

There is a lot I don't like about PHP, but one thing I love is multi-line strings: $query = <<<EOT select field1 ,field2 ,field3 from tableName where field1 = 123 EOT; ...
0
votes
1answer
70 views

Database object mapping, good practices [on hold]

I think I've understood the basic idea behind object mapping but there is one gap in my knowledge base that I hope to fill now. First let me tell you what I understand out of the whole thing. I have ...
2
votes
0answers
60 views

Scheme/Design Pattern for allowing a certain outside class to set properties

I came up with a solution (in PHP) to a problem and am wondering if it is a named Design Pattern, and if it is good practice. I have a collection class and an item class. The collection class is the ...
-4
votes
0answers
38 views

HTML Parsing in PHP [closed]

I have a code echo 'File Date: '. "$file_date<br>"; preg_match('/Instrument Type<\/u><\/font><br \/><b>(.*)<\/td>/', $html, $matches); $instrument_type = ...
0
votes
1answer
55 views

How to efficiently determine when changes occur in event lists

We have a system that stores event information. There is a primary list of events as well as a secondary list, these may overlap. Secondary lists are combined with the primary based on 3 main rules. ...
0
votes
2answers
53 views

PHP extended class method requires same signature including object class requirement? [duplicate]

Not sure exactly how to phrase the question succinctly for the title. I have a collection class that extends another collection class. The parent collection-class has a method addMember(someClass ...
0
votes
0answers
44 views

How to dynamically print a URL as a QR Code using PHP (Drupal Views)

I'm working a small home project, and I wish to dynamically produce a QR code on a content Node (I'm using the Drupal 7.3x CMS framework and specially the Barcode Module). I've not had much success in ...
0
votes
1answer
75 views

How to appropriately structure a script used in an AJAX call?

When I first learned AJAX, I was also teaching myself the languages of PHP, JavaScript, SQL, HTML, and CSS. I followed my coworkers existing web apps as examples of how to write my own web ...
0
votes
1answer
52 views

How to handle coding errors in my PHP AJAX code?

How do I handle coding errors in my PHP which has no GUI, only an API? I am concerned that I might never know that there are any. Note that only I will develop the client side. This is not a public ...
-1
votes
0answers
20 views

Data Type of file_get_contents of php in java [migrated]

I am trying to upload an image to the database with blob datatype. I use web-service method addProfilePic that store the blob data to the database with my Codeigniter project. I retrieve the image ...
0
votes
0answers
22 views

Architecture: Validate polymorphic votes - Controller or Model?

I have a question because I don't want to do something wrong. I have a polymorphic relation called votes. Well, I want to save votes but I need to validate if a user already has voted. But even if, ...
0
votes
2answers
29 views

Best Way To Store Images For Mobile Synchronization

The scenario is, I have a Web Dashboard (Developed using PHP + MySQL) and have Android and iOS Apps synchronizing data from the Web Dashboard (only one way i.e. Dashboard to Mobile Apps) Now the ...
0
votes
1answer
66 views

Is this a good service locator, and is this service locator pattern(?) OK?

I'm working in Zend framework 1 and was using Zend_Registry to store objects so that I could replace them in my controllers while unit testing: $auth = Zend_Registry::get('Auth'); // set in ...
0
votes
0answers
45 views

PHP mail templates

I'm working on a webshop (used to be for just one product, expanding it to multiple products and multiple shops hooked up to one backoffice, can't use PrestaShop because of compatibility). We send 3 ...
3
votes
1answer
201 views

How to hide a honeypot ( excluding external CSS and JS )

I am adding spam protection to my personal php framework and I think honeypots are a great way to block spam. Unfortunately they weren't invented yesterday and probably most bots do fetch CSS and can ...
2
votes
1answer
162 views

An embedded C developer wishing to interface some code with a web page

Okay, so as the title says, I'm an embedded C/C++ developer. Right now, I'm working on a project that involves a client/server C application. The server side of the application is running on ...
0
votes
1answer
92 views

Protected properties vs protected getters

If I have an abstract Animal class with a $name property and constructor like this: abstract class Animal { protected $name; public function __construct($name) { $this->name = $name; ...
1
vote
1answer
80 views

mySQL / PHP design pattern - one function multiple queries

So here's the gist of it. I'm looking for a design pattern where I can have one function, say queryHandler that gets the query and the parameters from a number of different functions and returns the ...
0
votes
1answer
40 views

Like structure table with Laravel and showing the most popular content at top

I am using Laravel to creating a website, my users can post questions and other users can write their comments under the post, each comment have Up vote and Down vote, and users can voting for ...
-1
votes
0answers
10 views

MySQL Query - how to keep normal users from seeing staff posts? [migrated]

On my forum, I'm having an issue where non-staff members can view staff related posts that are otherwise hidden to normal users. Upon investigating I've discovered that staff related topics do not ...
0
votes
1answer
33 views

When to create upload image folder? @upload ? Or beforehand? [closed]

Ok, Here's the deal. Say, user0001 is uploading an image, do I create the folder when he creates said image? Ie /images/00/01/user0001/ <- Or, should I pre-populate the /images/ folder with the ...
1
vote
0answers
64 views

Is this pattern of optional dependency injection sound? [duplicate]

A lot of the time when working on legacy code bases, I find it hard to move manually created dependencies to the constructor parameters, because of a variety of reasons. Sometimes it's because the ...
2
votes
0answers
119 views

Deleting all cached page of the site [migrated]

Scenario Mobile and desktop version. I'm developing a website with a desktop and a mobile version: users can choose to switch version if they want to: javascript will save a cookie telling the ...
1
vote
1answer
98 views

Design pattern where decorated object may ask for things like “status updates” from the decorator to perform it's role?

Here's an situation that has haunted one of my open-source projects for quite some time. Imagine if you could represent every front-end input form with a single backend object? An object that ...
-2
votes
0answers
29 views

Not sure where to put the where clause In codeigniter [migrated]

I have been looking over the active records guide from codeigniters site and I am trying to figure where to put the where clause, in the model or controller? I think it goes in the model, but not sure ...
0
votes
2answers
80 views

Serving a file from a private directory [closed]

I have a PDF that needs to be accessible for multiple unrelated areas across a website. I don't want to reveal anything about where the file is downloaded from and I want to only upload the file once. ...
0
votes
2answers
45 views

What pattern do I use and how do I implement it for one method that will be handled multiple ways

My scenario: I am creating an application that will allow me to create a mapping of redirect url's that will point from the request url (the url in the old ecommerce solution) to the target url. There ...
0
votes
1answer
101 views

Change routing to comply with Law of Demeter

I have a Task, Owner and Plan. Charge values are kept in a plan, owner is on a particular plan and task knows its owner. A task needs to setup its charges based on the knowledge the owner has. Owner ...
2
votes
1answer
84 views

How to add permissions checks 'after the fact'

I have a great number of PHP classes which perform the business logic of my application, e.g. class FileMaker{ public function makeFile(){ //some code here to make a file } } Now I need to ...
-3
votes
0answers
18 views

PHP Help with Call to a member function add() on a non-object [migrated]

Question: What is the problem that I apparently cannot pass an object through to this method? Code: http://pastebin.com/fUbJdgXk Issue: Line 22 $this->business->add($specrep); returns Call to a ...
1
vote
3answers
135 views

Controller in MVC

Alright so it is an essential part of OOP that one class should only do one thing, and it makes sense. In practice I've seen that classes which don't obey this rule get thick and cluttered. So I was ...
1
vote
1answer
111 views

Does ORM at any point become a “requirement” for RESTful API?

I've started building a RESTful API in PHP's Slim framework. The framework appealed to me because of its light-weight design and routing features. I am using PostgreSQL for the database. However, ...
0
votes
1answer
85 views

Is this the template method pattern?

Could someone tell me whether the following is A) a good solution to the problem of repeating code and B) an example of the template method? Let's say I have one table, named VEHICLES, which I use to ...
0
votes
0answers
107 views

Is this a good implementation of the builder pattern?

I'm trying to design an SQL builder in PHP. I'm trying to make it so that the system could work with different database systems (e.g. Oracle, MySQL, MSSQL). Here's what I've got so far. First, I have ...
1
vote
1answer
60 views

Is there a way to document required properties in traits (PHP)?

I'm fairly new to using traits in PHP and am wondering if there is a way to ensure that a class including a trait has particular properties. I know that you can use something like the following to ...
3
votes
1answer
102 views

Creating variables in methods/functions

In how far do we create variables in our methods or functions? Do we only create one when we're using the result of the variable more then one time like this? function someFunction(SomeClass ...
2
votes
1answer
90 views

How to design database tables for a Factory class?

How can I design database table structure for a class that varies in its core parameters, when it is created by a factory method? I have a Factory like this: class ProductFactory { public ...
1
vote
1answer
66 views

PHP MVC Display many records - model logic

I bet this question has been asked already but I can't form my thought as you can see from the title, so I couldn't find anything. I am working with MVC for quite some time now and I'm pretty happy to ...
0
votes
1answer
66 views

Condition before statement or statement in condition

I've come across this problem a few times: Is there any "programming rule" for checking for an condition (error checking for example) before you want to do execute code, or only execute the code when ...
0
votes
1answer
47 views

How can I program the script on my server to the receive a cname pointed to it?

I am in the final stages of creating a mobile responsive customer relations management platform. Presently it is written in php as a stand-alone self-installing script. I would like, however, to ...
0
votes
0answers
47 views

Login Tokens Remote DataServer for use in a Javascript/HTML-PHP environment

I've asked this question on stackoverflow, but i think this is a more appropriate place for it. I'm creating an app for iOS, Android and the Web. I created a separate Restful Data Service that is ...
5
votes
1answer
113 views

How to use OO Design to Refactor a Library with Functions that are specific Product-aware

I have a class that acts as a library of functions for various products. To compute its data, the function currently needs to be aware of all product names. Depending on which product calls the ...
0
votes
0answers
39 views

What could possibly be a Mysql database structure for an web app say like Flurry?

Simply say, I'm working on a web App say like Flurry (http://www.flurry.com/), that would communicate with a Smartphone App trough API. Right now I'm designing the database structure, and I guess ...
1
vote
1answer
136 views

MVC URL structure with URI parameters

When creating routes for your MVC web application I have seen two possible ways to pass variables to a controller method: With the first approach the variable is passed to a parameter of the ...