Rewriting a php app in CakePHP - php

So, I'm very tempted to rewrite my application using a php framework, as I think it'll make it easier for folks to get involved, as well as improving the design of the app.
CakePHP looks like the best of the PHP web frameworks. Does anyone have any experiences of it? What are the caveats I should consider going from handcoded PHP to using a framework?

Not depending on the framework you'll chose, the first thing you have to know is that :
it'll take some time for you to know it
you'll do crapping things, during that time ^^
so, take into account the fact it'll take some time before you are fully operational :-)
I think those points are the most under-estimated points : using a framework takes not much time... Using it well and to the full extend of its abilities takes... Well, a couple of months, maybe... Which means, when you are at the end of your project you'll say "I should rewrite that with all the stuff I learned while re-writing it the first time" :-D
What it means is : learn what the framework can do, learn how to use it, and use it for a while on small applications, before starting rewriting your big one !
Then, there is probably no "best framework" : one framework may be very well suited for one project, and another one may be best for a second, different project.
I've never worked with CakePHP ; I really like Zend Framework. But that is a personal opinion, and O know people who really like symfony ; they are not wrong : symfony is great -- and I am not wrong either ^^
Still, we sometimes agree on some things ; like the fact that Doctrine (default ORM layer of symfony) is really great stuff, and we tend to use in both symfony and ZF-based projects...
If motivated, you can take a look at many posts on SO, about frameworks... Here are a couple of those :
What PHP framework would you choose for a new application and why?
Is Symfony a good framework to learn?
What, in your mind, is the best PHP MVC framework?
Is Symfony a better choice than Zend for a web development shop (10+) because it is a full stack framework?
Best PHP framework for an experienced PHP developer?
Good luck with those ^^
("Which framework" is a quite pationnating -- and subjective -- question ^^ )

CakePHP has it's good parts but there is no "best" framework. Here's a thread with some clues about what's good in most popular PHP frameworks.
If you never used MVC frameworks before (and Cake is MVC framework) I think you should first familiaze yourself with MVC architecture.

"CakePHP looks like the best of the PHP
web frameworks."
This is subjective. You should compare the pros/cons of other PHP frameworks that will suit your needs.
These posts may help you:
https://stackoverflow.com/questions/2648/what-php-framework-would-you-choose-for-a-new-application-and-why
Why do I need to use a popular framework?
https://stackoverflow.com/questions/249984/php-framework-decision-analysis-paralysis

