Cake PHP Tips and Tricks

Cake PHP Tips and Tricks

Question:What is meant by MVC?

Ans: Model view controller, it is a software architecture, used to isolates business logic from presentation logic. cakephp is based on mvc pattern.
Question: What is the first file that gets loaded when you run a application using cakephp?
Ans: The very first file being loaded is index.php in the webroot folder, which will add CakePHP’s core in the include path which is bootstrap.php  and it can be changed , either through index.php , or through htaccess.


Question: Use One model inside of a different model in CakePHP?
Ans:ClassRegistry::init(‘Attribute’)->save($data); same way you can call the model inside Helper also.
Question: What are commonly used components of cakephp?

Ans:

  1. Security
  2. Sessions
  3. Access control lists
  4. Emails
  5. Cookies
  6. Authentication
  7. Request handling

Question: What is default function and default controller of cakephp which is called automatically?
Ans: Default controller is indexController.php and Default function is index.

Question: Why cakephp have two vendor folder?
Ans: You probably noticed that there are two “vendors” folders in CakePHP: one is directly in the root and the other in the “app” folder. So, why are there two such folders? It is simple. The “vendors” folder in the “app” folder is for application-specifc third-party libraries whereas the other “vendors” folder is for libraries you want to use in multiple applications.

Question : what is a component,helper and why are they used, is there other way we can do same thing, what is better?
Ans: A component is an independent piece of code written for specific task that can be used by calling in controllers (example : email component), helper is used for helping cakephp in rendering the data to be shown to user with views, these only adds to modularity in code otherwise same coding can be implemented in conrollers.

Question : How do you proceed when you have to use cakephp for any application?


Ans : take the framework either from cake site or if you have changed according to your needs start from there. proceed with basic software engg. concepts as requirement gathering etc

Question : What is the first function that gets loaded from a controller?


Ans : index

Question : What is HABTM?
Answer : has and belongs to many is a kind of associations that can be defined in models for retrieving associated data across different entities.

Question : How can we use ajax in cakephp?
Answer : by calling ajax helper and then using it in controller for rendering.

Question : If you have to validate a registration module for a user, what all can be possible ways , which one is the best?
Answer : can be done on submission in controller, or using javascript/ajax while user is still filling the data. second option is better.

Question : Can you list some database related functions in cakephp?
Answer : find, findAll , findAllBy , findBy , findNeighbours , query

Question : How can you include a javascript menu throughout the site. give steps?
Answer : By adding the javascript files in webroot and call them in default views if needed everywhere or just in the related veiws.

Question : How can you make urls search engine friendly while using cakephp?
Answer : it is an automatic task that is done by cakephp.

Question : Do you prefer to use cakephp,yes then why ? no then why not?
Answer : Its a wide question and the answer would depend upon the kind of application for which it is to be decided, if its a basic cms i would prefer to have joomla. but yes cakephp is prefered for large systems, “simplicity” is the most important factor.
you include a javascript menu throughout the site. give steps.

Question : list some of the features in Cake php?
Compatible with versions 4 and 5 of PHP
MVC architecture
Built-in validations
Caching
scaffolding

Question. can you remember what is the directory structure when you download cakephp?
Answer:
1. app/
2. config/
3. controllers/
4. models/
5. plugins/
6. tmp/
7. vendors/
8. views/
9. webroot/
10. cake/
config/
docs/
libs/
vendors/

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Post Navigation