Monday, May 10, 2010

Symfony 1.4: Create New Project

1. Create project directory under ~/workspace/
[root/workspace]# mkdir ProjectName

2. Create project
[root/workspace/ProjectName]# symfony14 generate:project ProjectName

in Eclipse
File > New > PHP Project
Project name: ProjectName

3. Create application
[root/workspace/ProjectName]# symfony14 generate:app appName

4. Configuration
[root/workspace/ProjectName]# chmod 777 cache/ log/

create symfony softlink
[root/workspace/ProjectName/web]# ln -s /opt/symfony/symfony14/data/web/sf

create softlink
[root]# cd /var/www/html
[root/var/www/html]# ln -s ~/workspace/ProjectName

under workspace/phplib
[root/workspace/phplib]# ln -s ~/workspace/PHPLIB_***Adapter/***Service ***Service

5. Create module
under project directory ProjectName
[root/workspace/ProjectName]# symfony14 generate:module appsName newModuleName

6. Set routing
url: /
param: { module: public, action: index }

7. Set view

       content-type: text/html
       title:  Project Name
       robots: index, follow
       description: Project Description
       keywords: xxxx, xxxxx
       language: en
    stylesheets: [main]
    javascripts: []
    has_layout: on
    layout: layout

customize the view for module

# apps/frontend/modules/job/config/view.yml
stylesheets: [public.css]

stylesheets: [main.css]

8. Turn on/off debug toolbar
Web Debug Toolbar Activation, in myapp/config/settings.yml

       web_debug: true

9. frontend_dev.php IP address check

// this check prevents access to debug front controllers that are deployed by accident to production servers.
// feel free to remove this, extend it or make something more sophisticated.
if (!in_array(@$_SERVER['REMOTE_ADDR'], array('', '::1')))
die('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');

Error in Linux, but not on other machine
Warning: session_start() [function.session-start]: Function spl_autoload_call() hasn't defined the class it was called for in /opt/symfony/symfony14/lib/storage/sfSessionStorage.class.php on line 93

Catchable fatal error: Object of class __PHP_Incomplete_Class could not be converted to string in /opt/symfony/symfony14/lib/yaml/sfYamlInline.php on line 105

Tried symfony14 cc, still have the error
Tried symfony14 clear-cache, red box - Task "clear-cache" is not defined
Closed browser without saving, worked (should just clear session/cookie);
symfony clear-cache is changed to symfony cache:clear

10. Forms
1) FormHelper was removed from symfony 1.4, so input_tag(), checkbox_tag() and etc not working.

2) Notice: Undefined variable: sf_flash
Use $sf_user->hasFlash()

11. Auth
Load AuthenticationService

# ProjectName/config/ProjectConfiguration.class.php

Add Auth.class.php

# ProjectName/lib/symfony/Auth.class.php
public function initialize(sfEventDispatcher $dispatcher, sfStorage $storage, $options = array()) { 

public function setAuthenticated($authenticated) {
    #throw new Exception('here');
    #sfContext::getLogger()->log('CSC_User::setAuthenticated is not implemented.');

public function addCredential($credential) {
    #sfContext::getLogger()->log('CSC_User::addCredential is not implemented.');

configure factories.yml

# ProjectName/apps/appName/config/factories.yml
    class: Auth

12. Login
Create new component instance in CSC

13. After move project / import other's project

Warning: copy(/home/eshare/projects/sfproject2/cache/frontend/prod/config/config_config_handlers.yml.php) [function.copy]: failed to open stream: [B]Permission denied in /home/eshare/projects/sfproject2/lib/vendor/symfony/lib/config/sfConfigCache.class.php on line 359[/B]

Warning: chmod() [function.chmod]: No such file or directory in /home/eshare/projects/sfproject2/lib/vendor/symfony/lib/config/sfConfigCache.class.php on line 365

Warning: require(/home/eshare/projects/sfproject2/cache/frontend/prod/config/config_config_handlers.yml.php) [function.require]: failed to open stream: No such file or directory in /home/eshare/projects/sfproject2/lib/vendor/symfony/lib/config/sfConfigCache.class.php on line 279

Fatal error: require() [function.require]: Failed opening required '/home/eshare/projects/sfproject2/cache/frontend/prod/config/config_config_handlers.yml.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/eshare/projects/sfproject2/lib/vendor/symfony/lib/config/sfConfigCache.class.php on line 279

clear the cache completely. (remove the folders inside cache)
Also run symfony project:permissions

1 comment:

  1. Excellent one!! I am going to implement it ASAP. I wish to understand the power of Symfony soon.