Monday, February 28, 2011

Re: What is "=>" in an Array?

Hi Nicolas,

In cakephp using $this->redirect(array('controller'=>'anycontroller', 'action'=>'index'));  works same as function

Header('Location: http://www.example.com/anycontroller/index');  works  in php. It is easy to understand

as both the functions works to redirect the control to  given url.  However we can use $this->redirect('http://www.example.com/anycontroller/index');

it is exactly same as $this->redirect(array('controller=>' anycontroller', 'action'=>'index')); The only difference

is that in the former one we are redirecting the control by passing exact url and in the later one it is pre-understood

that we want to pass control to the index action of controller named anycontroller that will find on the webroot of location

 http://www.example.com, that is 'http://www.example.com/anycontroller/index' hence we just pass the controller name and

the action name in an array where we want to redirect our control,

and if we only pass the array('action'=>'index'), it means we want to pass control to the index function of same controller of same site.

for better understanding i prefer to read http://book.cakephp.org/view/982/redirect ,

 and for good cakephp manual can be reached on the official site of cakephp that is

http://book.cakephp.org/view/982/redirect#!/view/879/Beginning-With-CakePHP

 

beside this array('controller' => 'anycontroller', 'action'=>'index') is in basic php syntax is an associative array

having 2 instances. First instance has key: 'controller' and value 'anycontroller' and  second instance

has key: 'action' and value 'index'. For better understanding go to http://php.net/manual/en/language.types.array.php

 

I hope it can help you

 

Thanks

Jitendra bajaj



On Mon, Feb 28, 2011 at 12:30 PM, Anatoliy Dimitrov <tollodim@gmail.com> wrote:
'=>' is one way to assign a value in an array in PHP. For more info
check:

http://php.net/manual/en/book.array.php

Regards,
Anatoli

On Feb 28, 6:47 am, nicolas <xu.shen...@gmail.com> wrote:
> hi,
> in this code: $this->redirect(array('action'=>'index'));
> I am absolutely new to cakePHP.  the "=>" really confuses me a lot. I
> couldn't find it in PHP documentation.
>
> Can anybody tell me what "=>" means exactly? and explain the syntax of
> =>?
>
> Thanks a lot!
>
> REgards,
> Nicolas

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: