Header menu

_________________________________________________________________________________
Showing posts with label cake. Show all posts
Showing posts with label cake. Show all posts

Tuesday, 8 October 2013

Add span tag( or any html tag) to link in cakephp

To add <span> tag to cakephp link add span to label

"<span>Label name</span>"

and add

"array('escape' => false)"

to link as shown in below example.

Example:
<?php echo $this->Html->link(
    '<span>My Label</span>',
    array('action' => 'add'),
    array('escape' => false)
// This line will parse rather then output HTML
); ?>
One thing to note here 'escape' => false' must be added to 3rd parameter of link.
You can see the structure of cakephp link for more information at

http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html

Thursday, 12 September 2013

Write sql queries in cakephp controller

How to write sql queries in cakephp controller 

public function index(){
    $result= $this->User->query("SELECT * FROM users ;");  
}

User :- It is the name of my Model
users:- Table name in database

$result:- contain array of result of sql query

Get session information in cakephp

How to get session information in cakephp 

In the controller you can use

$this->Session->read();

to get all details of session variable . And you can use

$this->set('session',$this->Session->read());


to use these values in corresponding view page.

-----------------------------------------------------------------------------------------------------------------------

If you wish to use session variable in each page then use set method in appcontroller to set its value

public function beforefilter(){
$this->set('session',$this->Session->read());
}

Now this session variable is accessible in every page of view.

Note: this should be placed in Appcontroller...

Wednesday, 11 September 2013

Cakephp 1.2 - include problem of css and js , and improper functioning

Changes to made to be made cake php version 1.2 properly :

1. uncomment the statement in file apache2/conf/httpd.config on wamp server

LoadModule rewrite_module modules/mod_rewrite.so

2. In the same file make sure

 AllowOverride all (if there is none in place of all .. change it to all for your "C:/wamp/www" directory)

3. Make sure that all three .htaccess files have default configuration .. there must not me any change ..

Monday, 9 September 2013

Session variable in cakephp

PHP session  allows you to store user information on the server for later use (i.e. username, time,visited urls etc), this information is temporary and
will be deleted after the user has left the website.

To access session variable in cakephp... Go to controller in which you want to see session variable and add following two lines in code..

$session=$this->Session->read();
pr($session);