Showing posts with label install. Show all posts
Showing posts with label install. Show all posts

Thursday, 4 December 2008

Installing symfony - setting up the virtual host 2

Just a quick clarification on my previous post about setting up virtual hosts, which seems to be a little misleading.

You do also need to define your localhost as follows:

<VirtualHost *:80>
ServerName localhost
DocumentRoot "/path/to/www"
DirectoryIndex index.php
</VirtualHost>

(localhost should already be defined in your hosts configuration file).
This way you can still access all your other applications.

Thoughts?

Tuesday, 25 November 2008

Installing symfony - setting up the virtual host

Well, here is another thing that I have learned using symfony.

The basic installation tutorial instructs you to set up a virtual host for symfony:

<VirtualHost *:80>
ServerName myapp.example.com
DocumentRoot "/home/steve/myproject/web"
DirectoryIndex index.php
Alias /sf /$sf_symfony_data_dir/web/sf
<Directory "/$sf_symfony_data_dir/web/sf">
AllowOverride All
Allow from All
</Directory>
<Directory "/home/steve/myproject/web">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>


This was all new to me, so I set up "all" the paths correctly, and found that while it did allow me to use my symfony application properly and all the data_dir links where effectively aliased as planned, it also broke my other "localhost" links (e.g. I could no longer access http://localhost/other_app). Ouch.

Now I have figured out why: I hadn't changed the ServerName. So, the issue was solved by simply creating a new ServerName like so:

ServerName symfonyappname.localhost


To get this working the operating system must also be configured accordingly. To do this, simply add an entry to your hosts file, the location of which depends on which OS you are using.

Check out this link to find out where your hosts file is located.

Once the hosts file is properly configured (remember you may need to reboot), simply type:

http://symfonyappname.localhost

and magic happens :).

Thoughts?

Thursday, 21 August 2008

Symfony sandbox project

I recently heard of the Symfony project. It's an appealing free open-source PHP5 development framework licensed under the MIT license and I decided to give it a go.

For starters I downloaded the sandbox version from:
http://www.symfony-project.org/installation/1_1

I had an easy-PHP installation already up and running on my Windows 2000 system. So simply dropped the sandbox project under my www folder and followed the instructions on the Symfony website using mySQL as database manager:
http://www.symfony-project.org/tutorial/1_1/my-first-project

It was all pretty straight-forward except for a few "catches" detailed below.

#1 - the project uses php.exe on the command line to generate configuration files, PHP classes, etc. You really need to make sure to copy the php.ini file to the folder where the php.exe is located in order for the configuration to be taken into account. You can check which modules are available (and in effect, whether your latest php.ini is getting loaded properly) by typing
php -m
on the command line.

#2 - I also activated the xsl extension. This gets rid of some error messages that occur during database configuration and creation. I am not sure whether this makes an actual difference on the end result but was trying to clear any errors as I ran into them.

#3 - When I tried to access http://localhost/sf_sandbox/web/frontend_dev.php/comment or http://localhost/sf_sandbox/web/frontend_dev.php/post as specified in the tutorial, the pages wouldn't launch properly, I was getting database error messages.
To avoid this, I had to manually configure the www\sf_sandbox\config\database.yml configuration file:

all:
propel:
class: sfPropelDatabase
param:
phptype: mysql
database: symfony_project
dsn: 'mysql://root@localhost/symfony_project'

I changed all three parameters: phptype, database (use the database name you chose), and dsn (note that root is using an empty password to connect here).
For changes to take effect, make sure to clear the cache using:
php symfony cache:clear

#4 - In the middle of the tutorial, it tells you to start using your new website.
However, when you try to add a comment you get the following error:
Class "Post" must implement a "__toString" method to be rendered in a "sfWidgetFormPropelSelect" widget
To fix this, open the
sf_sandbox\lib\model\Post.php
and add a __toString method as follows:


class Post extends BasePost
{
function __toString()
{
return $this->getTitle();
}
}


To be 100% accurate, also change the sf_sandbox\apps\frontend\modules\comment\templates\editSuccess.php file so that the Post id label becomes Post title or simply Post since the post title is what we're actually seeing now we have added the __toString method in the Post class.

#5 - I couldn't get the following to work:

Next, open the modules/comment/templates/editSuccess.php and replace the following lines:

<tr>
<th>Post:
<td><?php echo object_select_tag($comment, 'getPostId', array (
'related_class' => 'Post',
)) ?></td>
</tr>


The original code is slightly different in the sandbox version and the replacement code wouldn't work. One way to avoid this issue is to set the default post id in your comment actions class.
Simply open your sf_sandbox\apps\frontend\modules\comment\actions\actions.class.php and add the following in the "executeCreate()" method:

$post=PostPeer::retrieveByPk(
$this->getRequestParameter('post_id'));
if ($post)
{
$this->form->setDefault('post_id',
$this->getRequestParameter('post_id'));
}

This simply pre-selects the post title in the form when you access the 'new comment' page from a given post's page by setting the default value of the drop-down choice list.

#6 - in the same file (sf_sandbox\apps\frontend\modules\comment\actions\actions.class.php). Instead of using the code from the tutorial, simply replace the redirect line with:
$this->redirect('post/show?id='.
$request->getParameter('comment[post_id]'));

This will redirect to the correct post rather than to the comment page.

Well, that's it for now. I haven't finished the tutorial yet. I have only made it to just before the Form Validation chapter. So still lots of fun to be had - stay tuned!

Thoughts in the meantime?

[EDIT: it looks like the Symfony Sandbox Project tutorial has been updated so some - if not all - of the above information may no longer be applicable.]
Online Marketing
Add blog to our blog directory blog search directory Blog Directory Blogarama - The Blog Directory