Differences between _redirect('*/*/') and _redirect('*/*') - zend-framework

I am a newbie to Magento and Zend frameworks. Here are two examples in Mage_Customer_AccountController:
line 127
public function loginPostAction(){
if ($this->_getSession()->isLoggedIn()) {
$this->_redirect('*/*/');
return;
}
and line 230
public function createAction()
{
if ($this->_getSession()->isLoggedIn()) {
$this->_redirect('*/*');
return;
}
What difference will these two _redirect() result in?

These lines are equal, because Magento internally modifies url path to canonical view with "/" at the end.
The reason for writing once '*/*/' and other time '*/*' is just lack of style guidelines describing such cases for Magento developers. You can use any form you like.

Related

Searching for TYPO3 Extension: Global Variables

I am searching for a TYPO3 extension that lets me define variables and use them everywhere in the TYPO3 backend (something like %CEO_NAME%).
The customer wants to define names and addresses (for their CEO for example) centrally, so that when another person gets the job they can just change it once and it gets replaced in every RTE, page title, keyword, etc.
Is there some extension that would allow me to do that easily or is there an easy way this could be achieved with TS?
If at all possible I would like to avoid writing an own extension for this as the budget is somewhat tight on that project.
There are some possibilities with typoscript. Which means no editor can maintain the replacements.
One solution:
at last in the rendering process you replace any occurence:
page = PAGE
page {
:
do the rendering of the page
:
// now replace any occurence:
stdWrap.replacement {
1.search = __CEO__
1.replace = John Doe
2.search = __COMPANY__
2.replace = ACME
}
}
Be careful to select an unique key as the replacement is done everywhere (in HTML tags, in (inline) javascript/CSS, ...).
Advantage: this replacement can use regular expressions.
Next solutions:
Enhance the parsefunc, which is used for textarea fields.
tt_content.text.20 { <- example
parseFunc {
constants {
// replaces '###CEO###' with 'John Doe'
CEO = John Doe
}
short {
__CEO__ = John Doe
}
}
}
This will replace the markers only in the fields this parseFunc is active.

CustomPageFilter Error

My requirement is to create a sitemap something similar provided in acs-aem-commons, I can get an xml by hitting http://localhost:4502/content/geometrixx/en.sitemap.xml , but it include the page on the basis of IsHideNav() or IsValid() criteria. Now there can be multiple properties in page-properties dialog like hide in navigation , on the basis of which my page will be include/exclude in sitemap. Below is the snippet from the SiteMapServlet :
for (Iterator<Page> children = page.listChildren(new PageFilter(), true); children.hasNext();) {
write(children.next(), stream, resourceResolver);
}
So what i think to implement CustomPageFilter rather than PageFilter which can use some extra parameters also. When i create CustomPageFilter, I am getting an error(Modifier 'volatile' not allowed here) for the below code :
public volatile boolean includes(Object x0)
{
return includes((Page)x0);
}
Any clue why this error is coming here and can we create a custom filter to achieve such functionality.
Thanks

How to use a helper

I am creating a module that allows a user to input details into a form and save their details to allow relevant information to be forwarded to them at specified times.
To retrieve the details from the form and add them to the database I followed a tutorial and produced this code
public function saveAction()
{
$title = $this->getRequest()->getPost('title');
$f_name = $this->getRequest()->getPost('f_name');
$l_name = $this->getRequest()->getPost('l_name');
if ( isset($title) && ($title != '') && isset($f_name) && ($f_name != '') && isset($l_name) && ($l_name != '') ) {
$contact = Mage::getModel('prefcentre/prefcentre');
$contact->setData('title', $title);
$contact->setData('f_name', $f_name);
$contact->setData('l_name', $l_name);
$contact->save();
$this->_redirect('prefcentre/index/emailPreferences');
} else {
$this->_redirect('prefcentre/index/signUp');
}
}
The tutorial says to put it into the controller in a saveAction, and that works fine. However from my very limited understanding it would go in to a helper and i'd call the helper from the controller
I placed the above code in my helper and called it from within the saveAction using the following
Mage::helper('module/helpername');//returned blank screen and did not save
I also tried
Mage::helper('module/helpername_function');//returned error
My config has
<helpers>
<prefcentre>
<class>Ps_Prefcentre_Helper</class>
</prefcentre>
</helpers>
1 . Should this code go in a helper, if not where should it go?
2 . How do I call the helper(or the location the code need to go) to utilise the code?
1 . Should this code go in a helper, if not where should it go?
The actual code you posted imo is predestinated to be used within a controller action because it realizes a very specific process flow: Get user data for a specific case -> save if applicable -> redirect.
Secondly, a helper imo never should control route dispatching. It's a helper, not a controller.
I fail to see any use case where putting the method into a helper would give any advantages.
2 . How do I call the helper(or the location the code need to go) to
utilise the code?
Your definition uses <prefcentre> as alias, so if you did setup the helper the Magento standard way and using the file app/code/local/Ps/Prefcentre/Helper/Data.php, than your helper methods are callable like this:
Mage::helper('prefcentre')->myMethodName();

silverstripe permissions - prevent dataobject from being edited

at the moment I´m checking out the canEdit and canDelete Functions of Dataobject. As far as I can see I have to call that functions always manually in the template or other php code... Is there a way to prevent editing/deleting in general for a certain Dataobject? When I saw the canEdit function the first time I expected it to be checked by silverstripe automatically before writing the DataObject.
So I just want ADMINS to be allowed to write this DataObject:
public function canEdit($member = null){
return(
Permission::checkMember($member = Member::currentUser(), 'ADMIN')
);
}
Regards,
Florian
public function canEdit($member){
if (Permission::check('ADMIN')){
return true;
}else{
// do something here if applicable
}
}
Reference Link 1
Reference Link 2
Reference Link 3

CodeIgniter: URIs and Forms

I'm implementing a search box using CodeIgniter, but I'm not sure about how I should pass the search parameters through. I have three parameters: the search string; product category; and the sort order. They're all optional. Currently, I'm sending the parameters through $_POST to a temporary method, which forwards the parameters to the regular URI form. This works fine. I'm using a weird URI format though:
http://site.com/products/search=computer,sort=price,cat=laptop
Does anyone have a better/cleaner format of passing stuff through?
I was thinking of passing it into the products method as arguments, but since the parameters are optional things would get messy. Should I suck it up, and just turn $_GET methods on? Thanks in advance!
Query Strings
You can enable query strings in CodeIgniter to allow a more standard search function.
Config.php
$config['enable_query_strings'] = FALSE;
Once enabled, you can accept the following in your app:
http://site.com/products/search?term=computer&sort=price&cat=laptop
The benefit here is that the user will find it easy to edit the URL to make a quick change to their search, and your search uses common search functionality.
The down side of this approach is that you are going against one of the design decisions of the CodeIgniter development team. However, my personal opinion is that this is OK provided that query strings are not used for the bulk of your content, only for special cases such as search queries.
A much better approach, and the method the CI developers intended, is to add all your search parameters to the URI instead of a query string like so:
http://site.com/products/search/term/computer/sort/price/cat/laptop
You would then parse all the URI segments from the 3rd segment ("term") forward into an array of key => value pairs with the uri_to_assoc($segment) function from the URI Class.
Class Products extends Controller {
...
// From your code I assume you are calling a search method.
function search()
{
// Get search parameters from URI.
// URI Class is initialized by the system automatically.
$data->search_params = $this->uri->uri_to_assoc(3);
...
}
...
}
This would give you easy access to all the search parameters and they could be in any order in the URI, just like a traditional query string.
$data->search_params would now contain an array of your URI segments:
Array
(
[term] => computer
[sort] => price
[cat] => laptop
)
Read more about the URI Class here: http://codeigniter.com/user_guide/libraries/uri.html
If you're using a fixed number of parameters, you can assign a default value to them and send it instead of not sending the parameter at all. For instance
http://site.com/products/search/all/somevalue/all
Next, in the controller you can ignore the parameter if (parameter == 'all'.)
Class Products extends Controller {
...
// From your code I assume that this your structure.
function index ($search = 'all', $sort = 'price', $cat = 'all')
{
if ('all' == $search)
{
// don't use this parameter
}
// or
if ('all' != $cat)
{
// use this parameter
}
...
}
...
}