Tag Archives: framework

How to install Laravel to a subdirectory

Simple! Just need to change a setting in the .htaccess file. I am using Laravel 4, you might be using some other version but the method should apply nevertheless. I use an alias to point to this directory.

Add this line “RewriteBase /l4″ to your .htaccess where l4 is your sub directory or folder.

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On
    RewriteBase /l4
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Have fun!

Symfony2 and MVC

Really like what Fabien expressed here:

Is Symfony2 an MVC framework?

If you look around, every single framework seems to implement the MVC pattern.

I really don’t care whether Symfony2 is MVC or not. Probably because the MVC word is so overloaded and because nobody implements exactly the same MVC pattern anyway. The separation of concerns is all I care about. And if you like to call Symfony2 an MVC framework, then you should know that Symfony2 is really about providing the tools for the Controller part, the View part, but not the Model part. It’s up to you to create your model by hand or use any other tool, like an ORM.

I don’t like MVC because that’s not how the web works. Symfony2 is an HTTP framework; it is a Request/Response framework.

You have to be very discipline when you use Symfony2. Unlike other frameworks there are often many way of achieving the same result. I find myself thinking which is better often, changing where I place certain code and still lack the satisfaction and confidence that I did right. I am unsure where this and that should go although I will just say that given my experience with PHP I can pretty much make anything work. But. They just aren’t very sightly, if you know what I mean.

Symfony 2 is hard

Symfony2 is hard. But not simply because it is doing things so differently, rather, it depends on so many packages. While there are certainly a lot of resources online, many can be considered outdated.

This recalls a discussion I had with U-Zyn of gladlyCode on the trends on PHP frameworks. We concluded that Symfony has a brighter future because on the past few years Symfony has became one of the most talked about frameworks in Google Trends. That observation, however, did not consider the scenario where more people posted online as they needed help. Additionally search for Symfony also includes Symfony Legacy (Symfony 1) which turns out to be vastly different from Symfony 2. It is hard to distinguish articles of the two, half the time I’ll be read through then to realized it’s for Symfony 1

Symfony 2 supports both Doctrine 2 and Propel ORMs. There are times I read through articles for Propel rather than Doctrine2 that I am using. Yesterday I spent my day figuring out Symfony and all I achieved is installing bundles. Bundles are not as well documented and many times that are wrappers of another PHP project.

At the end of the day I find myself referring to so much websites that I maxed out my tabs and no longer see the favicon on the tab any more.

Symfony2 reminds me of TurboGears of Python, if anyone is even still using it. It’s not a bad thing, especially in the whole of PHP where writing yet another ORM isn’t really needed. My minor complaint is Symfony requires the developer to do more configuration than other frameworks — say Yii Framework — and the ORM of choice, Doctrine 2, requires too much definitions to be included in an Entity (similar to Model of MVC frameworks). Overall Symfony 2 is a big framework to work with, I am probably discovering something new at every juncture. It’s worth a try but you’ll need a day at least to explore their features.

How to use Symfony with existing database

I recently had to start a Symfony2 project using an existing database. Here is a rough guide on how it is done.

Firstly you have to update your app/config/parameter.ini to your existing database:

[parameters]
    database_driver="pdo_mysql"
    database_host="127.0.0.1"
    database_port=""
    database_name="gladlycode"
    database_user="root"
    database_password="root"
    mailer_transport="smtp"
    mailer_host="localhost"
    mailer_user=""
    mailer_password=""
    locale="en"
    secret="0bdc03a00514e9c1595219d165115d532"

My bundle is named GladlyCodeBundle, you will have to rename this. Based on this I do a map of existing database tables into XML format, note that the em dash is 2 dashes due to conversion by WordPress:

php app/console doctrine:mapping:convert xml ./src/Gladly/CodeBundle/Resources/config/doctrine/metadata/orm --from-database --force

You need to change the ‘Gladly/CodeBundle’ part to fit your project as the next step will look to import from the default location.

If you get any errors of this sort:

PHP Fatal error:  Call to a member function getColumns() on a non-object in /Users/kahwee/projects/gladlycode/vendor/doctrine/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php on line 133
PHP Stack trace:
PHP   1. {main}() /Users/kahwee/projects/gladlycode/app/console:0
PHP   2. Symfony\Component\Console\Application->run() /Users/kahwee/projects/gladlycode/app/console:22
...

It could be due to one of your tables not having a primary key. Just assign it the appropriate primary to continue with the import process.

Then I import them with annotations:

php app/console doctrine:mapping:import GladlyCodeBundle annotation

Finally I regenerate them into entities:

php app/console doctrine:generate:entities GladlyCodeBundle

And that’s it. Everything is imported.

Review: Django 1.0 Template Development

Django 1.0 Template Development, published by Packt, is a book that focuses on the templates portions of Django. Django is a popular Python web framework. Django models are easy to build but I always found the templates rather hard to understand.

Django 1.0 template development

Chapter 1, 2 and 3 gives an overview of how Django views work together. If you’re a developer, you shouldn’t skip that. I found myself understanding the Django MVC architecture better. (I come from a CakePHP background.) The author (Scott Newman) also did a good job introducing custom filters in Chapter 7. It’s something I haven’t explored till I read the book. There is also a chapter dedicated to pagination, also a must read.

The book is 272 pages, not too long. If you’re looking to improve your understanding on templates, this could be a good companion. I should also stress that the book is well organized. You can skip through the chapters and go straight to what you need without missing out much.

You can download a sample chapter here [PDF], and if you like it, you can find out how to get the book here.

Ruby on Rails and Merb will merge

Yay. We always see opensource branch and branch. Rarely do we see them come together.

Merb is an open, ever-changing project, and some its best ideas have come from not-core regular-Joe community members. It’s gotten where it has because of the community, and the community will get us even further in the future. Your ideas, feedback and even complaints will be 100% welcome in the future, just as they have been in the past. I believe in the tremendous value an open community and just generally open attitude bring to the table, and am counting on those things to continue ushering in the future of Ruby.

On to the news: beginning today, the Merb team will be working with the Rails core team on a joint project. The plan is to merge in the things that made Merb different. This will make it possible to use Rails 3 for the same sorts of use-cases that were compelling for Merb users. Effectively, Merb 2 is Rails 3. (Source: Yehudakatz)

I don’t use Rails by the way. I use more of CakePHP. But anyway, I think the merger is a good direction. Of course this is arguable since the merger would mean one less competing Rails framework. But this is software, not business. Merger means greater understanding. I believe there are many ways of doing one same thing, but one way that would be most efficient in most given situations and that’s why people build frameworks.