Order of execution standardController and ExtensionController in Salesforce - salesforce

one page has standard controller and extension controller that have save() function
when run page:
save() function of extension will run only
save() function of standard will run only
save() function of standard will run first and after that is save() function of extension will run
save() function of standard will run first and after that is save() function of extension will override.
save() function of extension will run first and after that is save() function of standard will run

I believe it will only run the Save on the first extension it finds with the method name then it falls back to the std controller if not found. If you want to run the standard save from the call the save method on the standard controller that you pass as an argument to the extension constructor.

Related

CakePHP index() vs view() and URL components

I am confused about the distinction and treatment of the index() and view() functions inside CakePHP 2.4.
Specifically, I am trying to modify a 3rd party API authored in CakePHP 2.4
Consider this Controller:
class EventsController extends AppController {
<snip>
public function index() {
if ($this->request->params['named']) {
$conditions = $this->request->params['named'];
} else {
$conditions = array();
}
}
This allows me to construct a URL like http://myserver/api/events/index/StartTime >=:12/EndTime <=15.json and the StartTime and EndTime get passed into conditions when I do a find.
That's great.
Now that same Controller has this additional function:
public function view($id) {
}
This function seems to be called when I invoke a url like http://myserver/api/events/1234.json
I am trying to extend view with more parameters, just like index. For example, I'd like to invoke:
http://myserver/api/events/1234/MonitorId =:3.json and MonitorId =:3 gets passed as a parameter to handle in view. I don't want to add these into the function definitions - it can be anything.
If I try and do this, I get a "Controller" not found, but this same approach works in index()
Can someone help me achieve my goal and help explain what is going on?
(IF it helps, the full code of the controller is here)
As I can see, you are using CakePHP RESTful routing routes.php
Here,
index is used for listing all the resources e.g. all blog posts. URL /events/index is getting mapped to index method in controller automagically.
view is used for showing a specific resource which can be identified by some unique identifier like id or uuid e.g. specific blog post. URL /events/<some_identifier> gets mapped to view method
What you need to do is modify view definition to read all query string parameters that you pass in URL and call Model accordingly. By default. routes parses the first string after events in URL to resource ID and passes it as first argument to view method in controller. This is scaffolded code.
You can use named parameters $this->request->params['named'] in your view definition and construct your queries. No hard-coding.
It turns out that I need to explicitly call the view action to pass it more parameters.
So api/events/view/218245/AlarmFrames >=: 80.json works as intended and then I can get the parameters with $conditions = $this->request->params['named'];

Method call on page load when URL params exist in Angular JS is not working

I have the following requirement :
Read URL parameters, load the 2 drop downs on the page and prepopulate them with the values in URL params. And then call a method with the dropdown values to load a grid.
Here is what i did until now :
On the controller I am checking for params using $location.search() and if they exist, calling some methods. I put this code at the end of the controller. But when a method inside the controller is called , the REST call does not go through, instead the call goes through after the total controller load happens.
Appreciate any help!
example scenario:
function abc(){/*some code*/}
function xyz(){/*some code*/}
function abd(){/*some code*/}
if(typeof $location.search().paramaName !=undefined){
/*Read URL params. preselect the current drop down by calling abc,xyz.use the values to call abd() which makes a REST API call to load the data on the page. */
}
You are probably missing the point that these rest calls are asynchronous.
You could include the call to these functions in the then() method of the returned promise object; which will be executed once the async call completes.
More on promises here -
Angular Promises
Promises Explained

In CakePHP, what does parent::initialize() do?

I see the line
parent::initialize();
in all the preloaded methods in CakePHP 3.x and in all the 3.x documentation.
Removing the line, or forgetting to add the line to new methods, doesn't seem to have any negative effects.
Which begs the question, what does it do?
Apologies is this is a totally noob question..
It is simple OOP. It calls the parent method of the same name.
Aclass {
public function foo() { echo 'bar'; };
}
Bclass extends Aclass {
public function foo() { parent::foo(); echo 'foobar'; }
}
Just try it and remove the parent call, you'll see what it does. The parents usually should be called, especially in methods like the initialize() callbacks. However, when to call or not to call them is a decision you have to make. It depends on if you want or need to call the parent methods logic or not. This is called "overloading".
This allows you to add functionality before or after the parent call of the method, which is a pretty common thing. I recommend you to read the OOP chapter of the php manual.
In your Controller’s initialize() method you can define any components you want loaded, and any
configuration data for them:
public function initialize()
{
parent::initialize();
$this->loadComponent('Security');
$this->loadComponent('Paginator');
$this->loadComponent('RequestHandler');
}
It is exactly what it says your running a method from the parent class. So the for example.
class AppController extends Controller {
public function initialize() {
echo 'hello world';
// do more sh*t
}
}
class UsersController extends AppController {
public function initialize() {
parent::initialize(); // this will run the method initialize from app controller that will echo 'hello world'
// do more sh*t
}
}
It's not doing anything when you remove it because there's nothing inside the parent initialize function, but it's there just in case you want to extend functionality from your parent controller to a child controller. For example:
In AppController there's a beforeFilter function that defines what I want to run before the page loads. Let's say I want a function to run on every single page - a simple redirect function if the user isn't logged in:
if (!$this->Auth->user()) {
$this->redirect('Users/login');
}
Instead of putting this in the beforeFilter on every single controller I go to, I can put it inside the beforeFilter of AppController.
My other controllers, like UsersController, extend from AppController:
class UsersController extends AppController {
So in the beforeFilter in my UsersController I can do:
public function beforeFilter(Event $event) {
parent::beforeFilter($event);
}
Now I inherit this redirect behavior from the parent controller(AppController), so that same code also runs in my child controller (UsersController) - and no matter what controller users go to they get redirected to the login page if they're not logged in.
This works the same way with parent::initialize(); you're inheriting what functionality exists inside the initialize function in the parent controller. This is just functionality included to eliminate redundant code.
So basically, if you see code that you're using on every single page, find a way to make it a bit object oriented by removing it and placing it in a file that your code can inherit from. It's along the same vein of moving the header and footer code out of HTML documents and placing them in their own php files so you can make a change in one area and have all affected derivatives updated, rather than editing the header and footer in every HTML document.

why in Cake PhP Controller index function needed?

why there is mandatory index function in cake php and how we can make an other function in a class, because i made a class in a controller and and also made a function which is index function but when i want to changes that function name there is an error? Kindly tell me if any one knows about it?Why we need to make index function and how to define that and how to make a new function in same class? I have also search but could find any satisfactory answer.
Here are some links
http://book.cakephp.org/
CakePHP check if user is logged in inside a view
Its not mandatory to have an index() function in the controller and cake will never ever generate error for this. Index function is only made, so that anyone hitting your controller without any action never sees the error related to framework.
Its a good practice to have index() function in classed and index.html or index.php file to avoid directory access.
It is not mandatory to have index function in the controller, but if no action exist then by default cake search for index function, because by default index is searched by browser.

CakePHP: Passing data to plugin

I have installed a plugin (SignMeUp) for the user registration, and according to the documentation the registration function inside my User Controller has to look something like this:
public function register() {
$this->SignMeUp->register();
}
Looking at the $this->data array inside this function shows that everything is working fine. However, when I use
debug($this->data);
inside the registration() function of the plugin (the one I just directed my function to), the array is empty. Somehow the data doesn't get passed on. What could be the cause?
Resolved! This can be solved by replacing all the $this->data occurences in the SignMeUpComponent with $this->controller->request->data
It's a change from Cake 1.3 to Cake 2.x

Resources