As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I've been using phpMyEdit to quickly generate CRUD screens for databases; it's a quick way to start interacting with data in my projects (and lets me toss together internal admin pages fast)... but it doesn't read the DB schema, so I have to manually set it up.
I'm looking for a tool/way to quickly generate CRUD from beginning to end: I give it a DB table, and it reads the schema, generates the HTML markup for the form, and does the CRUD work on the db itself.
Does this exist? My goal is to have zero setup for basic functionality, and then I'd love the option of being able to extend that basic setup to further refine the experience. (For example: if it can see my database table has four varchar() fields, that would be ready to go with four editing fields "out of the box," but then I'd like to be able to add a little bit of code/set some flags to specify the one varchar() column that is meant to hold an email address, so the tool would then do data validation to only allow emails in that field.)
UPDATE: I'm seeking a solution that I can drop into my existing PHP project(s) -- not an entire framework.
The Yii Framework Does this out of the box. You use a web gui to plug in the database table name and it generates crud screens and active record classes along with all the models, views, and controllers.
Try Grocery CRUD: http://www.grocerycrud.com/
It's based on codeigniter and is quick to setup basic CRUD.
I'm looking for a drop-in admin like this too, here's one I found so far:
http://ajaxcrud.com/
I think just about anything you might be interested in will require some front-end configuration or parameter setting.
One tool that I've heard of is TTswiftcoder - v2.6. One of it's nice features is its cost ($0.00).
I think there are plenty of tools around - both free and not-so-free. Try googling phrases like PHP Crud, PHP data grid, PHP code generator and the like. Also try Sourceforge, Freshmeat, phpclasses, Codango , ...
Hope this helps.
Have you tried CoughPHP? https://github.com/awbush/coughphp
Cough generates all the code you need
for managing the object
model-to-relational model mapping.
This includes simple methods for all
your CRUD functionality. This also
includes Cough Collection classes that
represent the relationships between
tables in your data model.
and: http://www.coughphp.com/docs/1.1/data_validation/
Related
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I've been coding with PHP for a while now, but I've been mainly coding with Functions and raw PHP.
I've started to think that I should be writing my code a whole lot neater and more efficiently. I still can't quite get my head around classes. Should I be writing ALL my code in classes?
For example, one of my scripts is a 'permissions manager' - which allows an admin to edit the permissions of various user groups on the site.
Traditionally, I'd have written this as just a script with functions and whatnot. But would it better to write this as a class? If so, what would this class contain? Would I have a separate permissions class for use around the site, and another for the admin-editing area?
Also the site has an API. Should this all be written as one class?
Also, should I be using public (shared) functions at all?
Thanks!
In my opinion everything depends on how large is your project. I've worked using Magento for a while and it's so big that it must be grouped in classes and packets. It's easier to read code and analyse the structure of project if it's split in classes. Also when you need to modify your project after a month or year then good structure helps to re-learn it.
It is useful to write stuff in Classes when a particular set of functions and variables belonging and/or oriented to the same entity or propose is to be used in different environments. It gives a sense of organization, delegation of tasks and avoids repetition of code.
But in situations where the above is false, it is completely disposable. Theres no point in writing a class to something that will run only in one specific place.
Also, if you only want to have a set of information organized in an object-like style like in $user->name, $user->age etc. you can simply do this:
$user = (object)array(
'name' => 'John',
'age' => 20
);
Yes, in my point of view it would be better to make your code in OOP to be more neat, understandable, readable and also for maintenance it will be more easy,
Please take a look here in this stack :
https://stackoverflow.com/questions/4409824/what-are-the-advantages-of-object-oriented-php
You should approach that question from a different angle. Don't just use OOP because you think you have to.
Ask yourself:
Are there parts of my application that I could reuse in other parts of my application? Then these could be taken out of your script and be put in a function or class.
Is there a scenario where you would like to exchange parts of your code to change the behaviour without having to rewrite major parts of your application? Then classes and interfaces are for you.
Another good argument for using OOP principles is the increased testability of your code. Using interfaces allows you to exchange the actual object for a mock or stub at test time.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I am currently working on a project for which I haven't found a solution yet, although i've been searching the web (stackoverflow included, obviously) for nearly 2 days.
The company i am working for has the need of gerating several kinds of pdfs: machine/product labels (small ones with info), product trial/test reports (typically A4 size, several values), and any other kind that shows up. All the company's data is the cloud in SQL-Server and the application needs to be web based as well, so that it can be used by anyone around the world (Suppliers, clients, colaborators).
Basically, some years ago a php script was done using TCPDF so the IT guys could create report templates programatically, that could be used anywhere. Nowadays, they use the same script but they create the templates in a web application done in VB.NET but it is not the perfect solution because it is full of bugs and limitations.
What is expected is an application that anyone (from the receptionist to the administrator) can use, that allows the generation of a custom template that will later be used to generate pdfs with the desired data fetched from their database.
As far as I see, there are 3 options:
1 - Use some kind of commercial or free tool which is already done and being used by other companies. Although it seems odd, i couldn't find a tool for this. How come there isn't one, considering that basically any big company needs to generate several types of pdfs everyday?
2 - Correct the existing VB.net application and php script, extending its functionality and reliability;
3 - Come up with a completely new approach for this. I've been thinking in creating a web app that allows people to drag and drop elements so that they can build the desired template (vb.net?c#?). Export this template to xml/json. Use this template and the set of fetched vars from the database to generate the pdf using any of the available tools (FPDF, TCPDF, or any other kind of php tool [php is desired to maintain the usability of the current working templates]).
I would really appreciate any kind of input, brainstorm or wild ideas.
One idea would be to look at JasperReports. It can output templates to PDF. I believe it can also run as an applet.
For a more modern look, you could write an ajax client that talked to a java server to call Jasper there.
This is certainly a common requirement - customisable templates for reports/documents. Web-editing facilities are one way of approaching the problem, but it seems very hard to get the web-ui to marry well to an output PDF (pagination alone is a significant roadblock).
Docmosis (a commercial document generation engine) seems like a pretty good fit here for providing the customisable-template capability and output to PDF etc. Because the "templates" are basic word or openoffice writer documents anyone can edit them (though some templates become complex enough you would avoid this for some customer/user groups).
A common implementation (which sounds like a solution to one of your key requirements) using Docmosis is to provide a set of templates in the application and allow the users to download, modify then upload back into the system. The templates take immediate effect and Docmosis has some interesting features to assist users detect and find errors in their template (such as writing errors into the produced PDF/doc as footnotes to describe what is wrong).
Please note I work for the company that created Docmosis.
I hope that helps.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
By a multi-site system I am referring to a system that has multiple panes of the same version. An example of this is Gamespot, where it shows different release dates and even different games depending on whether you are on uk.gamespot, us.gamespot, etc.
The site selection isn't this issue here. The issue is the process and ease of development and how site specific data is selected or entered. There is also the potential of various system components being not required to be site specific, and in some rare cases it will be required that all data from all sites be visible and selectable for reporting and administrative purposes.
The following techniques have been considered, and although we know they will work, we are unhappy with the cumbersome nature of their implementations:
Table Views -
By creating multiple views for each site on each table we can load data to be queried that is specific to the site. However, inline SQL would have to dynamically call on the correct view, and in the event of a new site being created, a full set of new views would have to be created.
SQL Modification -
By creating an SQL intermediary function, SQL can be modified to change the where clauses and joins to target columns that select only the data specific to a site. However, we believe that to run all of our queries through such a device could have serious problems down the road, and could limit our queries flexibility.
Inline site clauses -
Despite this being the most cumbersome and irritating to implement, it would prove to be the most reliable providing we are able to enforce standards on the way we code. Although this is potentially the most reliable, it is also the least appealing to our developers, it would mean writing site clauses for almost every single query.
So, rather than finding the best means to implement this system on the higher levels of the system, we are trying to find a methodology that will allow a fairly simple implementation of site specific data selection at a base level.
Please let me know if this question is too broad in any respect and I will try to narrow it down further.
First Edit:
The type of data across the sites is identical in respect to the tables. A users table will be shared across all sites and each user may only have access to one, some or all sites.
Lets take the Gamespot example a bit further. One user is given the responsibility of managing the UK version.
The information about games and their reviews are drawn from records accessibly to all sites, because this is globally relevant information
However, lets say the release dates come from another table which is site specific.
The information about the game is retrieved in a typical manner, however getting the release date takes a little extra code to get the correct one for the correct site.
Regarding the user, whichever site that user is currently managing, should be the site that the selection and insertions target.
As you can imagine, the release date is not a core table, and each date cannot simply be mapped against it's respective game directly.
(I do not imply to have any knowledge of the workings of Gamespot, the example is hypothetical)
I don't think there is a general answer here, because we don't know enough about the actual sites you are building. Here are a few examples of questions that will have a major bearing on the best design:
Does the content mostly overlap between the sites, or is it mostly different?
Is there a simple division between "common" content and "specific" content? (i.e. content is either common to all sites, or specific to one site only). Or does it need to be more flexible?
How much do you expect the requirements to evolve over time?
My advice is to focus your energy on the correct table structure to store your data. If you get that right, a good software design should flow naturally from it.
And of course, feel free to ask any specific questions you have along the way!
Edit: after your question update, I still think there is a lot of ambiguity, which can only be resolved as you work out your specific design. But if you want a quick answer, I think inline site clauses are the best of the three options you have suggested. The others add unnecessary layers of complexity.
I don't see why inline site clauses are "cumbersome" and "irritating". They won't introduce repetition in a good design, because you can handle them programmatically in PHP.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I am working on this website that catalogues products with their basic information and all. I checked and all the different input features required were possible using a combination of fields(cck) and some related modules, features like multi image upload, multiple field values, dependent fields, node reference. My only fear is this would result in a good number of tables that would effect performance. How serious would that performance hit be is what I am curious about? The website is for a niche segment and wont be expecting thousands of users at the same time, maybe a couple hundred simultaneous users during some promotional event, thats it.
I can code everything from scratch but the last time I tried it in drupal 6, there were a lot many hurdles, specially for ajax based dynamic forms and we are a bit tight on schedule. So i just need some help figuring out if the extra effort would be really worth it.
Thanks.
(ALSO: Why did field/cck have to take a table for each field route instead of a table for a content type? Wouldn't that have been more efficient?)
There is alot of ajax functionality out of the box, multi image upload etc ... so that depends on what you need, and if the functionality is allready available.
I have drupal websites with 1000+ visitors a day, with the right caching this is no problem.
The content type fields have their own table now, because they restructured everything to entitys. This makes everything more generic and abstract, so that functionality is now not specific to cck, or one module, but for every module at the same time. Sure this propabely affect the performance, but again, with the right caching enabled this shouldn't be a problem.
Conclussion: Is it worth the effort ? That totaly depends on what you need to create exactly, and how much you can use from existing modules. Also on how often you will have to change things, how large your catalogue ...
You should also check out the Media module suite. While it's not seen a final release as yet and its sub-modules are in a worse state, it's quite usable albeit with rough edges.
Fields use their own tables for efficiency and reusability. This allows a field to be reused in multiple node types. Besides, how would you handle multi-value fields if they were all dumped into a single table per node type?
Performance depends entirely on the type of your audience - anonymous vs. authenticated. If it's anonymous, then you should be fine. If it's authenticated then you will need to pay a little more attention :) Performance for your traffic estimate should not be a problem in a decently capable server.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
i mainly use PHP and I have been coding using it for a while. My main problem with PHP is that I think as your program gets bigger, it gets harder to maintain your code (probably applies for other things). I want to reduce this complexity in maintaining/modifying my codes. I want to make things modular and have rules when to start a new class or just append to an existing class (for example). I know that there are frameworks out there (CakePHP, Symfony, Rails) but what if I just want to use my PHP and use a hybrid of my own style and an existing style for good code management?
This is not just pertaining to php, this applies to coding in general. Frameworks will only help you organize your mess but if you are new to programming a framework will only organize your messy code.
Some basic ideas to keep in mind aside from undertaking a undergraduate in computer science (which i recommend if you are serious about coding) is to make your code modular.
For example, and this is a simply example to demonstrate the point. If you have a site that generates an html table containing financial data.
(Here are a few scenarios of how to go about coding this ...)
You open up a new screen, financialdata.php, you code from line 1 to line N the code needed to get the financial data from a data source (database perhaps) and then iterate over the financial
data to construct an html table.
You open up a new screen, financialData2.php, you code a function at the top which pulls data from yuor data source and returns an object (array maybe) containing the items. You take this return value and generate your table on this financialData2.php page.
You open up yet another new screen, financialData3.php, you take your database function from financialData2.php and use it to get your financial Data from yoru source. You code another function to generate an html table based on some arguments passed in as parameters. And lastly in your financialData3.php page you display do the following and your page now has a table containing financial data from your data source.
The lesson here: the more modular your code is the better in a lot of ways. You now have a data base function that can get data, and you have a function that will render a table based on a list of items passed in.
You can now create another page and use these functions in different ways, perhaps your data source function has parameters like table and selection criteria. This way you can use the same data function to get data from different tables based on criteria. You now have a VERY basic data abstraction. (Dont let abstraction scare you aware). An abstraction is nothing more then a simplification of something. In this case we have abstracted away the details of how we get data and let our function getData take care of those details.
Please comment/ask questions and we can discuss further but honestly, I do not think one book or web site can teach programming practice like a BS in CSE can through classroom discussion and hands on practice.
Learn Design Patterns:
http://sourcemaking.com/design_patterns (covers the GOF patterns)
http://martinfowler.com/eaaCatalog/index.html (covers POEAA obviously)
Also helpful to increase code quality:
http://phpqatools.org/
A sidenote on frameworks:
while frameworks often do tell you how you should layout your code and folders and stuff, they rarely tell you how to code properly. A framework offers solutions to common problems and that's cool, but if you try to step outside of what the framework already offers in terms of functionality, you are on your own again. That is because frameworks are concrete implementations, while you want to learn about design principles.
This is about code in general (it uses Java/C/.Net for the examples if I remember correctly), but Code Complete's the best book I've read on general code structure. It covers everything, from the nuts & bolts of how to write and organise variables and methods up to program structure. I'm not sure how applicable the examples are to PHP but probably worth a look.
http://www.nettuts.com
everything you'll want to know about PHP and web development.
I like this one: http://www.wrox.com/WileyCDA/WroxTitle/Professional-PHP5.productCd-0764572822,descCd-tableOfContents.html
http://www.amazon.ca/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612
Lots of design patterns explained. But not in PHP. Good for understanding useful design patterns. Support the author by purchasing it.