FWIW, I used it for a time when I was doing some php development. I found it easy to use, and the rapid development aspect was great, and I would imagine has just gotten better in the last 3 years. There is a ton of help in the irc channel, and the documentation is good. I didn't stick around in PHP long enough to become an expert. However, I was just starting out as a programmer then, and ran into Larry Masters (the creator, aka phpnut) and he was just a good person to talk to about design principles, and an all around nice guy. Then again you don't have to be a super nice guy to write a good web framework (I'm looking at you DHH).

Most of the frameworks "bind" you to them, meaning you have to do things their way. If you want to do something they weren't designed to do, you usually have to hack it. For example, how many PHP frameworks currently support Facebook Connect?
Personally I prefer "frameworks" that you can use only the parts you want. Zend is like this, Doctrine and Propel are ORM that are designed to be used with other code. For example, the Symfony framework can use either.
Finally, I haven't found a popular PHP framework that scales well.

I have used cakephp for a couple of projects. From the moment I learned it I have never written php again without it (unless is fun code in which I want to try some new stuff, or learn other design ideas away from MVC). As mentioned, learning it will take some time. How much time it takes really depends on your background. If you have used another MVC framework for a web scripting language then you will learn it really quick; RoR developers will pick it up within hours/days. If you don't have experience with MVC frameworks then it might take you a little bit, but it will really save you time later on the road (including in that project you start with).
Until today, I still learn new things about CakePHP every time I start a new project on it, although I do dig into a lot of its source code (you definitely don't need to do this, documentation and help boards are more than enough).
I definitely recommend you looking into it. It will save you a lot of time and get your head thinking in a different way (if you are not used to the MVC).
Best of luck.

CakePHP's convention over configuration approach has a few advantages once you learn them:
it helps to keep you code organised and understandable
makes it easier for multiple developers to collaborate on the same application
makes it possible for developers to understand other developers' applications
You have two main options when rewriting a legacy application in CakePHP:
change the database schema to reflect the conventions - resulting in less code
code your models to interface with the legacy database - this book goes into all the details
Either way, once you have done the above, it's pretty much plain sailing, and a good learning experience.

Related

purpose of 3rd party mvc?

ive seen many third party mvcs or frameworks such as codeignitor , cakephp, and so on. what i want to know is what are their purposes? ive created my own framework call it an mvc or framework (in my opinion their all the same). in my framework i have all the classes in one folder called classes and all functions in another. its all organized and when a new project comes in i am able to complete it fast. i have looked at the applications that i mentioned and it seems to have huge articles and tutorials to study. what is the purpose? why not study the main language such as php, javascript/ajax or jquery, and so on then build something that you know the ins and outs of so that any project comes your way you know what to do. ive known some people who use cakephp and for every project they get stuck and need to figure out what to do. another guy i knew worked with joomla and every basic company website that came his way he would reverse engineer joomla to make it work with the site. are people using these applications because they lack knowledge in the languages? or sometimes have no choice but to make a site while lacking language and put something together.
ps: i dont want to say which is better or argue, i want to understand and see if im missing anything.
Standardized frameworks make it easy to adapt and reuse blocks of code. By using a framework such as Zend, Cake, Joomla, etc. you can find repositories of pre-made scripts and components that easily plug into your existing site.
Not only that but frameworks will (in most cases) handle a lot of complicated, repetitive tasks that are standard across most websites. Frameworks will in most cases scaffold CRUD classes against your database automatically and support a clean separation of logic and view.
Frameworks aren't for everyone and I would actually recommend that newcomers to programming or PHP learn the basic syntax and object structure. Doing so will give you a stronger understanding of how your framework behaves and make it easier for you to modify/override the existing structure. Every framework is different, and some are better suited than others for particular tasks. You should do research and testing to see which one fits your needs.
One other benefit that hasn't been mentioned yet is that using a standard framework gives some shared knowledge between developers. If you build a project with your home-grown "framework" and then someone else has to maintain it in the future, they have to totally learn your methods from scratch. However, if you had used CakePHP, and they already have experience with CakePHP, they're going to have a pretty good base to start with. That can make a huge difference in the amount of time it takes them to get comfortable with a new system.
If you want to setup a project quickly, without having to know too much about everything underneath, using one of these frameworks can be very useful. You know, to some extent at least, that they're pretty well built and reliable, and it saves you a lot of time opposed to creating everything yourself. Most of them are also easily extendable to add functionality you might need.
But you're right, it's always a good thing to learn about all the basics. That way it's a lot easier to know what these frameworks exactly do, and more importantly, why and how. And knowing that makes it easier to choose the right framework for you and extend it in a proper and efficient way.
But in the end you'll learn from both approaches, the difference being that with an existing framework you can get start working with a site (almost) right away.
I too use my own home-built framework that took many months to develop, but for every project I still weigh the pros and cons of using a 3rd party framework. The decision usually comes down to the specifics of what I want to achieve. For example, in database-centric applications, I use my own framework because the ORM solutions of most of the well-known frameworks are just downright terrible and inefficient, but for something simple like a Blog, Codeigniter might be my choice (just because I hate Wordpress, which isn't even a framework but I have to mention here how horrible it is).
But keep in mind that while you know the ins and outs of your own framework, if anyone else has to maintain your project later on it will be difficult especially if you don't document. Big frameworks like CakePHP, Kohana, Symfony, etc. are fairly well known and it's easy to find others who have experience with them. Plus if you need help, all you have to do is post on their forums and chances are you'll have a good answer.
Another point is the maintenance of a home-built framework. More often than not this comes second to developing new sites or maintaining old ones, whereas a standard framework has a team of developers behind it. Any security issues in the framework are addressed and patched more rapidly and you can usually just upgrade the framework and keep your code intact.

php frameworks - build your own vs pre-made

I am building an application currently in PHP and I am trying to decide on whether to use a pre-existing framework like codeigniter or build my own framework. The application needs to be really scalable and I want to be completely in control of it which makes me think I should build my own but at the same time I dont want to reinvent the wheel if I dont have to.
Any advice greatly appreciated.
Thanks
Use an existing framework.
First of all creating a framework from scratch represents a massive investment in time and effort. The process involves a lot of trial and error, because you're designing something that needs to be both simple and powerful. For every design decision you'll have to ask yourself how it will affect every single future project that will be built on your framework.
You'd think that you could take each design decision and weigh it against the requirements like you would do for any other software project, but the thing is you don't know your requirements. You can't know them, because a framework is supposed to be able to do almost anything (or have the ability to be extended to do almost anything) within its domain. Future project a will need to be able to do x. Can your framework allow that without turning it into spaghetti code? And what if project b needs to do y? What if project c needs to do z?
Have you predicted everything?
Now the normal response to this is that if something doesn't work, you'll just change it in the future. It's software after all. A framework however isn't like a simple application. It's supposed to have an interface and once you expose that to the software that will be using it, you can't change it. You can extend it, but not change it. So now you have to think about deprecating methods, api versions and version compatibility. It's a whole new set of problems to deal with along with normal framework maintenance and new application writing.
Then there's documentation. You need an API, tutorials, example code. Once you build your own framework you have to deal with this as well. You could ignore it, but I assure you that eventually you yourself will need to find out what that method you wrote 6 months ago does. What does it return? What if special case x happens? Have you written all that down, or do you need to step through the code again? And I wont even mention how easy it will be for a new team member to get started on a custom framework whose documentation lies completely or at least mostly in your head.
You also have to acknowledge that unless you're working with the very best and brightest (and have a budget to match) you'll never have the extensive set of libraries that existing frameworks boast. Can you analyze, design, code, test and debug faster than an open-source community?
Finally you should ask yourself if you are proficient enough to be writing a framework. Have you dived deep into the code of a modern OO PHP5 framework to find out what makes it tick? And most importantly do you know why it does things that particular way? Keep in mind that any mistake you make in your design can blow up in your face months from now and you can end up paying for them over and over again.
To sum things up I'd advice you to go with an existing framework; it doesn't mean however that you have to pick one and like it. Take the time you'd otherwise devote to developing a new framework and devote it to learning an existing one. Then you can extend it to fit your needs. Also remember that there could be things you wont be able to do. But I assure you there would be things you wouldn't be able to do with your own framework either, so it doesn't matter all that much. A framework imposes a few limitations. It's the price you pay for being able to develop applications faster.
Make a list of requirements for your framework (ORM, PHP 5.3, PDO, etc). Then iterate over the existing frameworks and narrow them down to find the ones matching with your requirements. Then look at the codebase, documentation, community, project activity – does it feel something you would like to work with? Also be realistic about the time needed to to implement all your requirements by yourself – do you want to focus to building an application or a framework?
I'm building my own and I'm very glad I did in terms of learning, which is important to me. Also I LOVE to be in total control of my code. It comes with lots of negatives though, the big one being I'm the only one that knows how to use it. Also, a lot of development time is spent on improving my framework rather than delivering products to my clients. But I can't stress enough that I really, really enjoy building and using it.
If you want to learn (A LOT) build your own. If you just want to get work done use an existing one. (Before starting my own I almost went with CodeIgniter)
While I've build my own CMS framework in the past, and used custom (in-house) general php frameworks, I'd find an active framework that fits your development style, and use it.
Unless your main product/application is the framework. But it doesn't seem that way.
Your concerns about control and scalability should be applied to the host of frameworks out there - giving you a short list of options that fit your requirements.
Certainly, it's not a question of 'in-house' vrs 'public', then once you've made that call just pick any old framework.
To answer the question behind the question, for a framework that gives you complete control and should be able to scale reasonable well (I'm not sure how you need the framework to scale), I would suggest the Zend Framework. You can use single parts of it, rewrite what you want, and it's far more than just a MVC implementation.
Update: A quick example of customization with Zend. If you don't want to use their MVC stack, but need something to route requests, you can just use Zend's router library. If you like the MVC stack, but hate the way the router works, you can just implement the interface and write your own router.
This applies outside the MVC stack as well. Zend has a ton of libraries for mail, rss feeds, caching, auth, db, etc. Use what you want, and ignore the rest. Extend what you want, most of the framework is tiered with interfaces/abstract/generalized classes that you can build on if the standard functionality doesn't suite your needs.
The decision is very plain and simple.
If you want to learn and have full control - go for your own
If you want just to make money fast - go for ready made one.
I work in a company that initially wrote its own framework, built by a guy that worked here. It was only used on one project. The reason for this is that we soon realized that although it was clever and very good, there was no documentation for it. So if we employ another developer or a freelance guy, they'd have to learn it.
We run with CakePHP for a while, which is popular, but it does seem a mess. We eventually settled on KohanaPHP. Easy to extend, some good documentation (probably not up there with some others though), nicely formatted code (meaning if you can't find documentation you can quickly work out whats going on). The way the framework is written makes it pretty easy for a developer to pick up and follow what is going on. Whereas we always had trouble doing this with CakePHP.
I think the only argument for rolling your own framework is that you may want some highly customised stuff. But Kohana is so easy to extend, you can just throw it in there. You don't have to use their packed libraries if you really don't want to.
That said, some project I don't bother with a framework at all, just some sort of routing solution, like GluePHP. Since it would be overkill to use a full stack framework.
If you were just trying to practice, I'd suggest writing your own. Otherwise, though, definitely go with using an existing one. Symfony ftw.
The short answer is symfony2 IHMO.
The reasons are:
do not reinvent the wheel
a good wheel is better than yours (others are professional wheel makers,
since a lot of time)
an OSS framework can be expanded or modified, even only inspected
first or later you will not have time to maintain your own wheel
a number of eyes and hands do it better than 2!
Of course the previous points are valid for a very small set of professionally made frameworks! My favorite is symfony2, but there are a number of good alternatives.

How to know when it is time to use a framework to develop a website?

I have been developing websites in an n-tier structure and so far my requirements are fulfilled. But as powerful frameworks like Zend Framework, Symfony are getting popular, I wonder how to know if it is time to shift to a framework?
Am I in a kind of dilemma? What is the right option?
If you satisfied with your own way - never.
Frameworks being written not by gods but by people. Some of them may know less than you. Or have different point of view.
Also, it is more a paradigm dictated to you, than toolbox. A religion.
If you have your own way and it suits you, better develop your own framework. Not as universal as famous ones, but not as fat and sluggish as them too.
Yes.
It not only speeds up development time (once you know your way around the framework), it enables other developers to have a better understanding of how the site works.
Using a framework has of course its advantages because you can write your code faster, you have not worry about a lot of functionalities that are always required in a web application so you can think more about your application-specific implementation and you have just to upgrade the other functionalities.
Using a framework gives you of course advantages in terms of collaboration because obviously if you use a well-known framework there are a lot of people that know it without spending time to train them.
But, when you use a framework, you must respect its structure, its coding style and its design. That's usually not a problem because if you choose wisely a framework, you won't feel the need to go off the rails.
The best thing to do is really just have a go! I switched from my own coding style into CakePHP about a year ago and haven't looked back since. Makes it much easier for me to work on other framework-based code by other people, too, and it's overall reduced the wtfs of looking at my own code six months later because now the code follows a much stricter format and is more predictable.
If you're asking that question, then the time to try it is probably now since you've clearly had your interest piqued. If it turns out you don't like working with them then you can always go back to your usual way (or even write your own like Col. Shrapnel says).
The 4 reasons we chose to go with a framework (Zend) at my company:
1 - Common syntax: the framework has it's own syntax that all our coders must work to (to some degree). Makes it easier to use external developers, or handle staff turnover
2 - Scale: the site in question was of a scale that demanded MVC architecture
3 - Tested Components: The framework has most of the components pre-built, leaving you to focus on the Model
4 - Brand credibility: There's a certain value in using a high profile framework brand from a client perspective. It implies a standard solution, and "decouples" the client from your custom framework
Whenever you're not quite sure what the end result of the software is going to be. Ready made libraries are usually made to handle almost anything so you can easily extend your site on them. And if there's going to be new people working on it at some point in the future, they can hop in easily, without having to learn your way of doing things.
But other than that, i think that Col. Shrapnel is spot on.
As long as you can't answer this question yourself, I'd say: Always use a framework.
I know a lot of developers who think that using a framework makes them less off a "real programmer" which is just plain stupid. This wrong kind of pride should not stand in the way of creating well structured and maintainable code.
Using a good Framework saves you a lot of the small annoying problems so you can concentrate on your actual project. Of course there are no things that you can't do without a framework but with one you'll be able to do them much faster and with les headache.
Maybe experience will then show you cases where you don't need a framework or are in fact better of without one but these are quite rare.

Why use a web framework (like rails) over php?

This isn't a question about what framework to use. I've learned both Rails and Django, and I write all of my webapps in PHP. My question is why bother with the frameworks? It's always taken me longer to use a framework than to reuse old MySQL code and build "models" with phpMyAdmin. I also like writing everything myself, because I know what's going on. I can still reuse functions, etc. and do things how I want, and this freedom seems to be missing from most frameworks.
I'm not saying that my way is right; in fact, I'm trying to figure out where my logic fails. The hype can't be just thin air. What am I missing?
The basic idea of a framework is to allow you to work at a higher level of abstruction and write only the code you have to write to implement your specific requirements. All the other repetitive stuff is handled for you by the framework, and probably with far fewer bugs and security holes than if you did it yourself.
It may feel like it takes longer to learn a framework than to just do it yourself using basic language features and standard APIs, but it's simply not true - not if the framework is good and the app is non-trivial, and especially not once you have learned the framework (using a different one for each new project would of course be idiotic) and factor in the time it would take to find and eliminate all the bugs and correct all the design mistakes that have long since been found, eliminated and corrected in the framework by its developer community.
Almost every developer has cowboy coder instincts that tell him "Doing things yourself is much more fun than using code others have written, and I'm sure I'm good enough to get it right the first time, so it will even be faster and better!". These instincts are almost always wrong.
Frameworks allow you to concentrate on the application itself rather than worrying about the boilerplate code that you'd otherwise have to write for every application. They allow you to structure you site in a much more logical (mostly object-oriented) way, using tried and tested design patters such as model-view-controller. The code in framework is generally more mature and of a higher standard than code you would write yourself for one-off projects as framework have a large community of developers perfecting the code perfecting the code over year. This means that framework-driven sites often perform better and are much more secure.
You also mentioned you like writing things yourself - I know where you're coming from. My solution to this was to write my own framework - I get to reuse and improve my code with every project I do and I know the entire codebase inside out.
Writing it your self may make it easier for you to understand things your self but unfortunately it can make it much harder for other developers to understand what is happening. Frameworks will often be better documented and have a larger community that can support a new developer that is working on the app that you wrote.
I think a big part of it is what you focus on. Frameworks standardize the parts that you shouldn't have to keep revisiting, which helps you focus on the application as a whole. If you reuse your own code all the time you're already using your own makeshift framework.
Your comparing a framework (Rails) to a language (PHP). A framework is going to give you pre-built components so you can spend time on what makes your project unique.
You may already have a code base that helps do this for you. Check out some of the PHP frameworks since that's where you are more comfortable. Take a look at CakePHP, CodeIgnitor and/or Zend Framework.
If you are building many small apps/sites, using a framework may make your life easier.
I think a good step for you is to create your own framework with the code you've programmed so far. ;)
Try to make your code parametrizeable, in other words: create components which you can reuse in different parts of a website (for instance: styled containers), or in different websites (form generators/validators).
You can even go further and create base-classes from which you extend new classes to build your websites. (for instance: data objects with generic select/insert/update/delete methods).
I bet this gives you the best view on why frameworks are so damn handy ;)
It'll take you longer to initially use a framework for the same reasons a PHP developer would take longer to initially use Ruby - you're not familiar with it.
Once you're familiar with them, frameworks can offer the ability to skip the mundane and focus on actually writing the important parts of the app.
You should also just use a PHP based framework like Symfony or CakePHP using them should reduce your production time considerably.
One reason to use a frame work is code separation. Take symfony for example. The model is all done with propel or doctrine libraries. Very little SQL needed. You instantiate a new object and user getters and setters, to store your data, and instead of writing SQL in your page code you create functions in the objects related to the query. When you need to access the same kind of data on different pages you are asking the model for it, keeping the business logic with the model where it should be, so there's never any difference. All the work is done in the "action controller function". You get all the data you need, and then put as little php in the display, basically just echoing the variables you got in the action controller, (with the exception of some for loops and if statements for conditionals. I have found this a more efficient way to code, and on my 2nd project saw the production time cut in half.
You don't need to learn a new language python/ruby just to use a great framework, just have to fin one that works for you.
First, PHP has frameworks too, so the question as stated misses the point.
Yes, you can write your own framework, and as Kris said, there's no shame in that. However, part of the leverage of code reuse is the collective value of the efforts of many. It's not just about reusing your own code. Frameworks encapsulate the common tasks and patterns we all share and provide well tested solutions with many iterations of improvements from the community. No individual effort is going to measure up to that, no matter who you are.
If you roll your own, it will only become world class due to the collective effort of world class people, and that will only happen if your idea merits the attention. The top frameworks out there are already proven on those criteria.
DHH is a smart guy, but the Rails we have today never could have been realized by him alone. Not even close.
If you like "writing everything yourself" as you say, then choose a framework with a core philosophy that matches yours, and start making core contributions in the areas where you can see room for improvement.
Depending on the functions of your Web Application, it can be faster to develop without a framework. For example when the Webapp is just some kind of data viewer.
But as soon as you begin to implement more advanced functions, you are much more efficient with a framework.
Try do do this from scratch:
- proper Form validation
- Handling of multiple Language and Date/Time formatting
- Authentication
See a framework as free tools and stable implemented function for you to use.
Sounds to me like you have already written your own framework in php, since you do mention code reuse.
I can imagine it being easier to use your own set of wheels instead of adapting to someone else's. No shame in that.
Frameworks are there mainly to help people who are semi-new to PHP (or the specific language it is built on) to be able to build a website to an extent that it is secure and easy enough to add on extra parts to the site without having to know a lot about the specifics like security, MySQL (or other database types). In my opinion it is a fairly good way to help break coders into a language, allowing for the fact that the framework isn't too complex of course.
EDIT The reason behind me saying they are for beginners is because myself, as a beginner has used frameworks to break myself into languages a lot better.

Ruby on Rails or a PHP framework

I am a capable programmer and I write software for a living. I am taking up a new project to build a website that has a bunch of forms that perform CRUD operations on a database and some multimedia. I am very familiar with PHP and Python and have written some websites in them. I have written some rake tasks and a few ruby scripts that run in production, but I never wrote any websites in ruby. I am considering using Rails, but I have the following questions. It would be great to know the answers to any/all of these:
The project should be done in a month and is very time sensitive. Is 1 month enough for learning with and building a website in RoR?
Writing direct SQL queries is one of my strengths and I would like to use it. I heard that RoR is a pain to use if I am writing SQL queries directly. Is this true? Or can I just say execute a query, give me the results (as a list or dictionary) and then I will tell you how to render them?
I have heard that RoR does joins in memory and doesn't use the facilities offered by the database. Is this correct?
I need to create a website that displays a lot of Images, videos and Java applets. Would RoR hinder my ability to do this?
I am OK using a PHP framework. Is this a bad idea? If not, which PHP framework is closest to Rails in terms of programming convenience.
Answering your questions in order:
You could certainly learn Rails in that time. It's enough time to build a Web site too, but whether it's enough time for you to build your Web site is a different question. I would personally not want to try such a thing on a tight deadline.
You can write your own SQL queries, but there's little point to using Rails if you are going to work around all of its features.
Joins are normally done as part of the database queries generated by ActiveRecord.
Using ROR is pretty much orthogonal to having images, videos, etc. on a page.
I haven't used it, but CakePHP aims to be quite Railsy. Zend and CodeIgniter are more popular and I'm told better by people who have used all three, though.
The project should be done in a month
and is very time sensitive. Is 1 month
enough for learning with and building
a website in RoR?
Given the experience you describe I imagine one month to learn and build a simple-ish app (especially if it is CRUD based) should be enough. If there is a significant level of complexity I would be loath to learn a new technology and deliver a complicated site in one month.
Writing direct SQL
queries is one of my strengths and I
would like to use it. I heard that RoR
is a pain to use if I am writing SQL
queries directly. Is this true? Or can
I just say execute a query, give me
the results (as a list or dictionary)
and then I will tell you how to render
them?
The rails way is to use the ActiveRecord object mapppings it gives you (and mostly these work very well) It is also very easy to write direct SQL if that is what you want to do
ModelName.find_by_sql('your query')
is how you do that
I have heard that RoR does joins
in memory and doesn't use the
facilities offered by the database. Is
this correct?
ActiveRecord does a lot for you, but wherever performance is an issue, as above you can write your own SQL to leverage the advantages of the database.
I need to create a
website that displays a lot of Images,
videos and Java applets. Would RoR
hinder my ability to do this?
I don't see why it should. There are lots of gems and plugins out there which help with this sort of functionality, so it may well be the case that a lot of code could already be written for you.
I am OK
using a PHP framework. Is this a bad
idea? If not, which PHP framework is
closest to Rails in terms of
programming convenience.
I'll let a PHP expert answer this bit.
The project should be done in a month and is very time sensitive. Is 1 month enough for learning with and building a website in RoR?
If it's time-sensitive, stick with what you know.. That said, Rails has lots of plugins to handle things like image-uploads which may save you a lot of time. Rails has "scaffold generators" which create basic CRUD applications in a single command:
./script/generate scaffold title:text description:text when:datetime
..will generate the controllers/views to create/edit/delete items. You can then easily wrap nicer looking HTML around it, add authentication (via restful_authentication), and you may have your completed application in a few hours..
Writing direct SQL queries is one of my strengths and I would like to use it. I heard that RoR is a pain to use if I am writing SQL queries directly. Is this true? Or can I just say execute a query, give me the results (as a list or dictionary) and then I will tell you how to render them?
There's very few situation where you'd need to write SQL with ActiveRecord, but you can. RoR is still Ruby code, so you can always use a MySQL library and do away with ActiveRecord if you really need to write raw SQL (but, again, you almost certainly don't)
I have heard that RoR does joins in memory and doesn't use the facilities offered by the database. Is this correct?
There's no reason ActiveRecord cannot perform JOIN's via SQL queries, the ActiveRecord::Associations::ClassMethods mentions associations being performed via JOIN's.
Besides, even if it does do JOINs through memory, it's worked perfectly well for however long Rails has been around..
I need to create a website that displays a lot of Images, videos and Java applets. Would RoR hinder my ability to do this?
No. They're all just bits of HTML, which Rails can output as easily as any other framework.
I am OK using a PHP framework. Is this a bad idea? If not, which PHP framework is closest to Rails in terms of programming convenience.
Absolutely. If you don't go with Rails, use a PHP framework!
I would recommend against choosing a framework based on "how close to Rails" it is. PHP isn't Ruby. Trying to "port" (in a manner) a framework to a different language rarely works as well as writing a framework for that language.
As I commented on Chuck's answer, "CodeIgniter and Zend are good PHP web-frameworks. CakePHP is a good Ruby on Rails imitation"..
I found CodeIgniter felt much more like PHP (in a good way), it's documentation is also my favourite of any project I've used!
The Zend Framework is very modular, you can drop bits of Zend into an existing PHP app, or use it's MVC routing system.
CakePHP seems to be trying to make PHP act like Ruby, rather than making a framework that fits nicely with PHP.
All that said, the reason you use Ruby on Rails is the community (and thus all the plugins and stuff that revolve around it).
For example, paperclip plugin makes it extremely easy to an image-upload form (along with thumbnailing). To use it you add (to your model):
has_attached_file :photo, :styles => {:thumb=> "100x100#", :small => "150x150>" }
Then in your view, where you want the upload form to be, add:
<% form_for :user, :html => { :multipart => true } do |f| %>
<%= f.file_field :photo%>
<% end %>
That's it.
What I would recommend is spend a day making something simple in Rails. There's countless great tutorials (Railscasts are a good, random, example) and plenty of books on it. See if you like it, if not try CodeIgniter, Zend or CakePHP (or Django, or Merb, or.... Just don't spend the whole month trying frameworks!)
As you have some Python experience have you had a look at Django?
Rails is great for CRUD stuff.
1 - If you're already familiar with Ruby and MVC, a month should be fine. If not, there's a lot to learn.
2 - Rails will let you execute SQL queries, but it's really set up to take advantage of ActiveRecord.
3 - Rails is designed to switch between database types, so ActiveRecord does a lot on its own. Look into ActiveRecord Associations for more info.
4 - Never tried Java applets, but the rest work fine.
5 - If you're more comfortable with a PHP framework it's not a bad idea at all. There are even a few that try to replicate a lot of Rails features, such as CodeIgniter.
Check out RailsGuides for a better idea about all this.
I am OK using a PHP framework. Is this
a bad idea? If not, which PHP
framework is closest to Rails in terms
of programming convenience.
I guess CakePHP is close to RoR for a PHP framework.
I have not tried Rails myself, but wonder if it is a convenience. As far as Ive read (like the guy who spent 2 years making Rails do something it should not) when you need to do something more complex you apparently have to fight and hack the framework.
There are other frameworks for Ruby, PHP and Python. I suggest you look around a bit more before you decide.
If you want to code in PHP you could try Symfony with Zend Framework.
The project should be done in a month and is very time sensitive. Is 1 month enough for learning with and building a website in RoR?
It could be, but it could also make things unnecessarily harder on you. I usually wait for a project with a relaxed timeline to try and learn a new technology. If time is of the essense, bust out your favorite language and get it done.
Writing direct SQL queries is one of my strengths and I would like to use it. I heard that RoR is a pain to use if I am writing SQL queries directly. Is this true? Or can I just say execute a query, give me the results (as a list or dictionary) and then I will tell you how to render them?
I am not a Rails developer, but I do know it uses ActiveRecord. I am sure, however, that there is also a way to make it execute raw queries as most ORM do. Right there however you're going against the grain of what the framework wants you do and you may run into problems.
I have heard that RoR does joins in memory and doesn't use the facilities offered by the database. Is this correct?
Anything that abstracts out things for you, particularly database relationships, is going to be far from efficient. Worrying about it beforehand is usually not necessary, and once your application is finished it is common practice to then identify any particular slow queries and redo them by hand if necessary.
I need to create a website that displays a lot of Images, videos and Java applets. Would RoR hinder my ability to do this?
I have no idea why it would.
I am OK using a PHP framework. Is this a bad idea? If not, which PHP framework is closest to Rails in terms of programming convenience.
CakePHP is by far the closest framework to RoR. It borrows from a lot of its ideas. I have used it with some success in the past. CodeIgniter, while not related to Rails, is also terrific if you want something lightweight that won't force you to do anything its way.
http://www.doctrine-project.org/
I've had great success with the doctrine ORM : if you are writing object oriented php then this does the object->database record mapping for you. AFAIK this is one of the plusses to the django / rails framework.
So this links up the oop/database functionality like this:
$foo = new User(); // makes a new 'transitory' user object
$foo->name = 'bob'; // works like you'd expect
$foo->save(); // but this pushes it into the database.
//(There's a 'name' column in the 'User' table already: set up when Doctrine initializes).
& if you want a framework, it's a part of symfony now.
It's very motivating to have a real project to learn a new technology or approach, but it is possible to take on too much. It'll take 5 times longer than you'd take in the technology you know. Which can be okay - the learning, and the results might be worth it. But doesn't sound like this is appropriate here.
Rails is a great framework, but learning that framework and becoming more familiar with constructs specific to Ruby might be a bit much to do simultaneously with a one month deadline.
To step into a web application framework, I would recommend using a PHP framework if you are already familiar with PHP. While not a port, CakePHP is very much similar to Rails. It is modeled after Rails, and is my favorite PHP framework. symfony is a solid framework, but if you're looking for something more Rails-esque I recommend you try CakePHP.
If you're not already married to using Rails or something like it, I would recommend the Zend Framework. It is by far the most comprehensive web application framework available for PHP.
All of these frameworks will allow you to do all of the things you mentioned. It might be easier to think of them as a select group of building blocks than a comprehensive operating system for your website that you extend with plug-ins. That would be more similar to a CMS like ExpressionEngine. You can do anything with these frameworks, they're simply code bases for you to draw from to make developing web applications less tedious.
The Akelos framework is a PHP framework that purports being a port of Rails, so you might also be interested in that.
As for writing SQL queries, it's possible with any PHP framework, but the idea behind these frameworks is convention over configuration. Each has its own ORM scheme to abstract SQL queries away from the developers. While this might be due to the fact that many web developers, at least in my experience, are terrified of SQL, as someone who also likes writing SQL, I do appreciate the massive amounts of time that an ORM framework can save. Again, when the application is developed it's pretty much standard practice to profile the ORM's performance and look for areas to improve. Rapid-prototyping is a huge part of web application frameworks, so tools like this might actually be a hindrance to you. Like others have said, using one of these frameworks might end up being pointless if you're just going to work around their facilities.
Should you decide not to use one of these, PHP has a plethora of mature projects that will help you build an application, but seeking these out and learning how to implement them may take a great deal longer than learning a framework.
IMO a month is very tight to learn and launch in a month ( I'm assuming you're not full time though ) and you wouldn't be full time if you're learning as well. You know how it is when you get deeper.
About a month ago I faced the same dilemma between RoR and MVC. After a few weeks (learning at night ) I learned enough about RoR framework but ruby language was very new to me, the client wanted delivery and I was still in the "playground/sandbox" phase
So, because I know c# and the .net framework well and I can find resources quickly I have since open for MVC and within 2 weeks I've delivered something to the client.
So in my experience, learn RoR give it a week. If you're finding it takes more than say 40 hours to get going with the actual application, then stick with PHP and do RoR when you have more time and less time restraints.
Goodluck either way though!!
If you're comfortable with Model View Controller stucture then Ruby on Rails isn't too hard to learn. I myself came from PHP's Zend Framework to Ruby on Rails and really found it a relief. I like the whole idea of convention over configuration that Rails uses. It keeps your application (and all future applications) well structured, which in my option is extremely important and time saving.
At this time I've been programming in Ruby with Rails for maybe about 6-7 months and I'm really enjoying it. Clean code, VERY fast development, it's really incredible. Especially with the generator files and database migrations.
As for RoR being a pain when writing raw queries, I'm not sure, I never even have to write them but you sure can with a simple method. That shouldn't be a problem.
Once I started developing web applications in Ruby on Rails, I did not want to go back to PHP. Purely because I'm pretty much in love with how Rails works, the conventions, rapid development, clean code, consistent structure etc etc etc. But these days I now and then still get asked by clients to develop a web application with PHP. But in my eyes, if I went back in to Zend Framework I'd probably really get stressed as I find it extremely inefficient. (That might be my own fault, I'm not sure, but in my eyes, compared to Rails, meh). I discovered the PHP Framework "CakePHP". This framework is as far as I know the closest thing to Rails and I currently use it to develop PHP applications. It's pretty straightforward and works great. It also has a VERY nice thing called the "cookbook" on their website which helps you get up and running very quickly. So if you were to choose a PHP framework I would personally go with CakePHP just because its the closest thing to Rails.
The only thing I myself am a little annoyed about with Rails is that it requires a certain version of Rails to be installed, and that version must be compatible with a specific version of Ruby. You'll need to get the hang of Gems, Plugins (which aren't hard to understand, to be honest). But along with deployment, if you're running Apache 2+ then you need Passenger. Also to be safe you will want to freeze your gems and that kind of stuff to avoid conflicts with the servers specifications and installed utilities.
There's a lot more to learn than just the language and the framework when it comes to Ruby on Rails. PHP is pretty simple, just upload and it works. So you might want to look in to that as well before developing the application.
I think Rails is great, and it would be my first choice for such a project, but if you are in fact under a tight deadline and you are starting from square one with Rails, just don't do it. Go with what you know. PHP might not be the greatest, but it's a very serviceable language.
Despite what people might say, Rails does have a non-trivial learning curve, especially if you are not familiar with MVC. There's definitely a "Rails Way" to do things, and coming from most other frameworks, it takes a while to grok.
I think if you try to rush and learn Rails, you're just going to get frustrated, and I'm afraid this would taint your impression of it. Instead, try learning it in your spare time, or on a project with a more relaxed timeline. I think you'll get a lot more out of it this way.
I think adding the complexity of rewriting what you already know in a month - on a time sensitive project is a bad idea. Using any framework/tools you are unfamiliar with is probably a bad choice on any "time sensitive" project.
That being said the Zend_Framework for php is pretty solid with its form abstractions. I found an easier time moving to ZF than RoR - I tried both at the same time.
The documentation for ZF is fair - reading the actual code of the library is still my best source for documentation though. It isn't that tough to learn or start up - and if you don't mind IRC / stackoverflowing questions you should be able to learn it pretty fast.
Don't board the Rails train just because it looks cool. I know it's what everyone is talking about these days but to be honest, it's really not that special and you'd be better off using a framework written in a language you are comfortable with. If you are really good at SQL then it would take longer to learn how to use ActiveRecord than to just write the queries by hand, and ActiveRecord is basically half of Rails, which kind of defeats the purpose of using the framework. So based on the background info you provided, I'd say go with a PHP framework like CodeIgniter (haven't used it myself but I heard it's great, sounds like what you need).
The project should be done in a month
and is very time sensitive. Is 1 month
enough for learning with and building
a website in RoR?
As its been said before, stick with what you know if the deadline is short.
I am OK using a PHP framework. Is this
a bad idea? If not, which PHP
framework is closest to Rails in terms
of programming convenience.
CakePHP is very ruby like and I have been told that its a good stepping stone for PHP programmers to get in to Ruby and MVC.
use php + Zend Framework it's have all features of ror and more faster
ror is very slow, very expensive, and require powerful server
* The project should be done in a month and is very time sensitive. Is 1 month enough for learning with and building a website in RoR?
it's enough to learn Zend Framework
* Writing direct SQL queries is one of my strengths and I would like to use it. I heard that RoR is a pain to use if I am writing SQL queries directly. Is this true? Or can I just say execute a query, give me the results (as a list or dictionary) and then I will tell you how to render them?
should to writing SQL queries directly, ror make very slow and unoptimization queries
* I am OK using a PHP framework. Is this a bad idea? If not, which PHP framework is closest to Rails in terms of programming convenience.
all you need is mvc framework, I offer you take Zend Framework
For 1 month project use what you know better! Until now I have used Qcodo and Qcubed, but you generate your interface only from the database. Any PHP framework uses DSL. I love Python as language but never used. I was looking Ruby On Rails yesterday and it seems pretty nice. RoR has provided a new way to write agile web applications, but now there is grails too. Grails is written in Groovy, runs over the JVM and is dynamic language. The strengh of Grails is that can use any Java code and framework but with the simplicity of a dynamic language. With Grails you can do the same things of Rails and even more.
My advice, use what you know better, meanwhile learn Grails, this is what I am doing now.
Is 1 month
enough for learning with and building
a website in RoR?
Yes.
Writing direct SQL queries is one of
my strengths and I would like to use
it. I heard that RoR is a pain to use
if I am writing SQL queries directly.
Is this true? Or can I just say
execute a query, give me the results
(as a list or dictionary) and then I
will tell you how to render them?
Writing raw sql with Rails is not any more difficult than doing it with PHP. The object returned will be a hash of column-name/value pairs. The only problem may come if you decide to start using ActiveRecord which returns an ActiveRecord object (not a plain hash)
I have heard that RoR does joins in
memory and doesn't use the facilities
offered by the database. Is this
correct?
If you use raw sql, Rails shouldn't interfere with it.
I need to create a website that
displays a lot of Images, videos and
Java applets. Would RoR hinder my
ability to do this?
No.
I am OK using a PHP framework. Is this
a bad idea? If not, which PHP
framework is closest to Rails in terms
of programming convenience.
IDK.
I really like using ActiveRecord, but if you prefer raw sql, Rails can still be worth using. You'll get good url handling, a lot of built-in security, nice MVC architecture, and a nifty templating system, all while writing Ruby, which for many, has been a good experience.
Nice thread - some great comments in here everyone. This has been useful to me.

Categories