Let's say we have created new controller(s). For authentication and security purposes, we will need to update the acl. If we are lazy to go through the bake cake console, we can try the following steps:
1. In initDb() function under controllers/acls_controller.php, defined the user groups properly. (the actions allowed/denied for each user group) Save the file.
2. Comment all functions/variables besides the Auth-related, in app/app_controller.php. (To make sure that initDb() will be executed).
3. In the web browser, type the url and launch it:
{address}/acls/initdb
4. Uncomment functions/variables in app/app_controller.php, if they were commented just now.
Monday, 27 June 2011
Wednesday, 22 June 2011
CakePHP - Parse Data From Controller To View
Let's say $a = '123', in index() in users_controller.
If we want to use the $a in users/index, we can use set() and compact():
$this->set(compact('a'));
*set() : Send data from controller to view.
**compact() : Creates an array containing variables and their values.
***Note that we need to remove the dollar($) sign when using compact().
Reference:
1. Stupid CakePHP Controller Tricks
2. Interacting with Views
If we want to use the $a in users/index, we can use set() and compact():
$this->set(compact('a'));
*set() : Send data from controller to view.
**compact() : Creates an array containing variables and their values.
***Note that we need to remove the dollar($) sign when using compact().
Reference:
1. Stupid CakePHP Controller Tricks
2. Interacting with Views
Monday, 20 June 2011
CakePHP Trap: findAllBy() and find('all', ...)
Warning (512): SQL Error: 1054: Unknown column 'PricesProduct' in 'where clause' [CORE/cake/libs/model/datasources/dbo_source.php, line 684]
Warning (2): Invalid argument supplied for foreach() [APP/views/...]
Sorry, it's my mistake that i myself is confused with two different functions that cause different result.
So, there is currently no trap in cakephp!
Monday, 13 June 2011
CakePHP Login Redirection
Let's said we want page to be redirected to Reservation index page after a User's login to the website, we can therefore create the login redirection in the beforeFilter() function in UsersController:
$this->Auth->loginRedirect = array('controller'=>'reservations', 'action'=>'index');
And, i really need to shout at CakePHP for having such a lousy documentation.
Thursday, 9 June 2011
CakePHP Drop Down List - Same value for 'keys' and 'values'
By default, when we use the form helper to generate a [select] drop down list, the [value] of each [option] is the [id] of the particular table. However, we sometimes need to have [value] which is the same as the content of the [option], therefore we will need to use array_combine() function.
We can do in such a way:
Let's said :
$array1(
[1] => a
[3] => b
[4] => c
)
After using the array_combine() function, the $array1 becomes:
$array1(
[a] => a
[b] => b
[c] => c
)
Reference:
1. FormHelper - Setting Option Value in Select Dropdown
2. php.net - array-combine
We can do in such a way:
$array1=array_combine($array1, $array1)$array1 is an array of data. The first parameter will go to be the [key] of the new array and the second parameter will go to be the [value] of the new array, thus making both the [key] and the [value] of the new array having the same value.
Let's said :
$array1(
[1] => a
[3] => b
[4] => c
)
After using the array_combine() function, the $array1 becomes:
$array1(
[a] => a
[b] => b
[c] => c
)
Reference:
1. FormHelper - Setting Option Value in Select Dropdown
2. php.net - array-combine
Subscribe to:
Posts (Atom)