Thursday, October 24, 2013

CakePHP - Query with joins

from thread : http://stackoverflow.com/questions/5079908/cakephp-find-method-with-join


There are two main ways that you can do this. One of them is the standard CakePHP way, and the other is using a custom join.

The CakePHP Way

You would create a relationship with your User model and Messages Model, and use the containable behavior:
class User extends AppModel {
    public $actsAs = array('Containable');
    public $hasMany = array('Message');
}

class Message extends AppModel {
    public $actsAs = array('Containable');
    public $belongsTo = array('User');
}
You need to change the messages.from column to be messages.user_id so that cake can automagically associate the records for you.
Then you can do this from the messages controller:
$this->Message->find('all', array(
    'contain' => array('User')
    'conditions' => array(
        'Message.to' => 4
    ),
    'order' => 'Message.datetime DESC'
));

The (other) CakePHP way

I recommend using the first method, because it will save you a lot of time and work. The first method also does the groundwork of setting up a relationship which can be used for any number of other find calls and conditions besides the one you need now. However, cakePHP does support a syntax for defining your own joins. It would be done like this, from the MessagesController:
$this->Message->find('all', array(
    'joins' => array(
        array(
            'table' => 'users',
            'alias' => 'UserJoin',
            'type' => 'INNER',
            'conditions' => array(
                'UserJoin.id = Message.from'
            )
        )
    ),
    'conditions' => array(
        'Message.to' => 4
    ),
    'fields' => array('UserJoin.*', 'Message.*'),
    'order' => 'Message.datetime DESC'
));
Note, I've left the field name messages.from the same as your current table in this example.

Using two relationships to the same model

Here is how you can do the first example using two relationships to the same model:
class User extends AppModel {
    public $actsAs = array('Containable');
    public $hasMany = array(
        'MessagesSent' => array(
            'className'  => 'Message',
            'foreignKey' => 'from'
         )
    );
    public $belongsTo = array(
        'MessagesReceived' => array(
            'className'  => 'Message',
            'foreignKey' => 'to'
         )
    );
}

class Message extends AppModel {
    public $actsAs = array('Containable');
    public $belongsTo = array(
        'UserFrom' => array(
            'className'  => 'User',
            'foreignKey' => 'from'
        )
    );
    public $hasMany = array(
        'UserTo' => array(
            'className'  => 'User',
            'foreignKey' => 'to'
        )
    );
}
Now you can do your find call like this:
$this->Message->find('all', array(
    'contain' => array('UserFrom')
    'conditions' => array(
        'Message.to' => 4
    ),
    'order' => 'Message.datetime DESC'
));

Saturday, October 12, 2013

customizer theme

http://www.themesandco.com/customizr/

http://demo.themesandco.com/ 

Featured Images

http://en.support.wordpress.com/featured-images/#other-featured-images

Thursday, October 10, 2013

How to add a php page to Wordpress

 
You don't need to interact with the API, or use a plugin.
First, duplicate post.php or page.php in your theme folder (under /wp-content/themes/themename/).
Rename the new file as templatename.php (where templatename is what you want to call your new template!). Enter the following at the top of the new file:
<?php
/*
Template Name: templatename
*/
?>
You can modify this file (using php) to include other files or whatever you need.
Then create a new page in your wordpress blog, and in the page editing screen you'll see a 'Template' dropdown in the 'Attributes' widget to the right. Select your new template and publish the page.
Your new page will use the php code defined in templatename.php

http://stackoverflow.com/questions/2810124/how-to-add-a-php-page-to-wordpress

Friday, October 4, 2013

word press - Famous 5-Minute Install

Famous 5-Minute Install

Here's the quick version of the instructions for those who are already comfortable with performing such installations. More detailed instructions follow.
If you are not comfortable with renaming files, Steps 3 and 4 are optional and you can skip them as the install program will create the wp-config.php file for you.
  1. Download and unzip the WordPress package if you haven't already.
  2. Create a database for WordPress on your web server, as well as a MySQL user who has all privileges for accessing and modifying it.
  3. Upload the WordPress files to the desired location on your web server:
    • If you want to integrate WordPress into the root of your domain (e.g. http://example.com/), move or upload all contents of the unzipped WordPress directory (excluding the WordPress directory itself) into the root directory of your web server.
    • If you want to have your WordPress installation in its own subdirectory on your web site (e.g. http://example.com/blog/), create the blog directory on your server and upload the contents of the unzipped WordPress package to the directory via FTP.
    • Note: If your FTP client has an option to convert file names to lower case, make sure it's disabled.
  4. Run the WordPress installation script by accessing the URL in a web browser. This should be the URL where you uploaded the WordPress files.
    • If you installed WordPress in the root directory, you should visit: http://example.com/
    • If you installed WordPress in its own subdirectory called blog, for example, you should visit: http://example.com/blog/
That's it! WordPress should now be installed.