Magento sent custom message after indexController is done - magento

I've got a module, it works fine and the indexcontroller handles all the things I want it to.
And it ends with: $this->_redirect('adminhtml/sales_order/');
Now my question is: how can I sent a message with this redirect? So that a 'complete' message shows up on top of the screen?
I've tried this: $this->_redirect('adminhtml/sales_order/')->addSuccess("Done!"); but that doesn't work...

addSuccess() is a method of the session model (technically the messages get stored in the session and retrieved on the next page)
So your code has to be something like that:
Mage::getSingleton('adminhtml/session')->addSuccess('Done!');
$this->_redirect('adminhtml/sales_order');

try this
Mage::getSingleton('adminhtml/session')->addSuccess('Done....');
$this->_redirect('adminhtml/sales_order/')
HTH

Related

Custom Sinatra route

I'm looking to make a custom route for my Sinatra blog project which shows the user the last entered post in the database.
get "/most-recent-job" do
Job.last
Can anyone help? I can't find info in my curriculum for such a request.
The Sinatra documentation on routes is pretty thorough. Assuming you're just trying to call a class method of Jobs::last, and that the method returns something stringifyable, then:
get '/most-recent-job' do
Jobs.last
end
should get it done. If that's insufficient for your use case, you'll have to expand your question to include code and output showing what Jobs.last is supposed to return, whatever errors you're getting from the route currently, and what you think the route's output ought to look like if you're expecting a MIME type other than text/plain.

Dingo APi error message

I am trying to render my mailable in the browser in order to check the content. However I'm getting this message {"message":"sha1() expects parameter 1 to be string, object given","status_code":500}
My code snippet
I am running Dingo/Api on my page as well an I think it's somehow connected with it.
Can you please give me the suggestion why am I getting this message instead of rendering mailable?
Thank you
We got this to work by assigning the mailable to a var first and then directly calling the render function on it, like so:
$mailable = new YourMailableName();
return $mailable->render();

How do I redirect or call a different Controller Action from my Controller Action in Magento?

I want to call cms/index/noRoute Action from one of my custom module's controller action, How do I do it?
I tried,
$this->_redirectUrl('cms/index/noRoute')
and
$this->_forward('cms/index/noRoute')
also few variations for redirect URL like '*/cms/index/noRoute' etc, non of them worked. How should I do this?
Use below code :
$this->_redirect('defaultNoRoute');
return;
its work for me.
Found it, and its so simple,
$this->norouteAction();
Since I'm doing this in one of my controllers which is extended from Mage_Core_Controller_Front_Action which is again extends from Mage_Core_Controller_Varien_Action, gives me the ability to call norouteAction().
I think this should do the trick (untested): $this->_redirectUrl($this->getUrl('cms/index/noRoute'))

Codeigniter - change url at method call

I was wondering if the following can be done in codeigniter.
Let's assume I have a file, called Post.php, used to manage posts in an admin interface.
It has several methods, such as index (lists all posts), add, update, delete...
Now, I access the add method, so that the url becomes
/posts/add
And I add some data. I click "save" to add the new post. It calls the same method with an if statement like "if "this->input->post('addnew')"" is passed, call the model, add it to the database
Here follows the problem:
If everything worked fine, it goes to the index with the list of all posts, and displays a confirmation
BUT
No the url would still be posts/add, since I called the function like $this->index() after verifying data was added. I cannot redirect it to "posts/" since in that case no confirmation message would be shown!
So my question is: can i call a method from anther one in the same class, and have the url set to that method (/posts/index instead of /posts/add)?
It's kinda confusing, but i hope i gave you enough info to spot the problem
Cheers!
Use the redirect() in conjunction with CodeIgniter's Flash Data, or opt for AJAX.

From a magento observer how can I tell action type

How can I know if an action is front end or backend from within the code of an observer for the controller_action_layout_render_before event ?
This returns true if currently in backend.
Mage::app()->getStore()->isAdmin()
Do a print of the object observer to log file to see if you can find any data which acts as a clue to what you need:
Mage::log("observer object:" . print_r($observer, true));
I think there may be a data field which contains the event which fired the observer from there. Please post back your findings!
Hope this helps.

Resources