It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I'm new to cakephp and still learning my way through php in general. To learn I'm trying to build an app which allows the following:
- A user can sign up (using the basic Auth component)
- A signed up user can create a 'campaign', ie fill in a form which will end-up as a page on my website containing details of things the user is trying to achieve. As well as that there will be a 'story' field in the form for the user to explain the reason they are trying to achieve whatever it is they are doing.
Users will have different reasons for creating their campaign, ie new years resolution/wife nagged you into doing it/need to make more money etc etc...
To help users along what I'd like is to have some default stories written and via a radio button users can select their default template to edit. In other words, if they select the 'new years resolution' template a pre-written story will appear in the text box for the story field which they can edit to their preference before submitting.
As I said, Im new to cakephp but have bought all the books and read the manual a couple of times, but since I'm also a bit green with php too I'm struggling a bit. But whats the best way to go about doing the above?
If someone could give me a bit of a break down so I can go off and google the correct things then it would sure make this learning curve a whole lot less daunting.
thanks in advance
pete
ireland
[Sorry to be so blunt but] It's pretty tough to answer this since you don't really have a specific problem but a general problem: you don't know the tools you want to work with.
Again, I don't mean you no harm.
For PHP in general, I would probably suggest to keep http://docs.php.net open in your browser at any time. PHP has one of the best (or maybe the best) language reference and manual. It probably also doesn't hurt to buy a book - IMHO, one from O'Reilly is usually a good fit.
As for CakePHP, I'd recommend starting here: http://cakephp.org/#learn
What you need to do is learn the framework and then go from there. Learn and adapt. There's no other way. What you described is of course not specifically part of any of the tutorials or screencast, but they teach you the skills necessary to achieve your own goals.
It seems like I am "wearing the same exact shoes" as yourself. I have a huge project to work with and no CakePHP knowledge. I tried to start with a plugin like many have suggested, but quickly got lost. Now a couple of months into learning CakePHP, this is what I would suggest you do:
Read the manual entirely (I downloaded this COPY and ordered it only as a manual)
Place sticky markers on the pages and sections you feel you need to reference back
Use a notebook to create your database structure as detailed as possible and use CAKEAPP to make them all come together. Use as much time as you need since the Database is the most important section of your app. CakeAPP allows you to set your app relantionships as well. Pretty neat!
Download the SQL code from CAKEAPP and dump it into your MySQL Database
Use Cake Bake to generate all your Models and Controllers (Change them later if necessary)
Create your main site layout (default.ctp)
Manually create all your other Views.
At this stage, DO NOT look at plugins. Plugins will make you lazy and prevent you from learning CakePHP. After you got your main application structure going, you can then look at plugins to beef it up. Looking at plugins this early in your game will only slow you down. Also, look at tutorials online and Q&A like STACKOVERFLOW's. Most importantly, read the Manual
BTW, I am still working on my Database to make sure, from the get go everything is as close to what I need as possible.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am writing a website in PHP where the aim is to allow the users to enter some monthly data, this is stored in MySQL, and at any point a user can view statistics to do with there data. I have all the basics done, however my code is completely unreadable, it is a mass of if statements, with no obvious structure, even with comments it's fairly opaque. How should I structure my code elegantly, and in what way should I utilise the OOP features of PHP.
Well.. I can only tell you what I generally do, not if it's the 'best' way or if there are more transparent workflows... just that it works for me very well ;)
First thing, and most important:
get rid of ALL non-php code in your php, for html display use templates either make a template system yourself or get one off the shelf (smarty for example).
Try to identify structures you use very often (like sql conenction and access) and put those into classfiles (you can easily change your sql system that way if you need to, by just editing ONE file, not countless others too)
Now find duplicate codeflow (mostly identical if-else-structures and so on)
and create functions for them to replace the original code with said function.
maybe even create more classes for functions that belong to a certain task.
So you end up with one class for the db, one for user information and editing, one for adding, editing and removing informations, and one for html output (and maybe even more)
Now set up your file system accordingly (put class files into a subfolder, templates in another, the same for images, javascripts etc.pp)
Next: Find all "settings"
All predefined values that may need to be changed, and put those into a settingsfile (init.php for example) maybe even as a class construct.
And as the last part, clean up all the mess inside single phps you cannot reduce further.
First: all the setup, include the files(classes) you need setup define the constants you will need for this script etc.
Second: all the script functions either in alphabetical or logical order.
and last the codeflow.
And that's it (a lot of work...) But you'll end up with a structure that I find easy to maintain. If you need to edit a setting, than it is in the init.php for sure, you want to change some db-structures or have changed your database, then you'll just need to update your sql.php and the like.
If someone else has to maintain the code too, you'll most likely will have to comment each file properly as well, personally I use comments for myself as well, since I have some scripts that needed to be changed after five or more years, that way I still know what goes where ;)
Good luck!
I recommend reading up on code cohesion and loose coupling, those are important concepts which you need to familiarize yourself with if you're to build great, maintainable applications.
You should also catch-up on design patterns and common usage cases, if not all of them - atleast the big ones, which are IMO: singletons, factories, DI and IoC (you see those across the board).
Once you've got the theoratical thinking going, you should start writing your code in an indsutry-standard type of way, which for PHP is MVC - you can use one framework, whichever really doesn't matter much, once you've learnt one framework - reading alot of other projects code will be very easy because it usually follows the same pattern with some written better than others.
Good Luck!
You are in need of a framework to structure your code. Luckily for you, this problem has been solved by many. CodeIgniter, Cake, Zend, Kohana, Symfony, Yii, Slim, Laravel, Fuel, the list goes on.
I highly recommend you look into CodeIgniter as your first PHP framework. The documentation and community are both second-to-none.
You may use some kind of PHP framework like Yii, Zend, Symfony or Kohana. MVC separation will be your good friend.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am bulding a website for a project and I want to implement a fonction but I can't seems to find a way to do it.
The principe would be to have on each page one button that, when one particular user click on it, it then add it to his profil page ( that I will build) with the title of this page and an hyperlink to it.
The goal here is to have some sort of activities and the user click on the ones he want to do and then it show a "to-do" list to its profile page.
If you have any clue where to start, through a plugin or coding, I will really be thankful.
Have an awesome night and thanks in advance for the help
Edit :
Hi guys, I am really thankful for your answers and I just want to add some details as I as indeed not so explicit in my description ( the fact that english is not my language played a role too, sorry about that)
I already looked up on internet for hours and didn't find anything. Like Fergus said, I am not familliar with wordpress dev this deep. I basicly know how to add plugin, edit some easy php to make them work with my website if required. I am more business oriented but I have bases in dev in php, jquery/js, and litle bit in ajax.
My goal here was more to build an Minimum viable Product in order to make an "exemple" in order to look in the futur for a technical co-funder so I don't really mind if this is not very clean code.
I started reading the wordpress documentation, about the loop, the hooks, php file, template etc... So here is my technical level ;)
I really appreciate your answers and will try to work with what you wrote Fergus. This is a good start and I actually have a place to start learning know. thanks a lot
Full disclosure: I wouldn't generally answer this type of question as it's incredibly broad and seems to possess very little information; where more is required to truly answer it. However, it got me pondering something I've been wondering about and I've answered it anyway.
In future try and put some more information in your questions, tell us what you've researched and what you've tried and so on. Nobody wants to spend time writing out an answer to someone who wont even do a a quick Google search themselves!
Breaking it down
You need to provide some clear requirements - if you have any that is. If you don't have any, then you need to think of some. For example, from breaking down your post the obvious requirements are:
You need to... display a button on each page
You need to... store data about a users selected pages
You need to... retrieve pages associated with a specific user
You need to... display those pages on the users profile
Displaying a button
Have a button in the template; with an associated jQuery event handler for it? This isn't an elegant solution as it mixes logic with the view - making future maintainability and design changes a pain.
In which case, I'd begin looking at Wordpress Plugin Development - with the first requirement of the plugin to simply display a button - as well as output the required jQuery event handlers.
For implementing this you could look at existing plugins; easy things like source code viewers would show you how to inject scripts and mark-up into a page. Hell, any plugin should be able to show you how to do this!
Storing user data
This will have to be done in the wordpress database. So once again you could look at other plugins that conduct database operations and build a solution from there; or you could check out the wordpress plugin 'Function Reference' and set about 'hacking something together'; it's probably best to see how others achieve it first though.
This part of your plugin literally just needs to take the page and the user, that's all that really needs to be done.
Retrieving pages associated with a user
Ditto the above. You need to be able to take a username or user ID and return the specific pages that this user has clicked on. This could almost be described as just the above in reverse; similarly - bare this in mind when implementing it!
Displaying the data to a user
Think back to the first requirement: displaying a button. You need to be able to output specific data to the screen. The lessons learnt from here will come in very useful again.
So... With this in mind
You now have to consider what tools you're working with and how confident you really are. I get the impression you haven't worked with Wordpress before at this level - but have you worked with PHP? jQuery/Javascript? Do you have an understanding of MySQL and the way Wordpress stores data in databases?
Then condense what I've said above and find out:
How a plugin displays data in a Wordpress Page.
How a plugin can interact with the database.
In the Plugin API you may want to examine Actions as these appear to provide a wrapper for the core functionality of your plugin. Similarly, examine the available Hooks and determine when which part of your plugin is required to run.
As for database interaction? The Wordpress Documentation has pretty extensive information on this too.
There are plenty of documents online about plugin development; and this one details how to modify HTML output using filters. A quick google will probably provide you with 95% of what you need to know, the other 5% could probably be gained with a pen and pencil and a 10minute brainstorm.
In conclusion; break down your requirements in to easier chunks and do some research to see how these bits can be achieved. Then plan on how to integrate it all together as one package. It's too big a question to provide a whole answer to.
I will confess to never having developed a plugin myself, but I'll link you to the seemingly brilliant documentation for it. Similarly, if you haven't worked with jQuery before - here's the $.ajax() method documentation.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I was asked to build a website where a company's employees (around 20) could login and fill in their working schedules for a present and past (if needed) month. Employees should ofcourse only be able to see their own schedules, but the manager should have the privilege to access every schedule.
I have little experience in web development therefore an advice is needed. I have already created a PHP/MySql login page. Now what? How do I go about it?
Just some architectural or implementational(if you will) guidance would be really appreciated.
I have built applications similar to this in PHP / Mysql and can say that it's a good platform for it, although something like Rails might be quicker to use and require less micromanaging. As Wisdom says, use a framework to cut out some of the grunt work and ensure you're adhering to good security practices.
A few things come to mind that you'll need.
Clarity about what your database structure will look like. Try to identify: a) all the pieces of information you'll need to store (A user's name? login info? "authority" level to see others' entries?), b) what tables they can go in. (Can "name" and "hours worked" go in the same table? If they are different levels of analysis, should they go in different tables? Are those two bits of information connected somehow? If so, how should I represent that connection?) Relational design is your friend, especially if you're building something that might get revised later. Take the time to understand what it's about.
A page (view) for each different "type" of activity, would be a good place to start. So have a "Let me see my schedule" page, with links to a "Let me add a time entry" page and a "Let me edit that time entry" page. My experience is that, striving to keep your "view" pages' code as small and easy-to-read as possible, pushes you to better plan your code structure.
ANY values that you insert into a query string, should be sanitized. So queries to search or select values should always have any PHP variables filtered through a "cleaning" structure:
$query = sprintf("SELECT * FROM table1 WHERE identifier = %s",
mysql_real_escape_string($id));
Rather than:
$query = "SELECT * FROM table1 WHERE identifier = ".$id
because any text which a user types into a search or insert field online, if it ends up in your query, could be executed as part of the query. A hacker could then use this to make your other security features useless.
I would recommend to select a framework like cakephp or symfony this way you can avoid some mistakes. if you want to create by your own
first decide the database architecture that will fullfill your need.
than try to make crud functionality for each table as php object.
I think this can make you get going
I was heavily involved in the design of our company's internal dashboard, where employees can log-in and view pertinent company metrics. We used CodeIgniter as our framework and it worked really well! It's a PHP framework that uses MySQL, which we already had both PHP and MySQL installed on our servers. There were already a few people in our company who had experience with it, as it has been around a few more years and is more established than the latest and greatest fad frameworks. It has worked beautifully because of its MVC approach to development. We have attached it to our home-cooked database using Grocery CRUD. It has plug-ins that handle user authentication, sessions, and security. We have been extremely productive with it and I highly recommend. Keep in mind, this framework is designed for developers that want to create something very customizable. That being said, it provides basic things you need but lets you handle the higher-level stuff yourself.
You will need to design your database to meet your real-world constraints.
With MySQL you can create a relational database that reflects users and their positions. We created an E-R Diagram first to help our company's executives visualize the constraints and how we could model our business via the database, so that they could be involved in the discussion during the design phase.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Does anyone know of any good tutorials to build a database driven website?
I am trying to build a site, that will do the following:
I upload data into different tables (categories) into a MYSQL Database
The user on the front end selects a category
The database then prints out all of the data in that category
Seems simple right? But where do I start!
In my opinion, take up php basics from the ground up, learn your variables and what they do, if/else statements, loops n functions etc etc..and leanr how/why they operate.
once you have a handle on the basics, then do something like was suggested above like lynda.com(ive used em theyre great) and other tuts online/books etc.
To do what you want to do, not only will you need this (the basic concepts i put up above), but youll need to learn SQL/MySql as well which is another simple but easy to messup language especially at first depending on what/how/how much you want to extract from the DB, mixing it with php and printing on the page, seting up databases/tables etc etc...
ALSO, in order to organize and display your content, youll need to understand how to extract said data hence, learning the basic basics.
as far as W3Schools - for basics theyre fine.just my .02
If you do your homework, And can tackle what you need in an orderly fashion, in a few days you should be up n running.
Good luck.
You could always get started with the PHP Tutorials on W3Schools - http://www.w3schools.com/php/default.asp
Before I get slated for suggesting them, they are a good start, especially if youre quite new to PHP or PHP with MySQL.
As for the printing it out, I guess you mean display it on a web page, the tutorials would cover this as well.
Once familiar with what you are doing, I highly recommend the tutorials put together on Lynda.com - http://www.lynda.com/
They are really well put together, and come with a video walk-through, so you get covered whatever your learning style.
You could start off by looking at the example code here:
http://www.willfitch.com/mysqli-tutorial.html
Then look at the php documentation:
http://php.net/manual/en/book.mysqli.php
Be careful not to get confused with the mysql_ and mysqli_ functions. mysqli_ is the one you want!
If you are using PHP to build your website,then maintain database on PHPMYADMIN of your server.Connect from your php code to mysql using mysql_connect function..follow this link...php_on_server
I used a couple of the For Dummies series to learn PHP/MySQL/phpMyAdmin. I'm sure the purists will disapprove :)
However, one of my acquaintances works for Google, and he got in my ear that AJAX sites are a much better way to approach things than PHP-driven sites.
So I pretty much rewrote everything I'd done to minimise the need for page reloads. So I now use PHP on the server side, but the client side is never built with PHP. It starts as pure HTML, and then makes calls using Javascript.
I share this not because I have great expertise, but because it might save you some heartache later if you head down the AJAX road from the start :)
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Are there any prerequisites I need to know before I build a website/web application in php?
Anything like ajax, jquery, jsp etc?
PHP is a server side technology, it means the server execute your PHP script and then send the result to the user's browser.
JSP is a concurrent technology based on Java. Your site will be in PHP or JSP, not both.
AJAX stands for "Asynchronous Javascript And XML", it is a way to obtains data from a server with reloading the whole page.
jQuery is a Javascript framework which greatly simplify a lot of common tasks in Javascript.
Javascript is a language which is usually used client side to modify the page or respond to user's action without reloading the page.
You can do a complete site using only PHP without problem. Javascript and everything related (jQuery, AJAX) will help you building a site with better user experience if you do it right.
You can add MySQL to the list, or any other database technology, to store data on the server.
It completely depends on what you want to do, if you want to create a simple blog php is the only thing required, however if you would like to add more features then I would recomend starting the blog and learning more functions as you go along.
There are hundreads of tutorials out there which you can read or watch (on youtube) that will get you started. Most of the other languages such as javascript are touched on as they can make the site easier to use or just look better.
If you want to create a blog or a forum then php is all you need but you may like to start learning other languages once you have a good understanding of php. I would also recomend, if you are new to creating websites, that you should begin by creating a simple site first following a tutorial and then either adapt it or create an entirely different site after you understand the concept of php5.
Like others have said, it depends on what website you're trying to build. You'll be able to get quite far with just PHP/MySQL but for advanced interactivity and dynamics I'd suggest looking into other technologies and combining these into your website along with the PHP.
However, just starting a project and then adding things as you learn is probably the best way. You'll surely get to a point where you want to add something you don't really know how to do, and a quick search will point you towards.. for example, jQuery. That's the point where you can start learning about another jQuery and try to implement whatever it was that you wanted to add to the website.
However, for basic dynamic websites, PHP will do a great job. It all depends on what you want to achieve.
I recommend you to learn PHP hand in hand with MySQL, because it's a common combination for database based web applications.
For MySQL, the most important operations are CRUD
What do you want to create? Just throw in some signal words like guestbook, etc., so we can tell you more about the needed tools.