Symfony 2 can’t not write cache files

1. Using ACL on a system that supports chmod +a

Many systems allow you to use the “chmod +a” command. Try this first, and if you get an error – try the next method:

rm -rf app/cache/*
rm -rf app/logs/*

sudo chmod +a “www-data allow delete,write,append,file_inherit,directory_inherit” app/cache app/logs
sudo chmod +a “yourname allow delete,write,append,file_inherit,directory_inherit” app/cache app/logs

2. Using Acl on a system that does not support chmod +a

Some systems don’t support “chmod +a”, but do support another utility called “setfacl”. You may need to enable ACL support on your partition and install “setfacl “before using it (as is the case with Ubuntu), like so:

sudo setfacl -R -m u:www-data:rwx -m u:yourname:rwx app/cache app/logs
sudo setfacl -dR -m u:www-data:rwx -m u:yourname:rwx app/cache app/logs
FacebookTwitterGoogle+WeChatWhatsAppShare/Save

Best Encode for PHP5 and support symfony

In symfony, encoded classes excluded from config_autoload_yml.php. Because when symfony found the classes and read the contents, symfony can not find the words that contain abstract class|interface, final class|interface, class.

Following is the solution to make it work.

1. create config_handlers.yml in sf_root_dir/config folder and add

config/autoload.yml:
  class:    myAutoloadConfigHandler

2. add myAutoloadConfigHandler.class.php to sf_root_dir/config

3. change ProjectConfiguration.class.php and add myAutoloadConfigHandler.class.php

public function setup()
{
require_once(sfConfig::get('sf_root_dir').'/config/myAutoloadConfigHandler.class.php');

4. using ionCude Encoder to encode the files and add comment "class sfClassName" to the encode file.
Example: myTools.class.php

// class myTools
if(!extension_loaded('ionCube Loader')){$__oc=strtolower(substr(php_uname(),0,3));$__ln='ioncube_loader_'.$__oc.'_'.substr(phpversion(),0,3).(($__oc=='win')?'.dll':'.so');@dl($__ln);if(function_exists('_il_exec')){return _il_exec();}$__ln='/ioncube/'.$__ln;$__oid=$__id=realpath(ini_get('extension_dir'));$__here=dirname(__FILE__);if(strlen($__id)>1&&$__id[1]==':'){$__id=str_replace('\\','/',substr($__id,2));$__here=str_replace('\\','/',substr($__here,2));}$__rd=str_repeat('/..',substr_count($__id,'/')).$__here.'/';$__i=strlen($__rd);while($__i--){if($__rd[$__i]=='/'){$__lp=substr($__rd,0,$__i).$__ln;if(file_exists($__oid.$__lp)){$__ln=$__lp;break;}}}@dl($__ln);}else{die('The file '.__FILE__." is corrupted.\n");}if(function_exists('_il_exec')){return _il_exec();}echo('Site error: the file '.__FILE__.' requires the ionCube PHP Loader '.basename($__ln).' to be installed by the site administrator.');exit(199);
?>
4+oV5Djj/RjxxiMy5hHec2J9iSWGrP53JymQThUitFyI+rDD9TZc2z8BXRg+rQoi2zlgyd1jv271
LGLiuMCfZM9Wyo97ZTp208rr6ekINq15uTrYKONgK8dPivUR3GzHKXjbKRNv+toLg2bgkSIlKTzC
3KaXVdeReVGarLrmVxaC7L3pJ4Lt1Nex/HVwg3foRqvLGrv0vowUiL1k4uv87wuEJhST20s/KQ6M
8JwWXKksGBPbJ3cDMQuODDnHqNo//6G0VT4kAb4NP/LU9ejObXbOZx25YnWCgS1kyeeANpe++7Tv
rGwE4smPZpXuQawA5zZR2esxUiftfJXP4Pc0QmUUJRwcQhf2brOmWtb9JchulRNIRLgUxzmcYXk3
2z4KuvH3XkH/r2MnNXwiL1T172aBUF65ScDqVF3gZqJX1sOqvDwfqcVOPTA7PV1WUcGFbM58y0Cs

5. Now your files will be able auto load by the symfony.

6. Some link for ionCube
* The ionCube Home page
ioncube.com
* The Standalone Encoder

ionCube Standalone PHP Encoder

* The online Encoder

ionCube Online PHP Encoder

7. Finally, I have write a task to encode the files, if you need the task file, please send a email to me. I will send the file to you.

Doctrine Schema

Data Types

Doctrine offers several column data types. When you specify the portable Doctrine type it is automatically converted to the appropriate type of the DBMS you are using. Below is a list of the available column types that can be used as well as the type it is translated to when using the MySQL DBMS engine.

Type MySQL Type
integer integer
float double
decimal decimal
string varchar
array text
object text
blob longblob
clob longtext
timestamp datetime
time time
date date
enum varchar/enum
gzip text

If you want to use MySQL built-in enum type, you need enable the native enum support in the config file.

Now lets specify the use_native_enum attribute on our connection so that Doctrine knows to generate the native enum sql for your DBMS.

all:
  doctrine:
    class: sfDoctrineDatabase
    param:
      dsn: 'mysql:host=localhost;dbname=symfony12doctrine'
      username: user
      attributes:
        use_native_enum: true

Below is a sample yaml schema file that implements each of the different column types.

User:
  columns:
    id:
      type: integer(4)
      primary: true
      autoincrement: true
    username: string(255)
    password: string(255)
    latitude: float
    longitude: float
    hourly_rate:
      type: decimal
      scale: 2
    groups_array: array
    session_object: object
    description: clob
    profile_image_binary_data: blob
    created_at: timestamp
    time_last_available: time
    date_last_available: date
    roles:
      type: enum
      values: [administrator, moderator, normal]
      default: normal
    html_header: gzip

Indexes

You can optimize your database by defining indexes on columns which are used in conditions on your queries. Below is an example of indexing the username column of a user table since it is common to do lookups on the table by the users username.

User:
  columns:
    username: string(255)
    password: string(255)
  indexes:
    username_index:
      fields: [username]
      type: unique

Relationships

Doctrine offers the ability to map the relationships which exist in your database to the ORM so that it can be the most help when working with your data.

One to One

Here is a simple example of how to define a one-to-one relation between a User and Profile model.

Profile:
  columns:
    user_id: integer
    name: string(255)
    email_address:
      type: string(255)
      email: true
  relations:
    User:
      local: user_id
      foreign: id
      type: one
      foreignType: one

One to Many

Here is a simple example of how to define a one-to-many relation between a User and Phonenumber model.

Phonenumber:
  columns:
    user_id: integer
    phonenumber: string(255)
  relations:
    User:
      foreignAlias: Phonenumbers
      local: user_id
      foreign: id
      type: one

Many to Many

Here is a simple example of how to define a many-to-many relation between a BlogPost and Tag model.

BlogPost:
  columns:
    user_id: integer
    title: string(255)
    body: clob
  relations:
    User:
      local: user_id
      foreign: id
      type: one
      foreignType: one
      foreignAlias: BlogPosts
    Tags:
      class: Tag
      foreignAlias: BlogPosts
      refClass: BlogPostTag
      local: blog_post_id
      foreign: tag_id

Tag:
  columns:
    name: string(255)

BlogPostTag:
  columns:
    blog_post_id:
      type: integer
      primary: true
    tag_id:
      type: integer
      primary: true
  relations:
    BlogPost:
      local: blog_post_id
      foreign: id
      foreignAlias: BlogPostTags
    Tag:
      local: tag_id
      foreign: id
      foreignAlias: BlogPostTags
      foreignType: many

Behaviors

One great feature of Doctrine is the ability to have plug n’ play behavior. These behaviors can be easily included in your model definitions and you inherit functionality automatically.

Core Behaviors

Here is a list of behavior bundled with Doctrine core. You can use any of the behaviors in your models without writing any code.

Name Description
Geographical Adds latitude and longitude to your model and offers functionality for calculating miles/kilometers between records.
I18n Adds internationalization capabilities to your models.
NestedSet Turn your models in to a traversable tree.
Searchable Index all the data in your models and make it searchable.
Sluggable Add a slug field to your models and have it automatically create a slug based on your configuration.
SoftDelete Never really delete a record. Will simply set a deleted flag instead and filter all deleted records from select queries.
Timestampable Add a created_at and updated_at column to your models have Doctrine set them when inserting and updating records.
Versionable Turn your models in to an audit log and record all changes. Offers the ability to revert back to previous versions easily

Sluggable:

BlogPost:
  actAs:
    Sluggable:
      fields: [title]
      unique: true
  columns:
    user_id: integer
    title: string(255)
    body: clob

Nesting Behaviors

Gallery:
  actAs:
    I18n:
      fields: [title, description]
      actAs:
        Sluggable:
          fields:  [title]
  columns:
    title: string(255)
    description: clob

Using Multi Database In Symfony

all:
database1:
class: sfPropelDatabase
param:
dsn: pgsql://foo:bar@hostname/database1

database2:
class: sfPropelDatabase
param:
dsn: mysql://foo:bar@hostname/database2

Create one
PROJECT_DIR/config/database1.schema.xml
Create another one
PROJECT_DIR/config/database2.schema.xml

Rebuild DB model:

$ symfony propel-build-model

$database1_connection_handler = Propel::getConnection(FooPeer::DATABASE_NAME);
$database2_connection_handler = Propel::getConnection(BarPeer::DATABASE_NAME);