Object-Oriented PHP Structure? [closed] - php

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 days ago.
Improve this question
How can I better handle Object-Oriented PHP structure?
Folder Structure:
ROOT
- [includes]
- client.include.php (include client.controller.class & client.class)
- global.include.php (include global.controller.class & global.class)
- [classes]
- databaseHandler.include.php
- client.class.php (extend databaseHandler.class)
- client.controller.class.php (extend client.class)
- global.class.php (extend databaseHandler.class)
- global.controller.class.php (extend global.class)
- index.php
index.php added new GlobalController()
$client->getClient($client_id) <- this will NOT work
$global->getClient($client_id) <- this works
client's form will directed to client.include.php where new ClientController() will be trigger, and it is when they can access insert, update, delete function to SQL
Now, I put all gets method in global.class such as
getClient($client_id) <- for client's class
getOrder($order_id) <- for receipt's class
getConversation($conversatio_id) <- for conversation's class
But I think it gets really messy since I have to duplicate getClient() in both client.class & global.class
But if I use magic function __call, a duplicate warning is called, since all my class's base class is databaseHandler.class
Is there a better approach to this?

Related

Laravel 5: constants.php vs constants in controller vs constants in model [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I'm using Laravel 5 and I need to add some immutable values (constants) to be able to make use of them in controllers mostly (maybe in views too). Question is: What's the best approach?
I've been reading and 90% of approaches suggest to use a constants.php and Config.get(), but I don't like this because (I think) a constant is not a config value. I mean, it's not supposed to be changed. In other frameworks, I like to use models or other lib class to define values related to the entity I'm working on, Eg.: I need a constant for cache time in users, then User::CACHE_1_DAY = '86400' (silly example btw).
I would recommend adding a new class containing Helper methods, and bind that class to the application in your AppServiceProvider.
Finally inside that class, place getter methods for the constants.

Naming functions in PHP [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I looked online and could not find any answer. I'm new to PHP and i've seen so many different ways of naming functions. Namely,
isset <- no underscore
is_integer <- underscore
fooBar <-subsequent words after the first have the first letter capitalized.
In what way do the functions differ in the way they work, such that they are named differently by convention? Or is it some other reason?
Earlier versions of PHP built-in functions had no naming conventions, that's why we have such a zoo. But, no, it does not matter how you name a function as long as you use naming conventions of your team.
If you're making shared public code/library you better stay close to, for example, http://www.php-fig.org/psr/psr-1/ PHP standards

twig best practice regarding template locations [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
My site isn't using a front controller pattern or anything fancy, it's currently a bunch of php files in folders.
e.g:
http://www.example.com/customer/account-settings.php
maps direcctly to:
/var/www/sites/example/http/customer/account-settings.php
I've started playing with twig, and wonder what the best practice for locating the template files is?
Should I put them all in
/var/www/sites/exammple/templates/
or should I put them alongside their corresponding .php file?
/var/www/sites/example/http/customer/account-settings.twig
/var/www/sites/example/http/index.twig
etc?
I would place all files in one directory and than create a configuration variable like
$templatesDir='/var/www/sites/exammple/templates/';
to reference the location.
That way views are organized and not scattered around the project. If for some reason you want to change their location to another directory you just have to change the $templatesDir variable in one place.

Is creating a constant or enum class for template page efficient? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
Basically I'm building a website that need a html like template called from the folder using their file name.
Should I use a enum/constant class or should I just call them straight to their filename?
Example:
abstract class ViewTemplate
{
const ORDER_HISTORY = 'order_history_template.html';
const PURCHASE_HISTORY = 'purchase_history_template.html';
//etc...
}
Is this kind of class necessary and do they hog a lot of resources if I call the class when I have a lot of template?
Since the filename is a unique identifier - unless you expect the file names to change in the future (which isn't likely, and even if it happens refactoring is simple) there is no point to it.
You already have a unique identifier for a file you're loading. The only benefit of passing an enumeration with properties here is type-safety but you're only calling it once anyway so a typo could happen in one place anyway.
So overall it's redundant.

Should Bootstrap handle scripts and styles instead of views? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am working on a distributed project where I saw various "appendStylesheet" and "appendScripts" on headLink which were added in Bootstrap.php.
Honestly, I am not much experienced with ZF (consider few months ~ 2 projects) and personally I think, it is not "semantic". You can always append scripts via layouts or if you want flexibility as per different views, they could be called to appendStyles as every view would want (if not coded in layouts).
My question is about working "collaboratively".
Should "views" related scripts be added on bootstrap or let it do the function of routing and implementing modules, etc?
styles and scripts should be added from the layout or viewscripts. this way you can easily switch the application's "design" from one to another by simply replacing the view and public folders.

Categories