Re: Modification of a helper method?
Well, you could create a helper that doesn't modify the helper method,
but simply uses it.
E.g. in your views:
echo $myHelper->link('delete', $id); // generate a delete link for $id
for the active controller
echo $myHelper->link('edit', $id); // generate an edit link for $id
for the active controller
echo $myHelper->link('delete', $id, 'posts'); // generate a delete
link to another controller
Then in your helper, you just need to check the value of a view
variable and either generate the link or not generate it based on
that:
function link($action, $id = null, $controller = null) {
... // set default $id and $controller
$link = '';
$view =& ClassRegistry::getObject('view');
if ($view->viewVars['hasPrivilege']) { // check the controller-set
variable
$link = ... // generate the link
}
return $link;
}
Then in your controller you just need to set $hasPrivilege in the
view.
On Jun 12, 4:26 pm, cricket <zijn.digi...@gmail.com> wrote:
> On Jun 12, 6:14 pm, saidbakr <said....@gmail.com> wrote:
>
> > In other word,
>
> > In the controller action some logic will be done and it will return
> > either true or false. If it true, I need something to call the html
> > helper in the view and then changing all links with title contains the
> > text "Edit" or "Delete" to return null or empty string instead of html
> > link.
>
> That's not a good way to handle it. Pass your flag (true|false) to the
> view:
>
> $this->set( 'flag', $this->myLogic() );
>
> ... and then:
>
> if ( !$flag )
> {
> $html->link(...)
>
> }
>
> Or:
>
> if ( ( $foo['Edit'] || $foo['Delete'] ) && !$flag )
> {
> $html->link(...)
>
> }
Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home